Skip to content

Commit c4cb6ee

Browse files
kacperkozamaibin
authored andcommitted
Move optional to java-8-core (eugenp#5105)
1 parent 9028707 commit c4cb6ee

3 files changed

Lines changed: 11 additions & 18 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.baeldung.optional;
2+
3+
public class PersonRepository {
4+
5+
public String findNameById(String id) {
6+
return id == null ? null : "Name";
7+
}
8+
9+
}

core-java/src/test/java/com/baeldung/throwsexception/PersonRepositoryUnitTest.java renamed to core-java-8/src/test/java/com/baeldung/optional/PersonRepositoryUnitTest.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
package com.baeldung.throwsexception;
1+
package com.baeldung.optional;
22

33
import org.junit.Test;
44

55
import java.util.Optional;
66

7-
import static org.junit.Assert.assertEquals;
87
import static org.junit.jupiter.api.Assertions.assertAll;
8+
import static org.junit.jupiter.api.Assertions.assertEquals;
99
import static org.junit.jupiter.api.Assertions.assertThrows;
1010

1111
public class PersonRepositoryUnitTest {
@@ -40,14 +40,4 @@ public void whenIdNonNull_thenReturnsNameUpperCase() {
4040
assertEquals("NAME", name);
4141
}
4242

43-
@Test
44-
public void whenIdIsNonNull_thenShouldReturnNameUpperCase() throws Exception {
45-
String name = Optional
46-
.ofNullable(personRepository.findNameById("id"))
47-
.map(String::toUpperCase)
48-
.orElseThrow(Exception::new);
49-
50-
assertEquals("NAME", name);
51-
}
52-
5343
}

‎core-java/src/main/java/com/baeldung/throwsexception/PersonRepository.java‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
package com.baeldung.throwsexception;
22

3-
import javax.annotation.Nullable;
43
import java.sql.SQLException;
54
import java.util.List;
65

76
public class PersonRepository {
87

9-
@Nullable
10-
public String findNameById(String id) {
11-
return id == null ? null : "Name";
12-
}
13-
148
public List<String> findAll() throws SQLException {
159
throw new SQLException();
1610
}

0 commit comments

Comments
 (0)