So, I need to test the Service Layer for an application (I need to test some methods - this is my first contact with the testing section)
public void testGetAllOrderedDescByRating() {
FAQ faq1 = initFAQ(new FAQ(), 5, 1L);
FAQ faq2 = initFAQ(new FAQ(), 3, 2L);
FAQ faq3 = initFAQ(new FAQ(), 11, 3L);
EasyMock.expect(faqDao.getAllOrderedDescByRating()).andReturn(
new ArrayList<FAQ>());
EasyMock.expect(faqDao.makePersistent((FAQ) EasyMock.anyObject()))
.andReturn(new FAQ());
EasyMock.replay(faqDao);
FAQService.saveFAQ(faq1);
FAQService.saveFAQ(faq2);
FAQService.saveFAQ(faq3);
List<FAQ> list = FAQService.getAllOrderedDescByRating();
Assert.assertEquals(list.get(0).getRating(), 11.0);
Assert.assertEquals(list.get(1).getRating(), 5.0);
Assert.assertEquals(list.get(2).getRating(), 3.0);
EasyMock.verify(faqDao);
}
The method from the interface:
List getAllOrderedDescByRating();
I receive:
java.lang.AssertionError:
Unexpected method call makePersistent(faq.FAQ@3461d1): getAllOrderedDescByRating(): expected: 1, actual: 0 makePersistent(): expected: 1, actual: 1 (+1)
What I'm doing wrong?