/** * Given that I have a persistence layer is not working as expected, When I call {@link * ElasticSearchManager#pushAllArticles()}, Then I will log the error */ @Test public void testRuntimeErrorOccursOnPersistenceWhilePushingAllArticles() { IllegalArgumentException ex = new IllegalArgumentException(); expect(articleManager.getAllArticles()).andThrow(ex); logger.error("Error on ArticleManager when loading all articles.", ex); expectLastCall(); replayMocks(); esManager.pushAllArticles(); verifyMocks(); }
/** * Given that I have a set of articles in my DB, When I call {@link * ElasticSearchManager#pushAllArticles()}, Then I will retrieve all articles from the persistence * layer and post them into ElasticSearch <br> * TODO: Change the {@link Thread#sleep(long)} for something better like a {@link CountDownLatch}. * <br> * TODO: Investigate if the latter is the reason for the test failing sometimes, or is there * another reason. * * @throws InterruptedException */ @Test public void testPushAllArticles() throws InterruptedException { Article article = new Article(); Observable<Article> articles = Observable.just(article, article); expect(articleManager.getAllArticles()).andReturn(articles); client.postArticle(article); expectLastCall().times(2); replayMocks(); esManager.pushAllArticles(); // Should change this for CountDownLatch or a similar solution, left // like this just for testing Thread.sleep(250); verifyMocks(); }