Skip to content

Commit 33a1e5d

Browse files
authored
Merge pull request functionaljava#381 from gliptak/coverage21
Add Integers tests
2 parents 84953a2 + 68625ac commit 33a1e5d

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package fj.function;
2+
3+
import org.junit.Test;
4+
5+
import java.lang.reflect.Constructor;
6+
import java.lang.reflect.InvocationTargetException;
7+
8+
import static fj.data.List.list;
9+
import static fj.data.Option.none;
10+
import static org.hamcrest.core.Is.is;
11+
import static org.junit.Assert.*;
12+
13+
public class IntegersTest {
14+
15+
@Test
16+
public void testSum() {
17+
assertThat(Integers.sum(list(3, 4, 5)), is(12));
18+
}
19+
20+
@Test
21+
public void testProduct() {
22+
assertThat(Integers.product(list(3, 4, 5)), is(60));
23+
}
24+
25+
@Test
26+
public void testAdd() {
27+
assertThat(Integers.add.f(10).f(20), is(30));
28+
}
29+
30+
@Test
31+
public void testMultiply() {
32+
assertThat(Integers.multiply.f(3).f(5), is(15));
33+
}
34+
35+
@Test
36+
public void testAbs() {
37+
assertThat(Integers.abs.f(-5), is(5));
38+
}
39+
40+
@Test
41+
public void testFromString() {
42+
assertThat(Integers.fromString().f("-123").some(), is(-123));
43+
}
44+
45+
@Test
46+
public void testFromStringFail() {
47+
assertThat(Integers.fromString().f("w"), is(none()));
48+
}
49+
50+
@Test
51+
public void testCannotInstantiate() throws NoSuchMethodException, IllegalAccessException, InstantiationException {
52+
Constructor<Integers> constructor = Integers.class.getDeclaredConstructor();
53+
constructor.setAccessible(true);
54+
try {
55+
constructor.newInstance();
56+
fail("expected InvocationTargetException");
57+
} catch (InvocationTargetException ite) {
58+
assertTrue(ite.getCause() instanceof UnsupportedOperationException);
59+
}
60+
}
61+
62+
}

0 commit comments

Comments
 (0)