Refactor stream with indices (#2565)
* Refactor RxJava * Refactor Stream with indices
This commit is contained in:
parent
830db34334
commit
7916882668
|
@ -1,18 +1,17 @@
|
||||||
package com.baeldung.stream;
|
package com.baeldung.stream;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import com.codepoetics.protonpack.Indexed;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.Test;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
import com.codepoetics.protonpack.Indexed;
|
|
||||||
|
|
||||||
public class StreamIndicesTest {
|
public class StreamIndicesTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenArray_whenGetIndexedStrings_thenReturnListOfEvenIndexedStrings() {
|
public void whenCalled_thenReturnListOfEvenIndexedStrings() {
|
||||||
String[] names = {"Afrim", "Bashkim", "Besim", "Lulzim", "Durim", "Shpetim"};
|
String[] names = {"Afrim", "Bashkim", "Besim", "Lulzim", "Durim", "Shpetim"};
|
||||||
List<String> expectedResult = Arrays.asList("Afrim", "Besim", "Durim");
|
List<String> expectedResult = Arrays.asList("Afrim", "Besim", "Durim");
|
||||||
List<String> actualResult = StreamIndices.getEvenIndexedStrings(names);
|
List<String> actualResult = StreamIndices.getEvenIndexedStrings(names);
|
||||||
|
@ -21,7 +20,7 @@ public class StreamIndicesTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenArray_whenGetIndexedStrings_thenReturnListOfEvenIndexedStringsVersionTwo() {
|
public void whenCalled_thenReturnListOfEvenIndexedStringsVersionTwo() {
|
||||||
String[] names = {"Afrim", "Bashkim", "Besim", "Lulzim", "Durim", "Shpetim"};
|
String[] names = {"Afrim", "Bashkim", "Besim", "Lulzim", "Durim", "Shpetim"};
|
||||||
List<String> expectedResult = Arrays.asList("Afrim", "Besim", "Durim");
|
List<String> expectedResult = Arrays.asList("Afrim", "Besim", "Durim");
|
||||||
List<String> actualResult = StreamIndices.getEvenIndexedStrings(names);
|
List<String> actualResult = StreamIndices.getEvenIndexedStrings(names);
|
||||||
|
@ -30,7 +29,7 @@ public class StreamIndicesTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenArray_whenGetIndexedStrings_thenReturnListOfOddStrings() {
|
public void whenCalled_thenReturnListOfOddStrings() {
|
||||||
String[] names = {"Afrim", "Bashkim", "Besim", "Lulzim", "Durim", "Shpetim"};
|
String[] names = {"Afrim", "Bashkim", "Besim", "Lulzim", "Durim", "Shpetim"};
|
||||||
List<String> expectedResult = Arrays.asList("Bashkim", "Lulzim", "Shpetim");
|
List<String> expectedResult = Arrays.asList("Bashkim", "Lulzim", "Shpetim");
|
||||||
List<String> actualResult = StreamIndices.getOddIndexedStrings(names);
|
List<String> actualResult = StreamIndices.getOddIndexedStrings(names);
|
||||||
|
@ -39,30 +38,33 @@ public class StreamIndicesTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenList_whenGetIndexedStrings_thenReturnListOfEvenIndexedStrings() {
|
public void givenList_whenCalled_thenReturnListOfEvenIndexedStrings() {
|
||||||
List<String> names = Arrays.asList("Afrim", "Bashkim", "Besim", "Lulzim", "Durim", "Shpetim");
|
List<String> names = Arrays.asList("Afrim", "Bashkim", "Besim", "Lulzim", "Durim", "Shpetim");
|
||||||
List<Indexed<String>> expectedResult = Arrays.asList(Indexed.index(0, "Afrim"), Indexed.index(2, "Besim"), Indexed.index(4, "Durim"));
|
List<Indexed<String>> expectedResult = Arrays
|
||||||
|
.asList(Indexed.index(0, "Afrim"), Indexed.index(2, "Besim"), Indexed
|
||||||
|
.index(4, "Durim"));
|
||||||
List<Indexed<String>> actualResult = StreamIndices.getEvenIndexedStrings(names);
|
List<Indexed<String>> actualResult = StreamIndices.getEvenIndexedStrings(names);
|
||||||
|
|
||||||
assertEquals(expectedResult, actualResult);
|
assertEquals(expectedResult, actualResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenList_whenGetIndexedStrings_thenReturnListOfOddIndexedStrings() {
|
public void givenList_whenCalled_thenReturnListOfOddIndexedStrings() {
|
||||||
List<String> names = Arrays.asList("Afrim", "Bashkim", "Besim", "Lulzim", "Durim", "Shpetim");
|
List<String> names = Arrays.asList("Afrim", "Bashkim", "Besim", "Lulzim", "Durim", "Shpetim");
|
||||||
List<Indexed<String>> expectedResult = Arrays.asList(Indexed.index(1, "Bashkim"), Indexed.index(3, "Lulzim"), Indexed.index(5, "Shpetim"));
|
List<Indexed<String>> expectedResult = Arrays
|
||||||
|
.asList(Indexed.index(1, "Bashkim"), Indexed.index(3, "Lulzim"), Indexed
|
||||||
|
.index(5, "Shpetim"));
|
||||||
List<Indexed<String>> actualResult = StreamIndices.getOddIndexedStrings(names);
|
List<Indexed<String>> actualResult = StreamIndices.getOddIndexedStrings(names);
|
||||||
|
|
||||||
assertEquals(expectedResult, actualResult);
|
assertEquals(expectedResult, actualResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenArray_whenGetIndexedStrings_thenReturnListOfOddStringsVersionTwo() {
|
public void whenCalled_thenReturnListOfOddStringsVersionTwo() {
|
||||||
String[] names = {"Afrim", "Bashkim", "Besim", "Lulzim", "Durim", "Shpetim"};
|
String[] names = {"Afrim", "Bashkim", "Besim", "Lulzim", "Durim", "Shpetim"};
|
||||||
List<String> expectedResult = Arrays.asList("Bashkim", "Lulzim", "Shpetim");
|
List<String> expectedResult = Arrays.asList("Bashkim", "Lulzim", "Shpetim");
|
||||||
List<String> actualResult = StreamIndices.getOddIndexedStringsVersionTwo(names);
|
List<String> actualResult = StreamIndices.getOddIndexedStringsVersionTwo(names);
|
||||||
|
|
||||||
assertEquals(expectedResult, actualResult);
|
assertEquals(expectedResult, actualResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue