Unit Test created and Classes created

This commit is contained in:
2020-10-13 23:42:12 +02:00
parent 891504ef09
commit dcbb133489
27 changed files with 903 additions and 0 deletions

View File

@@ -0,0 +1,62 @@
import static org.hamcrest.CoreMatchers.allOf;
import static org.hamcrest.CoreMatchers.anyOf;
import static org.hamcrest.CoreMatchers.hasItems;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.*;
import org.junit.Test;
public class CoinsTest {
@Test
public void test_getCoinAmount(){
Coins coin = new Coins(10);
assertTrue("Fehler getCoinAmmount ist negativ",coin.getCoinAmount() >= 0);
}
@Test
public void test_addCoinException(){
try {
Coins coin = new Coins(10);
coin.addCoin(-10);
fail("Erwartet NegativAmountException - addCoin");
}catch (NegativAmountException negativAmountException) {
assertThat(negativAmountException.getMessage(), is("negativAmountException"));
}
}
@Test
public void test_removeCoinException(){
try {
Coins coin = new Coins(10);
coin.removeCoin(-10);
fail("Erwartet NegativAmountException - removeCoin");
}catch (NegativAmountException negativAmountException) {
assertThat(negativAmountException.getMessage(), is("negativAmountException"));
}
}
@Test
public void test_removeCoin(){
Coins coin = new Coins(10);
try {
assertTrue(coin.removeCoin(10));
} catch (NegativAmountException e) {
e.printStackTrace();
}
}
@Test
public void test_changeCoinAmount_true(){
Coins coin = new Coins(10);
assertTrue(coin.changeCoinAmmount(-10));
}
@Test
public void test_changeCoinAmount_false(){
Coins coin = new Coins(9);
assertFalse(coin.changeCoinAmmount(-10));
}
}