File tree Expand file tree Collapse file tree
main/java/com/baeldung/optional
test/java/com/baeldung/optional
core-java/src/main/java/com/baeldung/throwsexception Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 1- package com .baeldung .throwsexception ;
1+ package com .baeldung .optional ;
22
33import org .junit .Test ;
44
55import java .util .Optional ;
66
7- import static org .junit .Assert .assertEquals ;
87import static org .junit .jupiter .api .Assertions .assertAll ;
8+ import static org .junit .jupiter .api .Assertions .assertEquals ;
99import static org .junit .jupiter .api .Assertions .assertThrows ;
1010
1111public 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}
Original file line number Diff line number Diff line change 11package com .baeldung .throwsexception ;
22
3- import javax .annotation .Nullable ;
43import java .sql .SQLException ;
54import java .util .List ;
65
76public 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 }
You can’t perform that action at this time.
0 commit comments