Last active
July 23, 2016 11:38
-
-
Save jasongorman/74f6a0a049e03b7030ab46e8b01128e7 to your computer and use it in GitHub Desktop.
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
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()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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: