Code example for Notification

0
import static org.robolectric.Robolectric.shadowOf; 
 
@RunWith(TestRunners.WithDefaults.class) 
public class NotificationManagerTest { 
    private NotificationManager notificationManager;
    private Notification notification1 = new Notification();
    private Notification notification2 = new Notification();
 
    @Before public void setUp() { 
        notificationManager = (NotificationManager) Robolectric.application.getSystemService(Context.NOTIFICATION_SERVICE);
    } 
 
    @Test 
    public void testNotify() throws Exception { 
        notificationManager.notify(1, notification1);
        assertEquals(1, shadowOf(notificationManager).size());
        assertEquals(notification1, shadowOf(notificationManager).getNotification(null, 1));
 
        notificationManager.notify(31, notification2);
        assertEquals(2, shadowOf(notificationManager).size());
        assertEquals(notification2, shadowOf(notificationManager).getNotification(null, 31));