Skip to content

Commit

Permalink
Implémente un test (crédit avec un montant valide)
Browse files Browse the repository at this point in the history
  • Loading branch information
hal91190 committed Oct 25, 2017
1 parent 0a4a718 commit 857184f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/main/java/fr/uvsq/poo/compte/Account.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,12 @@ public Account(BigDecimal initialBalance) {
public BigDecimal getBalance() {
return balance;
}

/**
* Crédite le compte.
* @param amount le montant à créditer
*/
public void credit(BigDecimal amount) {

}
}
17 changes: 13 additions & 4 deletions src/test/java/fr/uvsq/poo/compte/AccountTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,32 @@
import static org.hamcrest.core.IsEqual.equalTo;

public class AccountTest {
BigDecimal amount;
BigDecimal amount100;
BigDecimal amount200;
BigDecimal invalidAmount;

@Before
public void setup() {
amount = new BigDecimal("100");
amount100 = new BigDecimal("100");
amount200 = new BigDecimal("200");
invalidAmount = new BigDecimal("-100");
}

@Test
public void anAccountCreatedWithAnAmountShouldHaveABalanceEqualsToThisAmount() {
Account account = new Account(amount);
assertThat(account.getBalance(), is(equalTo(amount)));
Account account = new Account(amount100);
assertThat(account.getBalance(), is(equalTo(amount100)));
}

@Test(expected = IllegalArgumentException.class)
public void aCreationWithANegativeAmountShouldFail() {
Account account = new Account(invalidAmount);
}

@Test
public void anAccountCreditedWithAnAmountShouldHaveABalanceIncreasedByThisAmount() {
Account account = new Account(amount100);
account.credit(amount100);
assertThat(account.getBalance(), is(equalTo(amount200)));
}
}

0 comments on commit 857184f

Please sign in to comment.