Created
August 18, 2011 15:10
-
-
Save christiangoudreau/1154267 to your computer and use it in GitHub Desktop.
Jukito test example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Test class for {@link CommentListPresenter}. | |
* | |
* @author Christian Goudreau | |
*/ | |
@RunWith(JukitoRunner.class) | |
public class CommentListPresenterTest extends PresenterWidgetTestBase { | |
/** | |
* Guice test module. | |
*/ | |
public static class Module extends PresenterTestModule { | |
@Override | |
protected void configurePresenterTest() { | |
} | |
} | |
// SUT | |
@Inject | |
CommentListPresenter presenter; | |
@Inject | |
CommentListPresenter.MyView view; | |
@Test | |
public void onCommentHistoryEmptyTest() { | |
// given | |
Comment comment = new Comment(); | |
// when | |
presenter.onCommentHistory(comment); | |
// then | |
verify(view, never()).setComments(anyListOf(Comment.class)); | |
} | |
@Test | |
public void onCommentHistoryTest() { | |
// given | |
Comment comment = new Comment(); | |
List<Comment> comments = new ArrayList<Comment>(); | |
comments.add(new Comment()); | |
comment.setComments(comments); | |
// when | |
presenter.onCommentHistory(comment); | |
// then | |
verify(view).setComments(anyListOf(Comment.class)); | |
} | |
@Test | |
public void onEditCommentTest() { | |
// given | |
Comment comment = new Comment(); | |
// when | |
presenter.onEditComment(comment); | |
// then | |
verify(eventBus).fireEventFromSource(isA(EditCommentEvent.class), same(presenter)); | |
} | |
@Test | |
public void onNewCommmentTest() { | |
// when | |
presenter.onNewComment(); | |
// then | |
verify(eventBus).fireEventFromSource(isA(EditCommentEvent.class), same(presenter)); | |
} | |
@Test | |
public void onPrintTest(CommentPrintableFactory commentPrintableFactory) { | |
// given | |
List<Comment> comments = new ArrayList<Comment>(); | |
// when | |
presenter.onPrint(comments); | |
// then | |
verify(eventBus).fireEventFromSource(isA(PrintEvent.class), same(presenter)); | |
verify(commentPrintableFactory).create(same(comments)); | |
} | |
@Test | |
public void onSetMemberCommentListTest(PlaceManager placeManager) { | |
// given | |
Member member = new Member(); | |
PlaceRequest request = new PlaceRequest(NameTokens.getCommentListPage()); | |
SetMemberCommentListEvent event = new SetMemberCommentListEvent(member); | |
List<Comment> comments = new ArrayList<Comment>(); | |
dispatcher.given(GetComment.class).willReturn(new GetResults<Comment>(comments)); | |
// when | |
presenter.onSetMemberCommentList(event); | |
// then | |
verify(placeManager).revealPlace(eq(request)); | |
verify(view).setComments(same(comments)); | |
assertEquals(presenter.member, member); | |
} | |
@Test | |
public void onViewCommentTest() { | |
// given | |
Comment comment = new Comment(); | |
// when | |
presenter.onViewComment(comment); | |
// then | |
verify(eventBus).fireEventFromSource(isA(SetViewCommentEvent.class), same(presenter)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment