Skip to content

Commit e71f966

Browse files
committed
Seggregate the test case of the default methods.
1 parent d55508f commit e71f966

File tree

4 files changed

+84
-32
lines changed

4 files changed

+84
-32
lines changed

src/test/java/com/github/streams/learn/default_methods/A_DefaultMethodTest.java

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,17 @@
11
package com.github.streams.learn.default_methods;
22

3-
import java.util.ArrayList;
43
import java.util.Arrays;
54
import java.util.HashMap;
65
import java.util.List;
76
import java.util.Map;
87
import java.util.TreeMap;
9-
import java.util.stream.Collectors;
108
import org.junit.jupiter.api.Assertions;
119
import org.junit.jupiter.api.Disabled;
1210
import org.junit.jupiter.api.Test;
1311

1412
/** This set of exercises covers new default methods on the Collections and related APIs. */
1513
class A_DefaultMethodTest {
1614

17-
///
18-
// Given a list of StringBuilders, modify each StringBuilder in-place by appending the string
19-
// "new" to each one.
20-
///
21-
@Test
22-
@Disabled
23-
public void appendNew() {
24-
List<StringBuilder> sbList =
25-
List.of(
26-
new StringBuilder("alfa"), new StringBuilder("bravo"), new StringBuilder("charlie"));
27-
28-
// TODO write code to modify sbList
29-
30-
Assertions.assertEquals(
31-
List.of("alfanew", "bravonew", "charlienew"),
32-
sbList.stream().map(StringBuilder::toString).collect(Collectors.toList()));
33-
}
34-
35-
/** Remove the words that have odd lengths from the list. */
36-
@Test
37-
@Disabled
38-
public void removeOddLengthWords() {
39-
List<String> list =
40-
new ArrayList<>(Arrays.asList("alfa", "bravo", "charlie", "delta", "echo", "foxtrot"));
41-
42-
// TODO write code to modify list
43-
44-
Assertions.assertEquals(List.of("alfa", "echo"), list);
45-
}
46-
4715
///
4816
// Replace every word in the list with its upper case equivalent.
4917
///
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.github.streams.learn.default_methods;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
import org.junit.jupiter.api.Assertions;
6+
import org.junit.jupiter.api.Disabled;
7+
import org.junit.jupiter.api.Test;
8+
9+
///
10+
/// Given a list of StringBuilders, modify each StringBuilder in-place by appending the string
11+
/// "new" to each one.
12+
///
13+
/// Example:
14+
/// ```
15+
/// Input: ["alfa", "bravo", "charlie"]
16+
///
17+
/// Output: ["alfanew", "bravonew", "charlienew"]
18+
/// ```
19+
20+
class B_ListDefaultMethodTest {
21+
@Test
22+
@Disabled()
23+
void testAppendNewSuffixInAllTheStrings() {
24+
final var input =
25+
new ArrayList<>(
26+
List.of(
27+
new StringBuilder("alfa"),
28+
new StringBuilder("bravo"),
29+
new StringBuilder("charlie")));
30+
31+
var yourSolution = List.of();
32+
var mySolution = DefaultMethodSolutions.appendNewSuffix(input);
33+
34+
Assertions.assertEquals(mySolution, yourSolution);
35+
}
36+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.github.streams.learn.default_methods;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
import org.junit.jupiter.api.Assertions;
6+
import org.junit.jupiter.api.Disabled;
7+
import org.junit.jupiter.api.Test;
8+
9+
///
10+
/// Remove the words that have odd lengths from the list.
11+
///
12+
/// Example:
13+
/// ```
14+
/// Input: ["alfa", "bravo", "echo", "charlie"]
15+
///
16+
/// Output: ["alfa", "echo"]
17+
/// ```
18+
19+
class C_ListDefaultMethodTest {
20+
21+
@Test
22+
@Disabled
23+
void removeOddLengthWords() {
24+
List<String> input =
25+
new ArrayList<>(List.of("alfa", "bravo", "charlie", "delta", "echo", "foxtrot"));
26+
27+
var yourSolution = List.of();
28+
var mySolution = DefaultMethodSolutions.removeOddLengthWords(input);
29+
30+
Assertions.assertEquals(mySolution, yourSolution);
31+
}
32+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.github.streams.learn.default_methods;
2+
3+
import java.util.List;
4+
5+
public class DefaultMethodSolutions {
6+
7+
public static List<StringBuilder> appendNewSuffix(List<StringBuilder> input) {
8+
input.replaceAll(x -> x.append("new"));
9+
return input;
10+
}
11+
12+
public static List<String> removeOddLengthWords(List<String> input) {
13+
input.removeIf(x -> x.length() % 2 == 1);
14+
return List.copyOf(input);
15+
}
16+
}

0 commit comments

Comments
 (0)