From 0dd6ddd137b1d1814c326462c7dba319c26cf803 Mon Sep 17 00:00:00 2001 From: Devendra Tiwari Date: Tue, 19 Sep 2017 02:47:49 +0530 Subject: [PATCH] Updated test method names to BDD convention (#2643) --- .../protonpack/CollectorUtilsTests.java | 12 ++-- .../baeldung/protonpack/StreamUtilsTests.java | 56 +++++++++---------- 2 files changed, 31 insertions(+), 37 deletions(-) diff --git a/libraries/src/test/java/com/baeldung/protonpack/CollectorUtilsTests.java b/libraries/src/test/java/com/baeldung/protonpack/CollectorUtilsTests.java index 4fd21ec508..cf6a1e5ec5 100644 --- a/libraries/src/test/java/com/baeldung/protonpack/CollectorUtilsTests.java +++ b/libraries/src/test/java/com/baeldung/protonpack/CollectorUtilsTests.java @@ -16,7 +16,7 @@ import static org.hamcrest.MatcherAssert.assertThat; public class CollectorUtilsTests { @Test - public void maxByWithProjectionAndDefaultComparer() { + public void givenIntegerStream_whenCollectOnMaxByProjection_shouldReturnOptionalMaxValue() { Stream integerStream = Stream.of("a", "bb", "ccc", "1"); Optional max = integerStream.collect(maxBy(String::length)); @@ -25,7 +25,7 @@ public class CollectorUtilsTests { } @Test - public void minByWithProjectionAndDefaultComparer() { + public void givenIntegerStream_whenCollectOnMinByProjection_shouldReturnOptionalMinValue() { Stream integerStream = Stream.of("abc", "bb", "ccc", "1"); Optional max = integerStream.collect(minBy(String::length)); @@ -34,14 +34,14 @@ public class CollectorUtilsTests { } @Test - public void returnsEmptyForEmptyStream() { + public void givenEmptyStream_withCollectorUnique_shouldReturnEmpty() { assertThat(Stream .empty() .collect(CollectorUtils.unique()), equalTo(Optional.empty())); } @Test - public void returnsUniqueItem() { + public void givenIntegerStream_withCollectorUnique_shouldReturnUniqueValue() { assertThat(Stream .of(1, 2, 3) .filter(i -> i > 2) @@ -49,7 +49,7 @@ public class CollectorUtilsTests { } @Test - public void returnsUniqueNullableItem() { + public void givenIntegerStream_withUniqueNullable_shouldReturnUniqueValue() { assertThat(Stream .of(1, 2, 3) .filter(i -> i > 2) @@ -57,7 +57,7 @@ public class CollectorUtilsTests { } @Test(expected = NonUniqueValueException.class) - public void throwsExceptionIfItemIsNotUnique() { + public void givenIntegerStream_withCollectorUnique_shouldThrowNonUniqueValueException() { Stream .of(1, 2, 3) .filter(i -> i > 1) diff --git a/libraries/src/test/java/com/baeldung/protonpack/StreamUtilsTests.java b/libraries/src/test/java/com/baeldung/protonpack/StreamUtilsTests.java index 282a41e0df..37ca71287f 100644 --- a/libraries/src/test/java/com/baeldung/protonpack/StreamUtilsTests.java +++ b/libraries/src/test/java/com/baeldung/protonpack/StreamUtilsTests.java @@ -21,15 +21,7 @@ import static org.hamcrest.Matchers.*; public class StreamUtilsTests { @Test - public void createInfiniteIndex() { - LongStream indices = StreamUtils - .indices() - .limit(500); - - } - - @Test - public void zipAStreamWithIndex() { + public void givenStream_whenZipWithIndex_shouldReturnZippedStreamWithIndex() { Stream source = Stream.of("Foo", "Bar", "Baz"); List> zipped = StreamUtils @@ -40,7 +32,7 @@ public class StreamUtilsTests { } @Test - public void zipAPairOfStreams() { + public void givenTwoStreams_whenZip_shouldReturnZippedStream() { Stream streamA = Stream.of("A", "B", "C"); Stream streamB = Stream.of("Apple", "Banana", "Carrot"); @@ -52,7 +44,7 @@ public class StreamUtilsTests { } @Test - public void zipThreeStreams() { + public void givenThreeStreams_whenZip_shouldReturnZippedStream() { Stream streamA = Stream.of("A", "B", "C"); Stream streamB = Stream.of("aggravating", "banausic", "complaisant"); Stream streamC = Stream.of("Apple", "Banana", "Carrot"); @@ -65,7 +57,8 @@ public class StreamUtilsTests { } @Test - public void mergeThreeStreams() { + //givenThreeStreams_whenMerge_shouldReturnMergedStream + public void givenThreeStreams_whenMerge_shouldReturnMergedStream() { Stream streamA = Stream.of("A", "B", "C"); Stream streamB = Stream.of("apple", "banana", "carrot", "date"); Stream streamC = Stream.of("fritter", "split", "cake", "roll", "pastry"); @@ -76,7 +69,8 @@ public class StreamUtilsTests { } @Test - public void roundRobinInterleaving() { + //givenThreeStreams_whenInterleave_shouldReturnRoundRobinInterleavingStream + public void givenThreeStreams_whenInterleave_shouldReturnRoundRobinInterleavingStream() { Stream streamA = Stream.of("Peter", "Paul", "Mary"); Stream streamB = Stream.of("A", "B", "C", "D", "E"); Stream streamC = Stream.of("foo", "bar", "baz", "xyzzy"); @@ -87,7 +81,8 @@ public class StreamUtilsTests { } @Test - public void takeWhileConditionIsMet() { + //givenInfiniteStream_whenTakeWhile10_shouldReturnStreamOfSize10 + public void givenInfiniteStream_whenTakeWhile10_shouldReturnStream() { Stream infiniteInts = Stream.iterate(0, i -> i + 1); Stream finiteInts = StreamUtils.takeWhile(infiniteInts, i -> i < 10); @@ -95,7 +90,7 @@ public class StreamUtilsTests { } @Test - public void takeUntilConditionIsNotMet() { + public void givenInfiniteStream_whenTakeUntil10_shouldReturnStreamUpto10() { Stream infiniteInts = Stream.iterate(0, i -> i + 1); Stream finiteInts = StreamUtils.takeUntil(infiniteInts, i -> i > 10); @@ -103,7 +98,7 @@ public class StreamUtilsTests { } @Test - public void skipWhileConditionMet() { + public void givenIntegerStreamOfTen_whenSkipWhileLessThanFour_shouldReturnStreamFromFourToTen() { Stream ints = Stream.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); Stream skipped = StreamUtils.skipWhile(ints, i -> i < 4); List collected = skipped.collect(Collectors.toList()); @@ -112,7 +107,7 @@ public class StreamUtilsTests { } @Test - public void skipUntilConditionMet() { + public void givenIntegerStreamOfTen_whenSkipUntilFour_shouldReturnStreamFromFiveToTen() { Stream ints = Stream.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); Stream skipped = StreamUtils.skipUntil(ints, i -> i > 4); List collected = skipped.collect(Collectors.toList()); @@ -121,14 +116,14 @@ public class StreamUtilsTests { } @Test - public void unfoldUntilEmptyIsReturned() { + public void givenSeedValue_withUnfold_shouldReturnStreamAccordingToGeneratorMethod() { Stream unfolded = StreamUtils.unfold(1, i -> (i < 10) ? Optional.of(i + 1) : Optional.empty()); assertThat(unfolded.collect(Collectors.toList()), contains(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); } @Test - public void groupRunsStreamTest() { + public void giveIntegerStream_whenGroupRuns_shouldReturnListGroupItems() { Stream integerStream = Stream.of(1, 1, 2, 2, 3, 4, 5); List> runs = StreamUtils .groupRuns(integerStream) @@ -138,14 +133,14 @@ public class StreamUtilsTests { } @Test - public void aggreagateOnBiElementPredicate() { + public void givenAStream_whenAggregate_shouldReturnAggregatedStreamOnTheBasisOfBiFunction() { Stream stream = Stream.of("a1", "b1", "b2", "c1"); Stream> aggregated = StreamUtils.aggregate(stream, (e1, e2) -> e1.charAt(0) == e2.charAt(0)); assertThat(aggregated.collect(toList()), contains(asList("a1"), asList("b1", "b2"), asList("c1"))); } @Test - public void windowingOnList() { + public void givenIntegerStream_whenWindowed_shouldReturnListOfListOfItemsOfWindowSize() { Stream integerStream = Stream.of(1, 2, 3, 4, 5); List> windows = StreamUtils @@ -156,7 +151,8 @@ public class StreamUtilsTests { } @Test - public void windowingOnListTwoOverlap() { + //givenIntegerStream_whenWindowedWithWindowSizeAndSkip_shouldReturnListOfListOfWindowSizeAddingASkip + public void givenIntegerStream_whenWindowedWithWindowSizeAndSkip_shouldReturnListOfListOfWindowSizeAddingASkip() { Stream integerStream = Stream.of(1, 2, 3, 4, 5); List> windows = StreamUtils @@ -167,7 +163,7 @@ public class StreamUtilsTests { } @Test - public void windowingOnEmptyList() { + public void givenEmptyStream_whenWindowed_shouldReturnIterableWithSizeZero() { ArrayList ints = new ArrayList<>(); ints @@ -184,7 +180,7 @@ public class StreamUtilsTests { } @Test - public void windowingOnListTwoOverlapAllowLesserSize() { + public void givenIntegerStream_whenWindowedWithWindowSizeAndSkipAndAllowLesserSize_shouldReturnListOfListOfInteger() { Stream integerStream = Stream.of(1, 2, 3, 4, 5); List> windows = StreamUtils @@ -195,14 +191,12 @@ public class StreamUtilsTests { } @Test - public void windowingOnListOneOverlapAllowLesserSizeMultipleLesserWindows() { - Stream integerStream = Stream.of(1, 2, 3, 4, 5); + public void givenLimit_withIndices_shouldReturnLongStreamUptoLimit() { + LongStream indices = StreamUtils + .indices() + .limit(500); - List> windows = StreamUtils - .windowed(integerStream, 3, 1, true) - .collect(toList()); - - assertThat(windows, contains(asList(1, 2, 3), asList(2, 3, 4), asList(3, 4, 5), asList(4, 5), asList(5))); + assertThat(indices.count(), equalTo(500)); } }