Skip to content

Commit

Permalink
Added: tests for Consumers
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-lee committed May 16, 2015
1 parent 6d0ec1b commit 40e4cb4
Show file tree
Hide file tree
Showing 12 changed files with 458 additions and 9 deletions.
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ language: java
cache:
directories:
- "$HOME/.gradle"
- "$HOME/.m2"
- "$HOME/.m2/repository"
jdk:
- oraclejdk8
script: mvn clean test package
script: gradle clean test jar
script:
- mvn clean test package
- gradle clean test jar

after_success:
- gradle jacocoTestReport coveralls
50 changes: 50 additions & 0 deletions src/test/java/cc/kevinlee/functional/types/Consumer10Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package cc.kevinlee.functional.types;

import org.junit.Test;

import java.util.Arrays;
import java.util.List;

import static cc.kevinlee.testosterone.Testosterone.test;
import static java.util.stream.Collectors.joining;
import static org.assertj.core.api.Assertions.assertThat;

/**
* @author Lee, Seong Hyun (Kevin)
* @since 2015-05-17
*/
public class Consumer10Test implements TypesUtil {

@Test
public void testAndThen() throws Exception {
final MutablePair<Integer, String> resultPair = new MutablePair<>();

final Consumer10<Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer> first =
(i1, i2, i3, i4, i5, i6, i7, i8, i9, i10) -> resultPair.value1(i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8 + i9 + i10);
final Consumer10<Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer> second =
(i1, i2, i3, i4, i5, i6, i7, i8, i9, i10) -> resultPair.value2("Values are " + Arrays.asList(i1, i2, i3, i4, i5, i6, i7, i8, i9, i10).stream().map(String::valueOf).collect(joining(", ")));

final int input1 = 1;
final int input2 = 2;
final int input3 = 3;
final int input4 = 4;
final int input5 = 5;
final int input6 = 6;
final int input7 = 7;
final int input8 = 8;
final int input9 = 9;
final int input10 = 10;
final List<Integer> inputList = Arrays.asList(input1, input2, input3, input4, input5, input6, input7, input8, input9, input10);
final Pair<Integer, String> expected =
new ImmutablePair<>(inputList.stream().reduce(0, (prev, i) -> prev + i),
"Values are " + inputList.stream().map(String::valueOf).collect(joining(", ")));
test("Consumer10.andThen(Consumer10)", "c10.andThen(c10_2) should do c10.accept(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10) then c10_2.accept(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10). \n" +
"In other words, c10.andThen(c10_2) == c10(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10); c10_2(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10)")
.when(() ->
first.andThen(second).accept(input1, input2, input3, input4, input5, input6, input7, input8, input9, input10)
)
.then(() ->
assertThat(resultPair).isEqualTo(expected)
);
}
}
43 changes: 43 additions & 0 deletions src/test/java/cc/kevinlee/functional/types/Consumer3Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package cc.kevinlee.functional.types;

import org.junit.Test;

import java.util.Arrays;
import java.util.List;

import static cc.kevinlee.testosterone.Testosterone.test;
import static java.util.stream.Collectors.joining;
import static org.assertj.core.api.Assertions.assertThat;

/**
* @author Lee, Seong Hyun (Kevin)
* @since 2015-05-17
*/
public class Consumer3Test implements TypesUtil {

@Test
public void testAndThen() throws Exception {
final MutablePair<Integer, String> resultPair = new MutablePair<>();

final Consumer3<Integer, Integer, Integer> first =
(i1, i2, i3) -> resultPair.value1(i1 + i2 + i3);
final Consumer3<Integer, Integer, Integer> second =
(i1, i2, i3) -> resultPair.value2("Values are " + Arrays.asList(i1, i2, i3).stream().map(String::valueOf).collect(joining(", ")));

final int input1 = 1;
final int input2 = 2;
final int input3 = 3;
final List<Integer> inputList = Arrays.asList(input1, input2, input3);
final Pair<Integer, String> expected =
new ImmutablePair<>(inputList.stream().reduce(0, (prev, i) -> prev + i),
"Values are " + inputList.stream().map(String::valueOf).collect(joining(", ")));
test("Consumer3.andThen(Consumer3)", "c3.andThen(c3_2) should do c3.accept(p1, p2, p3) then c3_2.accept(p1, p2, p3). \n" +
"In other words, c3.andThen(c3_2) == c3(p1, p2, p3); c3_2(p1, p2, p3)")
.when(() ->
first.andThen(second).accept(input1, input2, input3)
)
.then(() ->
assertThat(resultPair).isEqualTo(expected)
);
}
}
44 changes: 44 additions & 0 deletions src/test/java/cc/kevinlee/functional/types/Consumer4Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package cc.kevinlee.functional.types;

import org.junit.Test;

import java.util.Arrays;
import java.util.List;

import static cc.kevinlee.testosterone.Testosterone.test;
import static java.util.stream.Collectors.joining;
import static org.assertj.core.api.Assertions.assertThat;

/**
* @author Lee, Seong Hyun (Kevin)
* @since 2015-05-17
*/
public class Consumer4Test implements TypesUtil {

@Test
public void testAndThen() throws Exception {
final MutablePair<Integer, String> resultPair = new MutablePair<>();

final Consumer4<Integer, Integer, Integer, Integer> first =
(i1, i2, i3, i4) -> resultPair.value1(i1 + i2 + i3 + i4);
final Consumer4<Integer, Integer, Integer, Integer> second =
(i1, i2, i3, i4) -> resultPair.value2("Values are " + Arrays.asList(i1, i2, i3, i4).stream().map(String::valueOf).collect(joining(", ")));

final int input1 = 1;
final int input2 = 2;
final int input3 = 3;
final int input4 = 4;
final List<Integer> inputList = Arrays.asList(input1, input2, input3, input4);
final Pair<Integer, String> expected =
new ImmutablePair<>(inputList.stream().reduce(0, (prev, i) -> prev + i),
"Values are " + inputList.stream().map(String::valueOf).collect(joining(", ")));
test("Consumer4.andThen(Consumer4)", "c4.andThen(c4_2) should do c4.accept(p1, p2, p3, p4) then c4_2.accept(p1, p2, p3, p4). \n" +
"In other words, c4.andThen(c4_2) == c4(p1, p2, p3, p4); c4_2(p1, p2, p3, p4)")
.when(() ->
first.andThen(second).accept(input1, input2, input3, input4)
)
.then(() ->
assertThat(resultPair).isEqualTo(expected)
);
}
}
45 changes: 45 additions & 0 deletions src/test/java/cc/kevinlee/functional/types/Consumer5Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package cc.kevinlee.functional.types;

import org.junit.Test;

import java.util.Arrays;
import java.util.List;

import static cc.kevinlee.testosterone.Testosterone.test;
import static java.util.stream.Collectors.joining;
import static org.assertj.core.api.Assertions.assertThat;

/**
* @author Lee, Seong Hyun (Kevin)
* @since 2015-05-17
*/
public class Consumer5Test implements TypesUtil {

@Test
public void testAndThen() throws Exception {
final MutablePair<Integer, String> resultPair = new MutablePair<>();

final Consumer5<Integer, Integer, Integer, Integer, Integer> first =
(i1, i2, i3, i4, i5) -> resultPair.value1(i1 + i2 + i3 + i4 + i5);
final Consumer5<Integer, Integer, Integer, Integer, Integer> second =
(i1, i2, i3, i4, i5) -> resultPair.value2("Values are " + Arrays.asList(i1, i2, i3, i4, i5).stream().map(String::valueOf).collect(joining(", ")));

final int input1 = 1;
final int input2 = 2;
final int input3 = 3;
final int input4 = 4;
final int input5 = 5;
final List<Integer> inputList = Arrays.asList(input1, input2, input3, input4, input5);
final Pair<Integer, String> expected =
new ImmutablePair<>(inputList.stream().reduce(0, (prev, i) -> prev + i),
"Values are " + inputList.stream().map(String::valueOf).collect(joining(", ")));
test("Consumer5.andThen(Consumer5)", "c5.andThen(c5_2) should do c5.accept(p1, p2, p3, p4, p5) then c5_2.accept(p1, p2, p3, p4, p5). \n" +
"In other words, c5.andThen(c5_2) == c5(p1, p2, p3, p4, p5); c5_2(p1, p2, p3, p4, p5)")
.when(() ->
first.andThen(second).accept(input1, input2, input3, input4, input5)
)
.then(() ->
assertThat(resultPair).isEqualTo(expected)
);
}
}
46 changes: 46 additions & 0 deletions src/test/java/cc/kevinlee/functional/types/Consumer6Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package cc.kevinlee.functional.types;

import org.junit.Test;

import java.util.Arrays;
import java.util.List;

import static cc.kevinlee.testosterone.Testosterone.test;
import static java.util.stream.Collectors.joining;
import static org.assertj.core.api.Assertions.assertThat;

/**
* @author Lee, Seong Hyun (Kevin)
* @since 2015-05-17
*/
public class Consumer6Test implements TypesUtil {

@Test
public void testAndThen() throws Exception {
final MutablePair<Integer, String> resultPair = new MutablePair<>();

final Consumer6<Integer, Integer, Integer, Integer, Integer, Integer> first =
(i1, i2, i3, i4, i5, i6) -> resultPair.value1(i1 + i2 + i3 + i4 + i5 + i6);
final Consumer6<Integer, Integer, Integer, Integer, Integer, Integer> second =
(i1, i2, i3, i4, i5, i6) -> resultPair.value2("Values are " + Arrays.asList(i1, i2, i3, i4, i5, i6).stream().map(String::valueOf).collect(joining(", ")));

final int input1 = 1;
final int input2 = 2;
final int input3 = 3;
final int input4 = 4;
final int input5 = 5;
final int input6 = 6;
final List<Integer> inputList = Arrays.asList(input1, input2, input3, input4, input5, input6);
final Pair<Integer, String> expected =
new ImmutablePair<>(inputList.stream().reduce(0, (prev, i) -> prev + i),
"Values are " + inputList.stream().map(String::valueOf).collect(joining(", ")));
test("Consumer6.andThen(Consumer6)", "c6.andThen(c6_2) should do c6.accept(p1, p2, p3, p4, p5, p6) then c6_2.accept(p1, p2, p3, p4, p5, p6). \n" +
"In other words, c6.andThen(c6_2) == c6(p1, p2, p3, p4, p5, p6); c6_2(p1, p2, p3, p4, p5, p6)")
.when(() ->
first.andThen(second).accept(input1, input2, input3, input4, input5, input6)
)
.then(() ->
assertThat(resultPair).isEqualTo(expected)
);
}
}
47 changes: 47 additions & 0 deletions src/test/java/cc/kevinlee/functional/types/Consumer7Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package cc.kevinlee.functional.types;

import org.junit.Test;

import java.util.Arrays;
import java.util.List;

import static cc.kevinlee.testosterone.Testosterone.test;
import static java.util.stream.Collectors.joining;
import static org.assertj.core.api.Assertions.assertThat;

/**
* @author Lee, Seong Hyun (Kevin)
* @since 2015-05-17
*/
public class Consumer7Test implements TypesUtil {

@Test
public void testAndThen() throws Exception {
final MutablePair<Integer, String> resultPair = new MutablePair<>();

final Consumer7<Integer, Integer, Integer, Integer, Integer, Integer, Integer> first =
(i1, i2, i3, i4, i5, i6, i7) -> resultPair.value1(i1 + i2 + i3 + i4 + i5 + i6 + i7);
final Consumer7<Integer, Integer, Integer, Integer, Integer, Integer, Integer> second =
(i1, i2, i3, i4, i5, i6, i7) -> resultPair.value2("Values are " + Arrays.asList(i1, i2, i3, i4, i5, i6, i7).stream().map(String::valueOf).collect(joining(", ")));

final int input1 = 1;
final int input2 = 2;
final int input3 = 3;
final int input4 = 4;
final int input5 = 5;
final int input6 = 6;
final int input7 = 7;
final List<Integer> inputList = Arrays.asList(input1, input2, input3, input4, input5, input6, input7);
final Pair<Integer, String> expected =
new ImmutablePair<>(inputList.stream().reduce(0, (prev, i) -> prev + i),
"Values are " + inputList.stream().map(String::valueOf).collect(joining(", ")));
test("Consumer7.andThen(Consumer7)", "c7.andThen(c7_2) should do c7.accept(p1, p2, p3, p4, p5, p6, p7) then c7_2.accept(p1, p2, p3, p4, p5, p6, p7). \n" +
"In other words, c7.andThen(c7_2) == c7(p1, p2, p3, p4, p5, p6, p7); c7_2(p1, p2, p3, p4, p5, p6, p7)")
.when(() ->
first.andThen(second).accept(input1, input2, input3, input4, input5, input6, input7)
)
.then(() ->
assertThat(resultPair).isEqualTo(expected)
);
}
}
48 changes: 48 additions & 0 deletions src/test/java/cc/kevinlee/functional/types/Consumer8Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package cc.kevinlee.functional.types;

import org.junit.Test;

import java.util.Arrays;
import java.util.List;

import static cc.kevinlee.testosterone.Testosterone.test;
import static java.util.stream.Collectors.joining;
import static org.assertj.core.api.Assertions.assertThat;

/**
* @author Lee, Seong Hyun (Kevin)
* @since 2015-05-17
*/
public class Consumer8Test implements TypesUtil {

@Test
public void testAndThen() throws Exception {
final MutablePair<Integer, String> resultPair = new MutablePair<>();

final Consumer8<Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer> first =
(i1, i2, i3, i4, i5, i6, i7, i8) -> resultPair.value1(i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8);
final Consumer8<Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer> second =
(i1, i2, i3, i4, i5, i6, i7, i8) -> resultPair.value2("Values are " + Arrays.asList(i1, i2, i3, i4, i5, i6, i7, i8).stream().map(String::valueOf).collect(joining(", ")));

final int input1 = 1;
final int input2 = 2;
final int input3 = 3;
final int input4 = 4;
final int input5 = 5;
final int input6 = 6;
final int input7 = 7;
final int input8 = 8;
final List<Integer> inputList = Arrays.asList(input1, input2, input3, input4, input5, input6, input7, input8);
final Pair<Integer, String> expected =
new ImmutablePair<>(inputList.stream().reduce(0, (prev, i) -> prev + i),
"Values are " + inputList.stream().map(String::valueOf).collect(joining(", ")));
test("Consumer8.andThen(Consumer8)", "c8.andThen(c8_2) should do c8.accept(p1, p2, p3, p4, p5, p6, p7, p8) then c8_2.accept(p1, p2, p3, p4, p5, p6, p7, p8). \n" +
"In other words, c8.andThen(c8_2) == c8(p1, p2, p3, p4, p5, p6, p7, p8); c8_2(p1, p2, p3, p4, p5, p6, p7, p8)")
.when(() ->
first.andThen(second).accept(input1, input2, input3, input4, input5, input6, input7, input8)
)
.then(() ->
assertThat(resultPair).isEqualTo(expected)
);
}
}
Loading

0 comments on commit 40e4cb4

Please sign in to comment.