/** * Given that I have a persistence layer, When I call {@link * ElasticSearchManager#pushArticleById(String} and pass in an invalid id, Then It wont post * anything to ElasticSearch ElasticSearch */ @Test public void testPushArticleByInvalidId() { Article article = null; Observable<Article> articleObservable = Observable.just(article).filter((val) -> val != null); expect(articleManager.getArticleById(null)).andReturn(articleObservable); replayMocks(); esManager.pushArticleById(null); verifyMocks(); }
/** * Given that I have a persistence layer is not working as expected, When I call {@link * ElasticSearchManager#pushArticleById(String}, Then I will log the error */ @Test public void testRuntimeErrorOccursOnPersistenceWhilePushingPushArticleById() { IllegalArgumentException ex = new IllegalArgumentException(); expect(articleManager.getArticleById(TEST_ID)).andThrow(ex); logger.error("Error on ArticleManager when loading " + TEST_ID + " article.", ex); expectLastCall(); replayMocks(); esManager.pushArticleById(TEST_ID); verifyMocks(); }
/** * Given that I have an article in the persistence layer, When I call {@link * ElasticSearchManager#pushArticleById(String} and pass in its id, Then I will retrieve it from * the persistence layer and post it into ElasticSearch */ @Test public void testPushArticleByValidId() { Article article = new Article(); Observable<Article> articleObservable = Observable.just(article); expect(articleManager.getArticleById(TEST_ID)).andReturn(articleObservable); client.postArticle(article); expectLastCall(); replayMocks(); esManager.pushArticleById(TEST_ID); verifyMocks(); }