Skip to content

Instantly share code, notes, and snippets.

@jasongorman
Last active July 23, 2016 11:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasongorman/74f6a0a049e03b7030ab46e8b01128e7 to your computer and use it in GitHub Desktop.
Save jasongorman/74f6a0a049e03b7030ab46e8b01128e7 to your computer and use it in GitHub Desktop.
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());
}
}
@jasongorman
Copy link
Author

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