Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
public class DonateFixture {
private Library library;
private Title title;
private Member donor;
private EmailQueue queue;
private ArgumentCaptor<EmailAlert> alert;
private InterestedMemberSearch search;
public DonateFixture(){
search = new InterestedMemberSearchStub(
new String[]{
"joepublic@mymail.io",
"janedoe@hotfrogs.org.uk",
"fred@bloggs.eu"
}
);
}
public void setDonor(String memberId){
donor = new Member();
donateTitle();
}
public void setTitle(String name){
title = new Title(name);
}
public boolean libraryContains(){
return library.contains(title);
}
public int copyCount(){
return title.getCopyCount();
}
public int rewardPoints(){
return donor.getRewardPoints();
}
public String emailSubject(){
return alert.getValue().getSubject();
}
public String emailBody(){
return alert.getValue().getBody();
}
public String recipients(){
return alert.getValue().getRecipients();
}
@Test
public void donateMovieThatIsntInTheLibrary(){
setTitle("The Abyss");
setDonor("joepeters");
assertTrue(libraryContains());
assertEquals(1, copyCount());
assertEquals(10, rewardPoints());
assertEquals("Now available - The Abyss", emailSubject());
assertEquals("Dear member, just to let you know that The Abyss is now available to borrow",
emailBody());
assertEquals("joepublic@mymail.io, janedoe@hotfrogs.org.uk, fred@bloggs.eu",
recipients());
}
private void donateTitle() {
queue = mock(EmailQueue.class);
alert = ArgumentCaptor.forClass(EmailAlert.class);
library = new Library(queue, search);
library .donate(title, donor);
verify(queue).send(alert.capture());
}
}
Owner

jasongorman commented Jul 23, 2016

Example of a FitNesse fixture adapted to run as a JUnit test, too. Beware: order of inputs & outputs is important as to when to do set-up.

Screenshot of FitNesse Wiki page:
fitnesse_test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment