Java 类org.robolectric.shadows.ShadowNotification 实例源码

项目:librus-client    文件:NotificationTest.java   
@Test
public void shouldNotifyAboutNewGrade() throws ExecutionException, InterruptedException {
    //given
    Subject subject = EntityTemplates.subject();
    Grade newGrade = EntityTemplates.grade()
            .withSubjectId(subject.id());
    LibrusGcmListenerService service = serviceWithMockClient();
    addMockGrades(newGrade);
    data.insert(subject);

    //when
    service.onMessageReceived(null, mockBundle());

    //then
    ShadowNotification notification = shadowOf(singleNotification());
    assertThat(notification.getContentTitle(), is("Nowa ocena"));
    assertThat(notification.getContentText(), is("Matematyka 4+"));
}
项目:librus-client    文件:NotificationTest.java   
@Test
public void shouldNotifyAboutNewAnnouncement() throws ExecutionException, InterruptedException {
    //given
    Announcement newAnnouncement = EntityTemplates.announcement();
    LibrusGcmListenerService service = serviceWithMockClient();
    addMockAnnouncements(newAnnouncement);

    //when
    service.onMessageReceived(null, mockBundle());

    //then
    ShadowNotification notification = shadowOf(singleNotification());
    assertThat(notification.getContentTitle(), is("Tytuł ogłoszenia"));
    assertThat(notification.getContentText(), is("Treść ogłoszenia"));
    assertThat(notification.getBigContentTitle(), is("Tytuł ogłoszenia"));
    assertThat(notification.getBigText(), is("Treść ogłoszenia"));
}
项目:librus-client    文件:NotificationTest.java   
@Test
public void shouldNotifyAboutNewAnnouncements() throws ExecutionException, InterruptedException {
    //given
    Announcement[] newAnnouncements = IntStreams.range(1, 11)
            .mapToObj(index -> EntityTemplates.announcement()
                    .withId(String.valueOf(index))
                    .withSubject("Ogłoszenie #" + index))
            .toArray(Announcement[]::new);
    LibrusGcmListenerService service = serviceWithMockClient();

    addMockAnnouncements(newAnnouncements);

    //when
    service.onMessageReceived(null, mockBundle());

    //then
    Notification realNotification = singleNotification();
    ShadowNotification notification = shadowOf(realNotification);

    assertThat(notification.getContentTitle(), is("10 nowych ogłoszeń"));
    assertThat(notification.getContentText().toString(), startsWith("Ogłoszenie #1, Ogłoszenie #2"));
    assertThat(notification.getBigContentTitle(), is("10 nowych ogłoszeń"));
    assertThat(getInboxLine(realNotification, 0), is("Ogłoszenie #1"));
    assertThat(getInboxLine(realNotification, 1), is("Ogłoszenie #2"));
}
项目:librus-client    文件:NotificationTest.java   
@Test
public void shouldNotifyAboutLuckyNumber() throws ExecutionException, InterruptedException {
    //given
    LuckyNumber luckyNumber = EntityTemplates.luckyNumber();
    LibrusGcmListenerService service = serviceWithMockClient();

    addMockLuckyNumber(luckyNumber);

    //when
    service.onMessageReceived(null, mockBundle());

    //then
    ShadowNotification notification = shadowOf(singleNotification());

    assertThat(notification.getContentTitle(), is("Szczęśliwy numerek: 17"));
    assertThat(notification.getContentText().toString(), is("środa, 14 czerwca 2017"));
}
项目:librus-client    文件:NotificationTest.java   
@Test
public void shouldNotifyAboutNewEvent() throws ExecutionException, InterruptedException {
    //given
    Teacher teacher = EntityTemplates.teacher();

    Event event = EntityTemplates.event()
            .withAddedById(teacher.id());

    LibrusGcmListenerService service = serviceWithMockClient();
    addMockEvents(event);
    data.insert(teacher);

    //when
    service.onMessageReceived(null, mockBundle());

    //then
    ShadowNotification notification = shadowOf(singleNotification());
    assertThat(notification.getContentTitle(), is("Nowe wydarzenie"));
    assertThat(notification.getContentText(), is("Praca klasowa - piątek, 7 października 2016"));
}
项目:grocery-reminder    文件:GroceryStoreNotificationManagerTest.java   
@Test
public void whenANotificationIsSentThenTheTheNotificationIncludesTheStoreName() {
    ShadowApplication shadowApplication = (ShadowApplication) Shadows.shadowOf(RuntimeEnvironment.application);

    insertStoreLocation(shadowApplication);

    ShadowLocation.setDistanceBetween(new float[]{(float) GroceryReminderConstants.LOCATION_GEOFENCE_RADIUS_METERS});

    long currentTime = System.currentTimeMillis();
    groceryStoreNotificationManager.sendPotentialNotification(new Location(LocationManager.GPS_PROVIDER), currentTime);

    ShadowNotificationManager shadowNotificationManager = getShadowNotificationManager();
    Notification notification = shadowNotificationManager.getNotification(GroceryReminderConstants.NOTIFICATION_PROXIMITY_ALERT);
    ShadowNotification shadowNotification = (ShadowNotification)Shadows.shadowOf(notification);
    assertTrue(((String) shadowNotification.getContentTitle()).contains(ARBITRARY_STORE_NAME));
}
项目:open    文件:RouteFragmentTest.java   
@Test @SuppressLint("NewApi")
public void shouldKillNotificationOnExitNavigation() throws Exception {
    ArrayList<Instruction> instructions = new ArrayList<Instruction>();
    Instruction instruction = getTestInstruction(3, 3);
    instructions.add(instruction);
    fragment.setInstructions(instructions);
    TestHelper.startFragment(fragment, act);
    fragment.onPageSelected(0);

    ShadowNotification sNotification = getRoutingNotification();
    sNotification.getActions().get(0).actionIntent.send();

    ShadowApplication application = shadowOf(act.getApplication());
    Intent broadcastIntent = application.getBroadcastIntents().get(0);
    String broadcastClassName = broadcastIntent.getComponent().getClassName();
    boolean shouldExit = broadcastIntent.getExtras()
            .getBoolean(MapzenNotificationCreator.EXIT_NAVIGATION);
    assertThat(shouldExit).isTrue();
    assertThat(broadcastClassName)
            .isEqualTo("com.mapzen.open.util.NotificationBroadcastReceiver");
}
项目:librus-client    文件:NotificationTest.java   
@Test
public void shouldNotifyAboutMultipleGrades() throws ExecutionException, InterruptedException {
    //given
    Subject matematyka = EntityTemplates.subject()
            .withId("1")
            .withName("Matematyka");
    Grade grade1 = EntityTemplates.grade()
            .withGrade("4+")
            .withSubjectId(matematyka.id());

    Subject informatyka = EntityTemplates.subject()
            .withId("2")
            .withName("Informatyka");
    Grade grade2 = EntityTemplates.grade()
            .withGrade("5")
            .withSubjectId(informatyka.id());

    LibrusGcmListenerService service = serviceWithMockClient();
    addMockGrades(grade1, grade2);
    data.insert(matematyka);
    data.insert(informatyka);

    //when
    service.onMessageReceived(null, mockBundle());

    //then
    Notification realNotification = singleNotification();
    ShadowNotification notification = shadowOf(realNotification);

    assertThat(notification.getContentTitle(), is("2 nowe oceny"));
    assertThat(notification.getContentText().toString(), is("Matematyka, Informatyka"));
    assertThat(notification.getBigContentTitle(), is("2 nowe oceny"));
    assertThat(getInboxLine(realNotification, 0), is("Matematyka 4+"));
    assertThat(getInboxLine(realNotification, 1), is("Informatyka 5"));
}
项目:librus-client    文件:NotificationTest.java   
@Test
public void shouldNotifyAboutMultipleEvents() throws ExecutionException, InterruptedException {
    //given
    Teacher teacher1 = EntityTemplates.teacher()
            .withId("1")
            .withFirstName("Ala").withLastName("Makota");

    Event event1 = EntityTemplates.event()
            .withContent("Praca klasowa")
            .withDate(LocalDate.parse("2016-10-07"))
            .withAddedById(teacher1.id());

    Teacher teacher2 = EntityTemplates.teacher()
            .withId("2")
            .withFirstName("Tomasz").withLastName("Problem");

    Event event2 = EntityTemplates.event()
            .withContent("Kartkówka")
            .withDate(LocalDate.parse("2016-10-10"))
            .withAddedById(teacher2.id());

    LibrusGcmListenerService service = serviceWithMockClient();
    addMockEvents(event1, event2);
    data.insert(teacher1);
    data.insert(teacher2);

    //when
    service.onMessageReceived(null, mockBundle());

    //then

    Notification realNotification = singleNotification();
    ShadowNotification notification = shadowOf(realNotification);

    assertThat(notification.getContentTitle(), is("2 nowe wydarzenia"));
    assertThat(notification.getContentText(), is("Ala Makota, Tomasz Problem"));
    assertThat(getInboxLine(realNotification, 0), is("Praca klasowa - piątek, 7 października 2016"));
    assertThat(getInboxLine(realNotification, 1), is("Kartkówka - poniedziałek, 10 października 2016"));
}
项目:grocery-reminder    文件:GroceryStoreNotificationManagerTest.java   
@Test
public void whenANotificationIsSentThenTheContentTitleIsSet() {
    Intent intent = buildIntentToListenFor();

    groceryStoreNotificationManager.sendNotification(intent);

    ShadowNotificationManager shadowNotificationManager = getShadowNotificationManager();
    ShadowNotification notification = Shadows.shadowOf(shadowNotificationManager.getNotification(GroceryReminderConstants.NOTIFICATION_PROXIMITY_ALERT));
    assertEquals(RuntimeEnvironment.application.getString(R.string.app_name) + ": " + ARBITRARY_STORE_NAME, notification.getContentTitle());
}
项目:grocery-reminder    文件:GroceryStoreNotificationManagerTest.java   
@Test
public void whenANotificationIsSentThenTheContentTextIsSet() {
    Intent intent = buildIntentToListenFor();

    groceryStoreNotificationManager.sendNotification(intent);

    ShadowNotificationManager shadowNotificationManager = getShadowNotificationManager();
    ShadowNotification notification = Shadows.shadowOf(shadowNotificationManager.getNotification(GroceryReminderConstants.NOTIFICATION_PROXIMITY_ALERT));
    assertEquals(RuntimeEnvironment.application.getString(R.string.reminder_notification), notification.getContentText());
}
项目:grocery-reminder    文件:GroceryStoreNotificationManagerTest.java   
@Test
public void whenANotificationIsSentThenTheVibrationIsSet() {
    Intent intent = buildIntentToListenFor();

    groceryStoreNotificationManager.sendNotification(intent);

    ShadowNotificationManager shadowNotificationManager = getShadowNotificationManager();
    ShadowNotification notification = Shadows.shadowOf(shadowNotificationManager.getNotification(GroceryReminderConstants.NOTIFICATION_PROXIMITY_ALERT));

    assertArrayEquals(GroceryReminderConstants.PROXIMITY_VIBRATION_PATTERN, notification.getRealNotification().vibrate);
}
项目:grocery-reminder    文件:GroceryStoreNotificationManagerTest.java   
@Test
public void whenANotificationIsSentThenTheDefaultNotificationSoundPlays() {
    Intent intent = buildIntentToListenFor();

    groceryStoreNotificationManager.sendNotification(intent);

    ShadowNotificationManager shadowNotificationManager = getShadowNotificationManager();
    ShadowNotification notification = Shadows.shadowOf(shadowNotificationManager.getNotification(GroceryReminderConstants.NOTIFICATION_PROXIMITY_ALERT));

    assertEquals(Settings.System.DEFAULT_NOTIFICATION_URI, notification.getRealNotification().sound);
}
项目:grocery-reminder    文件:GroceryStoreNotificationManagerTest.java   
@Test
public void givenANotificationIsSentWhenTheNotificationIsActedOnThenTheRemindersActivityIsLaunched() {
    groceryStoreNotificationManager.sendNotification(buildIntentToListenFor());

    ShadowNotificationManager shadowNotificationManager = getShadowNotificationManager();
    ShadowNotification notification = Shadows.shadowOf(shadowNotificationManager.getNotification(GroceryReminderConstants.NOTIFICATION_PROXIMITY_ALERT));
    ShadowPendingIntent shadowPendingIntent = Shadows.shadowOf(notification.getRealNotification().contentIntent);
    ShadowIntent shadowIntent = Shadows.shadowOf(shadowPendingIntent.getSavedIntent());

    assertEquals(RemindersActivity.class.getName(), shadowIntent.getComponent().getClassName());
}
项目:grocery-reminder    文件:GroceryStoreNotificationManagerTest.java   
@Test
public void givenANotificationIsSentWhenTheNotificationIsActedOnThenTheTheNotificationIsDismissed() {
    groceryStoreNotificationManager.sendNotification(buildIntentToListenFor());

    ShadowNotificationManager shadowNotificationManager = getShadowNotificationManager();
    ShadowNotification notification = Shadows.shadowOf(shadowNotificationManager.getNotification(GroceryReminderConstants.NOTIFICATION_PROXIMITY_ALERT));

    assertTrue((notification.getRealNotification().flags & Notification.FLAG_AUTO_CANCEL) == Notification.FLAG_AUTO_CANCEL);
}
项目:open    文件:RouteFragmentTest.java   
@Test @SuppressLint("NewApi")
public void shouldGenerateNotificationOnFirstInstruction() throws Exception {
    ArrayList<Instruction> instructions = new ArrayList<Instruction>();
    Instruction instruction = getTestInstruction(3, 3);
    instructions.add(instruction);
    fragment.setInstructions(instructions);
    TestHelper.startFragment(fragment, act);

    ShadowNotification sNotification = getRoutingNotification();
    assertThat(sNotification.getContentTitle()).isEqualTo("Test SimpleFeature");
    assertThat(sNotification.getContentText()).isEqualTo("Head on 19th Street for 520 ft");
    assertThat(sNotification.getActions().get(0).title).isEqualTo("Exit Navigation");
}
项目:open    文件:RouteFragmentTest.java   
@Test @SuppressLint("NewApi")
public void shouldGenerateNotificationOnPageSelected() throws Exception {
    ArrayList<Instruction> instructions = new ArrayList<Instruction>();
    Instruction instruction = getTestInstruction(3, 3);
    instructions.add(instruction);
    fragment.setInstructions(instructions);
    TestHelper.startFragment(fragment, act);
    fragment.onPageSelected(0);

    ShadowNotification sNotification = getRoutingNotification();
    assertThat(sNotification.getContentTitle()).isEqualTo("Test SimpleFeature");
    assertThat(sNotification.getContentText()).isEqualTo("Head on 19th Street for 520 ft");
    assertThat(sNotification.getActions().get(0).title).isEqualTo("Exit Navigation");
}
项目:react-native-notifications    文件:PushNotificationTest.java   
protected void verifyNotification(Notification notification) {
    ShadowNotification shadowNotification = Shadows.shadowOf(notification);
    assertEquals(shadowNotification.getContentText(), DEFAULT_NOTIFICATION_BODY);
    assertEquals(shadowNotification.getContentTitle(), DEFAULT_NOTIFICATION_TITLE);
}
项目:FullRobolectricTestSample    文件:Robolectric.java   
public static ShadowNotification shadowOf(Notification other) {
  return (ShadowNotification) Robolectric.shadowOf_(other);
}
项目:FullRobolectricTestSample    文件:Robolectric.java   
public static ShadowNotification.ShadowBigTextStyle shadowOf(Notification.BigTextStyle other) {
  return (ShadowNotification.ShadowBigTextStyle) Robolectric.shadowOf_(other);
}
项目:open    文件:RouteFragmentTest.java   
private ShadowNotification getRoutingNotification() {
    NotificationManager manager = (NotificationManager) act.getSystemService(
            Context.NOTIFICATION_SERVICE);
    ShadowNotificationManager sManager = shadowOf(manager);
    return shadowOf(sManager.getAllNotifications().get(0));
}