Skip to content

Instantly share code, notes, and snippets.

@kevinpet
Created September 21, 2013 01:22
Show Gist options
  • Save kevinpet/6646065 to your computer and use it in GitHub Desktop.
Save kevinpet/6646065 to your computer and use it in GitHub Desktop.
public class AccountTest {
Mockery mockery;
Strategy mockStrategy;
Account account;
@Before
public void before() {
mockery = new Mockery();
mockery.setImposteriser(ClassImposteriser.INSTANCE);
mockStrategy = mockery.mock(Strategy.class);
account = new Account(mockStrategy);
}
@Test
public void testAcceptableRisk_getsAdded() {
mockery.checking(new Expectations() {{
oneOf(mockStrategy).isRiskAcceptable(0.1, 0.2);
will(returnValue(true));
}});
account.addInvestment("BND", 0.1, 0.2);
mockery.assertIsSatisfied();
assertEquals(1, account.getInvestments().size());
}
@Test
public void testUnacceptableRisk_doesntGetAdded() {
mockery.checking(new Expectations() {{
oneOf(mockStrategy).isRiskAcceptable(0.1, 0.2);
will(returnValue(false));
}});
account.addInvestment("VWO", 0.1, 0.2);
mockery.assertIsSatisfied();
assertTrue(account.getInvestments().isEmpty());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment