forked from janbodnar/Java-Advanced
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColorBagTest.java
More file actions
76 lines (56 loc) · 1.83 KB
/
ColorBagTest.java
File metadata and controls
76 lines (56 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package com.zetcode.bag;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.Collections;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
class ColorBagTest {
private ColorBag colorBag;
@BeforeEach
void setupEach() {
colorBag = new ColorBag();
colorBag.add("red");
colorBag.add("green");
colorBag.add("yellow");
colorBag.add("blue");
colorBag.add("magenta");
colorBag.add("brown");
}
@Test
@DisplayName("added color value should be in bag")
void add() {
var newColor = "pink";
colorBag.add(newColor);
assertTrue(colorBag.contains(newColor),
"failure - added colour not it the bag");
}
@Test
@DisplayName("removed color should not be in bag")
void remove() {
var color = "green";
colorBag.remove(color);
assertFalse(colorBag.contains(color),
"failure - removed color still in bag");
}
@Test
@DisplayName("color bag should be transformed into List")
void toList() {
var myList = Arrays.asList("red","green", "yellow",
"blue", "magenta", "brown");
var colorList = colorBag.toList();
Collections.sort(myList);
Collections.sort(colorList);
assertEquals(colorList, myList,
"failure - color bag not transformed into List");
}
@Test
@DisplayName("size of a color bag should match")
void size() {
int bagSize = colorBag.size();
assertEquals(6, bagSize,
"failure - size of bag does not match");
}
}