MailProvider { public Observable<Mail> starMail(int mailId, final boolean star) { return getMail(mailId).map(new Func1<Mail, Mail>() { @Override public Mail call(Mail mail) { mail.setStarred(star); return mail; } }); } MailProvider(AccountManager accountManager, MailGenerator genrator); Observable<List<Label>> getLabels(); Observable<Mail> getMail(final int id); Observable<List<Mail>> getMailsOfLabel(final String l); Observable<Mail> markAsRead(final Mail mail, final boolean read); Observable<Mail> starMail(int mailId, final boolean star); Observable<Mail> addMailWithDelay(final Mail mail); Observable<Mail> addMail(final Mail mail); Observable<Mail> setLabel(Mail mail, final String label); Observable<Mail> setLabel(int mailId, final String label); Observable<List<Mail>> searchForMails(String query, final int limit); Observable<List<Mail>> searchForOlderMails(final String query, final Date olderAs,
      final int limit); Observable<List<Mail>> getMailsSentBy(final int personId); Observable<MailStatistics> getStatistics(); static int DELAY; static int authExceptionEach; static int errorEach; static final Label INBOX_LABEL; }
@Test public void starMail() { final AtomicBoolean starredMail = new AtomicBoolean(false); final int id = 1; mailProvider.starMail(id, true).subscribe(new Subscriber<Mail>() { @Override public void onCompleted() { } @Override public void onError(Throwable e) { e.printStackTrace(); Assert.fail("Error while starring mail with id = " + id); } @Override public void onNext(Mail mail) { Assert.assertEquals(id, mail.getId()); Assert.assertTrue(mail.isStarred()); starredMail.set(true); } }); Assert.assertTrue(starredMail.get()); final AtomicBoolean errorThrown = new AtomicBoolean(false); mailProvider.starMail(-1, true).subscribe(new Subscriber<Mail>() { @Override public void onCompleted() { } @Override public void onError(Throwable e) { Assert.assertTrue(e instanceof NotFoundException); errorThrown.set(true); } @Override public void onNext(Mail mail) { Assert.fail("A mail with id = " + id + " has been starred, but a mail with this id should not exist"); } }); Assert.assertTrue(errorThrown.get()); final AtomicBoolean unStaredMail = new AtomicBoolean(false); mailProvider.starMail(id, false).subscribe(new Subscriber<Mail>() { @Override public void onCompleted() { } @Override public void onError(Throwable e) { e.printStackTrace(); Assert.fail("Error while unstaring mail with id = " + id); } @Override public void onNext(Mail mail) { Assert.assertEquals(id, mail.getId()); Assert.assertFalse(mail.isStarred()); unStaredMail.set(true); } }); Assert.assertTrue(unStaredMail.get()); final AtomicBoolean unstarErrorThrown = new AtomicBoolean(false); mailProvider.getMail(-1).subscribe(new Subscriber<Mail>() { @Override public void onCompleted() { } @Override public void onError(Throwable e) { Assert.assertTrue(e instanceof NotFoundException); unstarErrorThrown.set(true); } @Override public void onNext(Mail mail) { Assert.fail("A mail with id = " + id + " has been unstarred, but a mail with this id should not exist"); } }); Assert.assertTrue(unstarErrorThrown.get()); }