Skip to content

Commit 0582fc1

Browse files
committed
improve tests
1 parent 0ddc49f commit 0582fc1

28 files changed

+479
-74
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package io.github.benas.unixstream;
2+
3+
import org.junit.Test;
4+
5+
import static org.assertj.core.api.Assertions.assertThat;
6+
7+
public class PredicatesTest {
8+
9+
@Test
10+
public void nonNull() throws Exception {
11+
assertThat(Predicates.nonNull().test(1)).isTrue();
12+
assertThat(Predicates.nonNull().test(null)).isFalse();
13+
}
14+
15+
@Test
16+
public void isNull() throws Exception {
17+
assertThat(Predicates.isNull().test(1)).isFalse();
18+
assertThat(Predicates.isNull().test(null)).isTrue();
19+
}
20+
21+
@Test
22+
public void empty() throws Exception {
23+
assertThat(Predicates.empty().test("")).isTrue();
24+
assertThat(Predicates.empty().test("a")).isFalse();
25+
}
26+
27+
@Test
28+
public void startsWith() throws Exception {
29+
assertThat(Predicates.startsWith("a").test("ab")).isTrue();
30+
assertThat(Predicates.startsWith("a").test("cd")).isFalse();
31+
}
32+
33+
@Test
34+
public void endsWith() throws Exception {
35+
assertThat(Predicates.endsWith("b").test("ab")).isTrue();
36+
assertThat(Predicates.endsWith("b").test("cd")).isFalse();
37+
}
38+
39+
@Test
40+
public void matches() throws Exception {
41+
assertThat(Predicates.matches("a*").test("aa")).isTrue();
42+
assertThat(Predicates.matches("a*").test("bb")).isFalse();
43+
}
44+
45+
@Test
46+
public void even() throws Exception {
47+
assertThat(Predicates.even().test(2)).isTrue();
48+
assertThat(Predicates.even().test(1)).isFalse();
49+
}
50+
51+
@Test
52+
public void odd() throws Exception {
53+
assertThat(Predicates.odd().test(1)).isTrue();
54+
assertThat(Predicates.odd().test(2)).isFalse();
55+
}
56+
57+
@Test
58+
public void isZero() throws Exception {
59+
assertThat(Predicates.isZero().test(0)).isTrue();
60+
assertThat(Predicates.isZero().test(1)).isFalse();
61+
}
62+
63+
}

src/test/java/io/github/benas/unixstream/UnixStreamImplTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,8 @@ public void integrationTest3() throws IOException {
6262
assertThat(items).isNotNull().isNotEmpty().hasSize(2).containsExactly("name", "bar");
6363
}
6464

65+
@Test
66+
public void getShouldReturnTheOriginalStream() throws Exception {
67+
assertThat(UnixStream.unixify(stream).get()).isEqualTo(stream);
68+
}
6569
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package io.github.benas.unixstream.components;
2+
3+
import io.github.benas.unixstream.UnixStream;
4+
import org.junit.Test;
5+
6+
import java.io.IOException;
7+
import java.nio.file.Paths;
8+
9+
import static org.assertj.core.api.Assertions.assertThat;
10+
11+
public class CatTest {
12+
13+
private static final String TEST_RESOURCES_DIRECTORY = "src/test/resources";
14+
15+
@Test
16+
public void cat() throws IOException {
17+
UnixStream<String> unixStream = UnixStream.cat(Paths.get(TEST_RESOURCES_DIRECTORY, "input.txt"));
18+
19+
assertThat(unixStream).containsExactly("1,foo", "2,bar");
20+
}
21+
}

src/test/java/io/github/benas/unixstream/components/CompactTest.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package io.github.benas.unixstream.components;
22

3-
import static org.assertj.core.api.Assertions.assertThat;
3+
import io.github.benas.unixstream.UnixStream;
4+
import org.junit.Before;
5+
import org.junit.Test;
46

5-
import java.util.Arrays;
67
import java.util.List;
78
import java.util.stream.Collectors;
89
import java.util.stream.Stream;
9-
import org.junit.Before;
10+
11+
import static org.assertj.core.api.Assertions.assertThat;
1012

1113
public class CompactTest {
1214

@@ -23,7 +25,14 @@ public void setUp() {
2325
@org.junit.Test
2426
public void apply() {
2527
List<String> strings = compact.apply(stream).collect(Collectors.toList());
26-
27-
assertThat(strings).isNotEmpty().isEqualTo(Arrays.asList("ab", "cd"));
28+
29+
assertThat(strings).containsExactly("ab", "cd");
30+
}
31+
32+
@Test
33+
public void compact() throws Exception {
34+
UnixStream<String> unixStream = UnixStream.from(Stream.of(" f o o ")).compact();
35+
36+
assertThat(unixStream).containsExactly("foo");
2837
}
2938
}

src/test/java/io/github/benas/unixstream/components/ConcatTest.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.github.benas.unixstream.components;
22

3+
import io.github.benas.unixstream.UnixStream;
34
import org.junit.Before;
45
import org.junit.Test;
56

@@ -22,9 +23,29 @@ public void setUp() throws Exception {
2223
}
2324

2425
@Test
25-
public void testApply() throws Exception {
26+
public void apply() throws Exception {
2627
List<String> strings = concat.apply(stream).collect(Collectors.toList());
2728

28-
assertThat(strings).isNotEmpty().hasSize(4).containsExactly("a", "b", "c", "d");
29+
assertThat(strings).containsExactly("a", "b", "c", "d");
30+
}
31+
32+
@Test
33+
public void concatWithAnotherStream() throws Exception {
34+
Stream<String> stream1 = Stream.of("foo");
35+
Stream<String> stream2 = Stream.of("bar");
36+
37+
UnixStream<String> stream = UnixStream.unixify(stream1).concat(stream2);
38+
39+
assertThat(stream).containsExactly("foo", "bar");
40+
}
41+
42+
@Test
43+
public void concatTwoStreams() throws Exception {
44+
Stream<String> stream1 = Stream.of("foo");
45+
Stream<String> stream2 = Stream.of("bar");
46+
47+
UnixStream<String> stream = UnixStream.concat(stream1, stream2);
48+
49+
assertThat(stream).containsExactly("foo", "bar");
2950
}
3051
}

src/test/java/io/github/benas/unixstream/components/CutTest.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.github.benas.unixstream.components;
22

3+
import io.github.benas.unixstream.UnixStream;
34
import org.junit.Before;
45
import org.junit.Test;
56

@@ -35,15 +36,21 @@ public void create_whenFiledIsLessThanOne() {
3536
public void apply() {
3637
List<String> strings = cut.apply(stream).collect(Collectors.toList());
3738

38-
assertThat(strings).isNotEmpty().hasSize(2).containsExactly("b", "d");
39+
assertThat(strings).containsExactly("b", "d");
3940
}
4041

4142
@Test
4243
public void apply_whenFieldIsOutOfRange() {
4344
cut = Cut.cut(";", 3);
4445
List<String> strings = cut.apply(stream).collect(Collectors.toList());
4546

46-
assertThat(strings).isNotEmpty().hasSize(2).containsExactly("", "");
47+
assertThat(strings).containsExactly("", "");
4748
}
4849

50+
@Test
51+
public void cut() throws Exception {
52+
UnixStream<String> unixStream = UnixStream.unixify(stream).cut(";", 2);
53+
54+
assertThat(unixStream).containsExactly("b", "d");
55+
}
4956
}

src/test/java/io/github/benas/unixstream/components/Dos2UnixTest.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package io.github.benas.unixstream.components;
22

3-
import static org.assertj.core.api.Assertions.assertThat;
3+
import io.github.benas.unixstream.UnixStream;
4+
import org.junit.Before;
5+
import org.junit.Test;
46

57
import java.util.List;
68
import java.util.stream.Collectors;
79
import java.util.stream.Stream;
8-
import org.junit.Before;
9-
import org.junit.Test;
10+
11+
import static org.assertj.core.api.Assertions.assertThat;
1012

1113
public class Dos2UnixTest {
1214

@@ -24,6 +26,13 @@ public void setUp() {
2426
public void apply() {
2527
List<String> strings = dos2Unix.apply(stream).collect(Collectors.toList());
2628

27-
assertThat(strings).isNotEmpty().hasSize(2).containsExactly("a\n", "b\nc\n");
29+
assertThat(strings).containsExactly("a\n", "b\nc\n");
30+
}
31+
32+
@Test
33+
public void dos2unix() throws Exception {
34+
UnixStream<String> unixStream = UnixStream.unixify(stream).dos2unix();
35+
36+
assertThat(unixStream).containsExactly("a\n", "b\nc\n");
2837
}
2938
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package io.github.benas.unixstream.components;
2+
3+
import io.github.benas.unixstream.UnixStream;
4+
import org.junit.Test;
5+
6+
import java.io.IOException;
7+
8+
import static org.assertj.core.api.Assertions.assertThat;
9+
10+
public class EchoTest {
11+
12+
@Test
13+
public void echo() throws IOException {
14+
UnixStream<String> stream = UnixStream.echo("hello");
15+
16+
assertThat(stream).containsExactly("hello");
17+
}
18+
}

src/test/java/io/github/benas/unixstream/components/ExcludeTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package io.github.benas.unixstream.components;
22

3+
import io.github.benas.unixstream.Predicates;
4+
import io.github.benas.unixstream.UnixStream;
35
import org.junit.Before;
46
import org.junit.Test;
57

@@ -28,4 +30,11 @@ public void apply() {
2830

2931
assertThat(strings).isNotEmpty().hasSize(1).containsExactly("bc");
3032
}
33+
34+
@Test
35+
public void exclude() throws Exception {
36+
UnixStream<String> unixStream = UnixStream.from(stream).exclude(Predicates.contains("a"));
37+
38+
assertThat(unixStream).containsExactly("bc");
39+
}
3140
}

src/test/java/io/github/benas/unixstream/components/ExpandTest.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package io.github.benas.unixstream.components;
22

3-
import static org.assertj.core.api.Assertions.assertThat;
3+
import io.github.benas.unixstream.UnixStream;
4+
import org.junit.Before;
5+
import org.junit.Test;
46

5-
import java.util.Arrays;
67
import java.util.List;
78
import java.util.stream.Collectors;
89
import java.util.stream.Stream;
9-
import org.junit.Before;
10+
11+
import static org.assertj.core.api.Assertions.assertThat;
1012

1113
public class ExpandTest {
1214

@@ -21,10 +23,17 @@ public void setUp() {
2123

2224
}
2325

24-
@org.junit.Test
26+
@Test
2527
public void apply() {
2628
List<String> strings = expand.apply(stream).collect(Collectors.toList());
27-
28-
assertThat(strings).isNotEmpty().isEqualTo(Arrays.asList("a b", "c d"));
29+
30+
assertThat(strings).containsExactly("a b", "c d");
31+
}
32+
33+
@Test
34+
public void expand() throws Exception {
35+
UnixStream<String> unixStream = UnixStream.from(stream).expand();
36+
37+
assertThat(unixStream).containsExactly("a b", "c d");
2938
}
3039
}

0 commit comments

Comments
 (0)