|
7 | 7 | import static org.hamcrest.core.Is.is;
|
8 | 8 | import static org.junit.Assert.assertThat;
|
9 | 9 |
|
10 |
| -import java.util.ArrayList; |
11 |
| -import java.util.List; |
12 |
| - |
13 | 10 | import com.greghaskins.spectrum.Spectrum;
|
14 | 11 | import com.greghaskins.spectrum.Variable;
|
| 12 | + |
15 | 13 | import org.junit.runner.RunWith;
|
16 | 14 |
|
| 15 | +import java.util.ArrayList; |
| 16 | +import java.util.List; |
| 17 | + |
17 | 18 | @RunWith(Spectrum.class)
|
18 | 19 | public class UnboxerSpecs {
|
19 |
| - { |
20 |
| - describe("Using unboxer on let", () -> { |
21 |
| - List<String> list = unbox(let(ArrayList::new), List.class); |
22 |
| - |
23 |
| - it("can use the object as though it was not in a supplier", () -> { |
24 |
| - list.add("Hello"); |
25 |
| - assertThat(list.get(0), is("Hello")); |
26 |
| - }); |
27 |
| - |
28 |
| - it("can use multi-parameter methods correctly", () -> { |
29 |
| - list.add("a"); |
30 |
| - list.add("b"); |
31 |
| - list.add(0, "_"); |
32 |
| - |
33 |
| - assertThat(list.size(), is(3)); |
34 |
| - assertThat(list.get(0), is("_")); |
35 |
| - }); |
36 |
| - }); |
37 |
| - |
38 |
| - describe("Using unboxer with variable", () -> { |
39 |
| - Variable<ArrayList<String>> listVariable = new Variable<>(new ArrayList<>()); |
40 |
| - List<String> list = unbox(listVariable, List.class); |
41 |
| - |
42 |
| - it("can read the variable contents", () -> { |
43 |
| - list.add("World"); |
44 |
| - assertThat(list.size(), is(1)); |
45 |
| - assertThat(list.get(0), is("World")); |
46 |
| - }); |
47 |
| - |
48 |
| - it("can still read the same list in the next spec", () -> { |
49 |
| - assertThat(list.size(), is(1)); |
50 |
| - }); |
51 |
| - |
52 |
| - it("can reset the content via the original variable object", () -> { |
53 |
| - listVariable.set(new ArrayList<>()); |
54 |
| - assertThat(list.size(), is(0)); |
55 |
| - }); |
56 |
| - }); |
57 |
| - } |
| 20 | + { |
| 21 | + describe("Using unboxer on let", () -> { |
| 22 | + List<String> list = unbox(let(ArrayList::new), List.class); |
| 23 | + |
| 24 | + it("can use the object as though it was not in a supplier", () -> { |
| 25 | + list.add("Hello"); |
| 26 | + assertThat(list.get(0), is("Hello")); |
| 27 | + }); |
| 28 | + |
| 29 | + it("can use multi-parameter methods correctly", () -> { |
| 30 | + list.add("a"); |
| 31 | + list.add("b"); |
| 32 | + list.add(0, "_"); |
| 33 | + |
| 34 | + assertThat(list.size(), is(3)); |
| 35 | + assertThat(list.get(0), is("_")); |
| 36 | + }); |
| 37 | + }); |
| 38 | + |
| 39 | + describe("Using unboxer with variable", () -> { |
| 40 | + Variable<ArrayList<String>> listVariable = new Variable<>(new ArrayList<>()); |
| 41 | + List<String> list = unbox(listVariable, List.class); |
| 42 | + |
| 43 | + it("can read the variable contents", () -> { |
| 44 | + list.add("World"); |
| 45 | + assertThat(list.size(), is(1)); |
| 46 | + assertThat(list.get(0), is("World")); |
| 47 | + }); |
| 48 | + |
| 49 | + it("can still read the same list in the next spec", () -> { |
| 50 | + assertThat(list.size(), is(1)); |
| 51 | + }); |
| 52 | + |
| 53 | + it("can reset the content via the original variable object", () -> { |
| 54 | + listVariable.set(new ArrayList<>()); |
| 55 | + assertThat(list.size(), is(0)); |
| 56 | + }); |
| 57 | + }); |
| 58 | + } |
58 | 59 | }
|
0 commit comments