|
1 | 1 | package com.codedifferently.lesson16; |
2 | 2 |
|
| 3 | +import static org.assertj.core.api.Assertions.assertThat; |
| 4 | +import static org.assertj.core.api.Assertions.assertThatThrownBy; |
3 | 5 | import static org.junit.jupiter.api.Assertions.assertEquals; |
| 6 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
| 7 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
4 | 8 |
|
5 | | -import java.sql.Array; |
| 9 | +import com.codedifferently.lesson16.Coins.CoinType; |
6 | 10 | import java.util.ArrayList; |
7 | | - |
| 11 | +import java.util.List; |
8 | 12 | import org.junit.jupiter.api.Test; |
9 | 13 |
|
10 | | -import com.codedifferently.lesson16.Coins.CoinType; |
| 14 | +class CoinTest { |
11 | 15 |
|
12 | | -class CoinTest{ |
| 16 | + @Test |
| 17 | + void testCheckCoinInPocket() { |
| 18 | + // arrange |
| 19 | + Coins coin = new Coins(CoinType.NICKEL, 5, false, 5.0, 1953, List.of("nickel", "copper")); |
| 20 | + // act action |
| 21 | + Coins.CoinType actualCoin = coin.getCoinType(); |
| 22 | + int coinValue = coin.getCoinValue(); |
| 23 | + boolean coinRarity = coin.isCoinRare(); |
13 | 24 |
|
| 25 | + // assert |
| 26 | + assertEquals(CoinType.NICKEL, actualCoin); |
| 27 | + assertEquals(5, coinValue); |
| 28 | + assertFalse(coinRarity); |
| 29 | + } |
14 | 30 |
|
| 31 | + @Test |
| 32 | + void testWeighCoins() { |
| 33 | + // arrange |
| 34 | + Coins coin = new Coins(CoinType.NICKEL, 5, false, 5.0, 1953, List.of("nickel", "copper")); |
| 35 | + double expectedWeight = 5.0; |
| 36 | + // act |
| 37 | + double coinWeight = coin.getCoinGramWeight(); |
| 38 | + // assert |
| 39 | + assertEquals(expectedWeight, coinWeight); |
| 40 | + } |
15 | 41 |
|
16 | | -@Test |
17 | | - void testCheckCoinInPocket(){ |
18 | | -//arrange |
19 | | - Coins coin = new Coin(Coins.CoinType.NICKEL, 5, false, 5.0, 1966, new ArrayList<>(nickel,copper)); |
20 | | -//act action |
21 | | - CoinType actualCoin = CoinType.NICKEL; |
| 42 | + @Test |
| 43 | + void testConvertCoins() { |
| 44 | + // arrange |
| 45 | + List<Coins> coinCollection = new ArrayList<>(); |
| 46 | + coinCollection.add(new Coins(CoinType.NICKEL, 5, false, 5.0, 1953, List.of())); |
| 47 | + coinCollection.add(new Coins(CoinType.NICKEL, 5, false, 5.0, 1953, List.of())); |
| 48 | + // act |
| 49 | + int totalNickles = coinCollection.size(); |
| 50 | + int dimes = Coins.convertNickelsToDimes(totalNickles); |
| 51 | + // assert |
| 52 | + assertEquals(1, dimes); |
| 53 | + } |
22 | 54 |
|
23 | | -//assert |
24 | | - assertEquals(CoinType.NICKEL,coins.checkCoinType()) |
25 | | -} |
26 | | -@Test |
27 | | - void testWeighCoins(){ |
28 | | -//arrange |
29 | | - Coins coin = new Coin(Coins.CoinType.NICKEL, 5, false, 5.0, 1966, new ArrayList<>(nickel,copper)); |
30 | | - double expectedWeight = 5.0; |
31 | | -//act |
32 | | - double coinWeight = coin.coinGramWeight(); |
33 | | -//assert |
34 | | - assertEquals(expected, coinWeight); |
35 | | -} |
36 | | -@Test |
37 | | - void testConvertCoins(){ |
38 | | -//arrange |
39 | | - coinCollection = new Arraylist<>(); |
40 | | - Coin nickel1 = new Coin(); |
41 | | - Coin nickel2 = new coin(); |
42 | | - coinCollection.add(nickel1); |
43 | | - coinCollection.add(nickel2); |
| 55 | + @Test |
| 56 | + void testCollectCoins() { |
| 57 | + // arrange |
| 58 | + Coins.CollectCoins(); |
44 | 59 |
|
45 | | -//act |
46 | | - Coin Dime = Coin.convertNickelsToDime(nickel1, nickel2); |
47 | | -//assert |
48 | | - Assert(10, Dime.getValue()) |
49 | | -} |
50 | | -@Test |
51 | | - void testCollectCoins(){ |
52 | | -//arrange |
53 | | - coinCollection = new Arraylist<>(); |
54 | | - Coin penny = new Coin(); |
55 | | - Coin nickel = new Coin(); |
56 | | - Coin dime = new Coin (); |
57 | | -//act |
58 | | - AddCoin(penny); |
59 | | - AddCoin(nickel); |
60 | | - AddCoin(dime); |
61 | | -//assert |
62 | | - AssertEquals(3,coinCollection()); |
63 | | -} |
64 | | -@Test |
65 | | - void testGetAgeCoin(){ |
66 | | -//arrange |
67 | | - Coin coin = new Coin(); |
68 | | -// Act |
69 | | - int age = coin.geCoinAge(); |
70 | | -// Assert |
71 | | - assertEquals(1954, age); |
| 60 | + List<Coins> coinCollection = Coins.getCoinCollection(); |
| 61 | + |
| 62 | + assertTrue(coinCollection.size() == 3); |
72 | 63 | } |
73 | | -@Test |
74 | | - void testGetMaterialComposition(){ |
75 | | - Coin Penny = new Coin(new Arraylist<>(Array.asList("copper,zinc"))) |
76 | 64 |
|
77 | | -} |
| 65 | + @Test |
| 66 | + void testGetAgeCoin() { |
| 67 | + // arrange |
| 68 | + Coins dime = new Coins(CoinType.DIME, 10, true, 10.0, 1957, List.of("nickel", "copper")); |
| 69 | + // Act |
| 70 | + int age = dime.getCoinAge(); |
| 71 | + // Assert |
| 72 | + assertEquals(1957, age); |
| 73 | + } |
| 74 | + |
| 75 | + @Test |
| 76 | + void testGetMaterialComposition() { |
| 77 | + // arrange |
| 78 | + Coins penny = new Coins(CoinType.PENNY, 1, true, 2.5, 1977, List.of("zinc", "copper")); |
| 79 | + // act |
| 80 | + List<String> materialComposition = penny.getMaterial(); |
| 81 | + // assert |
| 82 | + assertThat(materialComposition).containsExactly("zinc", "copper"); |
| 83 | + } |
| 84 | + |
| 85 | + @Test |
| 86 | + void testCannotConvert() { |
| 87 | + assertThatThrownBy( |
| 88 | + () -> { |
| 89 | + Coins.convertNickelsToDimes(0); |
| 90 | + }) |
| 91 | + .isInstanceOf(IllegalArgumentException.class) |
| 92 | + .hasMessageContaining("you do not have enough nickles"); |
| 93 | + } |
78 | 94 | } |
0 commit comments