Skip to content

Commit a323d64

Browse files
Blue Montag SoftwareKevinGilmore
authored andcommitted
JIRA issue : BAEL-960. Collection Factory Methods for Vavr. User: ignaciogallego@gmail.com (eugenp#2517)
* New test class for the collections factory methods in vavr * rename unit test for collection factory methods
1 parent 1ced2a3 commit a323d64

1 file changed

Lines changed: 107 additions & 0 deletions

File tree

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
package com.baeldung.vavr.collections;
2+
3+
import static io.vavr.API.Array;
4+
import static io.vavr.API.Failure;
5+
import static io.vavr.API.List;
6+
import static io.vavr.API.None;
7+
import static io.vavr.API.Some;
8+
import static io.vavr.API.Stream;
9+
import static io.vavr.API.Success;
10+
import static io.vavr.API.Tuple;
11+
import static io.vavr.API.Vector;
12+
import static org.junit.Assert.assertEquals;
13+
import static org.junit.Assert.assertFalse;
14+
import static org.junit.Assert.assertTrue;
15+
16+
import org.junit.Test;
17+
18+
import io.vavr.Tuple3;
19+
import io.vavr.collection.Array;
20+
import io.vavr.collection.List;
21+
import io.vavr.collection.Stream;
22+
import io.vavr.collection.Vector;
23+
import io.vavr.control.Option;
24+
import io.vavr.control.Try;
25+
26+
public class CollectionFactoryMethodsUnitTest {
27+
28+
@Test
29+
public void givenANoneOptionElement_whenCreated_thenCorrect() {
30+
Option<Integer> none = None();
31+
assertFalse(none == null);
32+
assertEquals(none, Option.none());
33+
}
34+
35+
@Test
36+
public void givenASomeOptionElement_whenCreated_thenCorrect() {
37+
Option<Integer> some = Some(1);
38+
assertFalse(some == null);
39+
assertTrue(some.contains(1));
40+
}
41+
42+
@Test
43+
public void givenATupleElement_whenCreated_thenCorrect() {
44+
Tuple3<Character, String, Integer> tuple = Tuple('a', "chain", 2);
45+
assertTrue(tuple!=null);
46+
assertEquals(tuple._1(), new Character('a'));
47+
assertEquals(tuple._2(), "chain");
48+
assertEquals(tuple._3().intValue(), 2);
49+
}
50+
51+
@Test
52+
public void givenASuccessObject_whenEvaluated_thenSuccess() {
53+
Try<Integer> integer = Success(55);
54+
assertEquals(integer.get().intValue(), 55);
55+
}
56+
@Test
57+
public void givenAFailureObject_whenEvaluated_thenExceptionThrown() {
58+
Try<Integer> failure = Failure(new Exception("Exception X encapsulated here"));
59+
60+
try {
61+
Integer i = failure.get();// evaluate a failure raise the exception
62+
System.out.println(i);// not executed
63+
} catch (Exception e) {
64+
assertEquals(e.getMessage(), "Exception X encapsulated here");
65+
}
66+
}
67+
68+
@Test
69+
public void givenAList_whenCreated_thenCorrect() {
70+
List<Integer> list = List(1, 2, 3, 4, 5);
71+
72+
assertEquals(list.size(), 5);
73+
assertEquals(list.get(0).intValue(), 1);
74+
}
75+
76+
@Test
77+
public void givenAnEmptyList_whenCreated_thenCorrect() {
78+
List<Integer> empty = List();
79+
80+
assertEquals(empty.size(), 0);
81+
assertEquals(empty, List.empty());
82+
}
83+
84+
@Test
85+
public void givenAnArray_whenCreated_thenCorrect() {
86+
Array<Integer> array = Array(1, 2, 3, 4, 5);
87+
88+
assertEquals(array.size(), 5);
89+
assertEquals(array.get(0).intValue(), 1);
90+
}
91+
92+
@Test
93+
public void givenAStream_whenCreated_thenCorrect() {
94+
Stream<Integer> stream = Stream(1, 2, 3, 4, 5);
95+
96+
assertEquals(stream.size(), 5);
97+
assertEquals(stream.get(0).intValue(), 1);
98+
}
99+
100+
@Test
101+
public void givenAVector_whenCreated_thenCorrect() {
102+
Vector<Integer> vector = Vector(1, 2, 3, 4, 5);
103+
104+
assertEquals(vector.size(), 5);
105+
assertEquals(vector.get(0).intValue(), 1);
106+
}
107+
}

0 commit comments

Comments
 (0)