From c4cb6eec7338b33d43740fc69f8941f27e3d9f0d Mon Sep 17 00:00:00 2001 From: Kacper Date: Wed, 29 Aug 2018 15:51:41 +0200 Subject: [PATCH] Move optional to java-8-core (#5105) --- .../com/baeldung/optional/PersonRepository.java | 9 +++++++++ .../optional}/PersonRepositoryUnitTest.java | 14 ++------------ .../baeldung/throwsexception/PersonRepository.java | 6 ------ 3 files changed, 11 insertions(+), 18 deletions(-) create mode 100644 core-java-8/src/main/java/com/baeldung/optional/PersonRepository.java rename {core-java/src/test/java/com/baeldung/throwsexception => core-java-8/src/test/java/com/baeldung/optional}/PersonRepositoryUnitTest.java (75%) diff --git a/core-java-8/src/main/java/com/baeldung/optional/PersonRepository.java b/core-java-8/src/main/java/com/baeldung/optional/PersonRepository.java new file mode 100644 index 0000000000..46018faf80 --- /dev/null +++ b/core-java-8/src/main/java/com/baeldung/optional/PersonRepository.java @@ -0,0 +1,9 @@ +package com.baeldung.optional; + +public class PersonRepository { + + public String findNameById(String id) { + return id == null ? null : "Name"; + } + +} diff --git a/core-java/src/test/java/com/baeldung/throwsexception/PersonRepositoryUnitTest.java b/core-java-8/src/test/java/com/baeldung/optional/PersonRepositoryUnitTest.java similarity index 75% rename from core-java/src/test/java/com/baeldung/throwsexception/PersonRepositoryUnitTest.java rename to core-java-8/src/test/java/com/baeldung/optional/PersonRepositoryUnitTest.java index 3749ce10d0..4efa625ccd 100644 --- a/core-java/src/test/java/com/baeldung/throwsexception/PersonRepositoryUnitTest.java +++ b/core-java-8/src/test/java/com/baeldung/optional/PersonRepositoryUnitTest.java @@ -1,11 +1,11 @@ -package com.baeldung.throwsexception; +package com.baeldung.optional; import org.junit.Test; import java.util.Optional; -import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertAll; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; public class PersonRepositoryUnitTest { @@ -40,14 +40,4 @@ public class PersonRepositoryUnitTest { assertEquals("NAME", name); } - @Test - public void whenIdIsNonNull_thenShouldReturnNameUpperCase() throws Exception { - String name = Optional - .ofNullable(personRepository.findNameById("id")) - .map(String::toUpperCase) - .orElseThrow(Exception::new); - - assertEquals("NAME", name); - } - } \ No newline at end of file diff --git a/core-java/src/main/java/com/baeldung/throwsexception/PersonRepository.java b/core-java/src/main/java/com/baeldung/throwsexception/PersonRepository.java index a3e69b7f6f..7d8345c3c1 100644 --- a/core-java/src/main/java/com/baeldung/throwsexception/PersonRepository.java +++ b/core-java/src/main/java/com/baeldung/throwsexception/PersonRepository.java @@ -1,16 +1,10 @@ package com.baeldung.throwsexception; -import javax.annotation.Nullable; import java.sql.SQLException; import java.util.List; public class PersonRepository { - @Nullable - public String findNameById(String id) { - return id == null ? null : "Name"; - } - public List findAll() throws SQLException { throw new SQLException(); }