Skip to content

Commit 16b5dd8

Browse files
authored
Add test for the main method
1 parent 23ea19b commit 16b5dd8

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/main/java/java_stream_api/App.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,7 @@ public static List<User> convertBirthdatesToString(List<User> users) {
180180

181181
// 30. Filter a list of Person objects, keeping only those who live in "City X".
182182
public static List<Person> filterPersonsByCity(List<Person> persons, String city) {
183-
return persons.stream()
184-
.filter(p -> city.equals(p.getCity()))
185-
.collect(Collectors.toList());
183+
return persons.stream().filter(p -> city.equals(p.getCity())).collect(Collectors.toList());
186184
}
187185

188186
// 31. Reverse the order of elements in a list.

src/test/java/java_stream_api/AppTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,4 +448,10 @@ void testUserNamesSortedByLength() {
448448
List<String> result = App.userNamesSortedByLength(Arrays.asList(u1, u2, u3));
449449
assertEquals(Arrays.asList("Eve", "Abi", "Angelina"), result, "Sort by length ascending");
450450
}
451+
452+
@Test
453+
@DisplayName("Main method runs without throwing exceptions")
454+
void testMainRunsWithoutException() {
455+
assertDoesNotThrow(() -> App.main(new String[] {}));
456+
}
451457
}

0 commit comments

Comments
 (0)