2017-08-29 07:36:55 +02:00
|
|
|
package com.baeldung.stream;
|
|
|
|
|
|
2017-09-05 23:55:15 +02:00
|
|
|
import com.codepoetics.protonpack.Indexed;
|
|
|
|
|
import org.junit.Test;
|
2017-08-29 07:36:55 +02:00
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
2017-09-05 23:55:15 +02:00
|
|
|
import static org.junit.Assert.assertEquals;
|
2017-08-29 07:36:55 +02:00
|
|
|
|
2018-06-01 16:42:51 +05:30
|
|
|
public class StreamIndicesUnitTest {
|
2017-08-29 07:36:55 +02:00
|
|
|
|
|
|
|
|
@Test
|
2017-09-05 23:55:15 +02:00
|
|
|
public void whenCalled_thenReturnListOfEvenIndexedStrings() {
|
|
|
|
|
String[] names = {"Afrim", "Bashkim", "Besim", "Lulzim", "Durim", "Shpetim"};
|
2017-08-29 07:36:55 +02:00
|
|
|
List<String> expectedResult = Arrays.asList("Afrim", "Besim", "Durim");
|
|
|
|
|
List<String> actualResult = StreamIndices.getEvenIndexedStrings(names);
|
|
|
|
|
|
|
|
|
|
assertEquals(expectedResult, actualResult);
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-31 18:42:03 +02:00
|
|
|
@Test
|
2017-09-05 23:55:15 +02:00
|
|
|
public void whenCalled_thenReturnListOfEvenIndexedStringsVersionTwo() {
|
|
|
|
|
String[] names = {"Afrim", "Bashkim", "Besim", "Lulzim", "Durim", "Shpetim"};
|
2017-08-31 18:42:03 +02:00
|
|
|
List<String> expectedResult = Arrays.asList("Afrim", "Besim", "Durim");
|
|
|
|
|
List<String> actualResult = StreamIndices.getEvenIndexedStrings(names);
|
|
|
|
|
|
|
|
|
|
assertEquals(expectedResult, actualResult);
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-29 07:36:55 +02:00
|
|
|
@Test
|
2017-09-05 23:55:15 +02:00
|
|
|
public void whenCalled_thenReturnListOfOddStrings() {
|
|
|
|
|
String[] names = {"Afrim", "Bashkim", "Besim", "Lulzim", "Durim", "Shpetim"};
|
2017-08-29 07:36:55 +02:00
|
|
|
List<String> expectedResult = Arrays.asList("Bashkim", "Lulzim", "Shpetim");
|
|
|
|
|
List<String> actualResult = StreamIndices.getOddIndexedStrings(names);
|
|
|
|
|
|
|
|
|
|
assertEquals(expectedResult, actualResult);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
2017-09-05 23:55:15 +02:00
|
|
|
public void givenList_whenCalled_thenReturnListOfEvenIndexedStrings() {
|
2017-08-29 07:36:55 +02:00
|
|
|
List<String> names = Arrays.asList("Afrim", "Bashkim", "Besim", "Lulzim", "Durim", "Shpetim");
|
2017-09-05 23:55:15 +02:00
|
|
|
List<Indexed<String>> expectedResult = Arrays
|
|
|
|
|
.asList(Indexed.index(0, "Afrim"), Indexed.index(2, "Besim"), Indexed
|
|
|
|
|
.index(4, "Durim"));
|
2017-08-29 07:36:55 +02:00
|
|
|
List<Indexed<String>> actualResult = StreamIndices.getEvenIndexedStrings(names);
|
|
|
|
|
|
|
|
|
|
assertEquals(expectedResult, actualResult);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
2017-09-05 23:55:15 +02:00
|
|
|
public void givenList_whenCalled_thenReturnListOfOddIndexedStrings() {
|
2017-08-29 07:36:55 +02:00
|
|
|
List<String> names = Arrays.asList("Afrim", "Bashkim", "Besim", "Lulzim", "Durim", "Shpetim");
|
2017-09-05 23:55:15 +02:00
|
|
|
List<Indexed<String>> expectedResult = Arrays
|
|
|
|
|
.asList(Indexed.index(1, "Bashkim"), Indexed.index(3, "Lulzim"), Indexed
|
|
|
|
|
.index(5, "Shpetim"));
|
2017-08-29 07:36:55 +02:00
|
|
|
List<Indexed<String>> actualResult = StreamIndices.getOddIndexedStrings(names);
|
|
|
|
|
|
|
|
|
|
assertEquals(expectedResult, actualResult);
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-31 18:42:03 +02:00
|
|
|
@Test
|
2017-09-05 23:55:15 +02:00
|
|
|
public void whenCalled_thenReturnListOfOddStringsVersionTwo() {
|
|
|
|
|
String[] names = {"Afrim", "Bashkim", "Besim", "Lulzim", "Durim", "Shpetim"};
|
2017-08-31 18:42:03 +02:00
|
|
|
List<String> expectedResult = Arrays.asList("Bashkim", "Lulzim", "Shpetim");
|
|
|
|
|
List<String> actualResult = StreamIndices.getOddIndexedStringsVersionTwo(names);
|
|
|
|
|
|
|
|
|
|
assertEquals(expectedResult, actualResult);
|
|
|
|
|
}
|
2017-08-29 07:36:55 +02:00
|
|
|
}
|