Merge pull request #15202 from panos-kakos/JAVA-26739

[JAVA-26739] Upgraded json-path to latest version
This commit is contained in:
Kasra Madadipouya 2023-11-13 22:44:57 +01:00 committed by GitHub
commit cdc1d8001f
8 changed files with 94 additions and 96 deletions

View File

@ -47,14 +47,14 @@
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>json-path</artifactId>
<version>${rest-assured.version}</version>
<version>${json-path.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<hibernate.core.version>5.4.0.Final</hibernate.core.version>
<rest-assured.version>3.1.1</rest-assured.version>
<json-path.version>5.3.2</json-path.version>
</properties>
</project>

View File

@ -8,88 +8,88 @@ import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
// Uncomment code when code base is compatible with Java 9
//public class Java9OptionalUnitTest {
//
// @Test
// public void givenOptionalOfSome_whenToStream_thenShouldTreatItAsOneElementStream() {
// //given
// Optional<String> value = Optional.of("a");
//
// //when
// List<String> collect = value.stream().map(String::toUpperCase).collect(Collectors.toList());
//
// //then
// assertThat(collect).hasSameElementsAs(List.of("A"));
// }
//
// @Test
// public void givenOptionalOfNone_whenToStream_thenShouldTreatItAsZeroElementStream() {
// //given
// Optional<String> value = Optional.empty();
//
// //when
// List<String> collect = value.stream().map(String::toUpperCase).collect(Collectors.toList());
//
// //then
// assertThat(collect).isEmpty();
// }
//
// @Test
// public void givenOptional_whenPresent_thenShouldExecuteProperCallback() {
// //given
// Optional<String> value = Optional.of("properValue");
// AtomicInteger successCounter = new AtomicInteger(0);
// AtomicInteger onEmptyOptionalCounter = new AtomicInteger(0);
//
// //when
// value.ifPresentOrElse((v) -> successCounter.incrementAndGet(), onEmptyOptionalCounter::incrementAndGet);
//
// //then
// assertThat(successCounter.get()).isEqualTo(1);
// assertThat(onEmptyOptionalCounter.get()).isEqualTo(0);
// }
//
// @Test
// public void givenOptional_whenNotPresent_thenShouldExecuteProperCallback() {
// //given
// Optional<String> value = Optional.empty();
// AtomicInteger successCounter = new AtomicInteger(0);
// AtomicInteger onEmptyOptionalCounter = new AtomicInteger(0);
//
// //when
// value.ifPresentOrElse((v) -> successCounter.incrementAndGet(), onEmptyOptionalCounter::incrementAndGet);
//
// //then
// assertThat(successCounter.get()).isEqualTo(0);
// assertThat(onEmptyOptionalCounter.get()).isEqualTo(1);
// }
//
// @Test
// public void givenOptional_whenPresent_thenShouldTakeAValueFromIt() {
// //given
// String expected = "properValue";
// Optional<String> value = Optional.of(expected);
// Optional<String> defaultValue = Optional.of("default");
//
// //when
// Optional<String> result = value.or(() -> defaultValue);
//
// //then
// assertThat(result.get()).isEqualTo(expected);
// }
//
// @Test
// public void givenOptional_whenEmpty_thenShouldTakeAValueFromOr() {
// //given
// String defaultString = "default";
// Optional<String> value = Optional.empty();
// Optional<String> defaultValue = Optional.of(defaultString);
//
// //when
// Optional<String> result = value.or(() -> defaultValue);
//
// //then
// assertThat(result.get()).isEqualTo(defaultString);
// }
//}
public class Java9OptionalUnitTest {
@Test
public void givenOptionalOfSome_whenToStream_thenShouldTreatItAsOneElementStream() {
//given
Optional<String> value = Optional.of("a");
//when
List<String> collect = value.stream().map(String::toUpperCase).collect(Collectors.toList());
//then
assertThat(collect).hasSameElementsAs(List.of("A"));
}
@Test
public void givenOptionalOfNone_whenToStream_thenShouldTreatItAsZeroElementStream() {
//given
Optional<String> value = Optional.empty();
//when
List<String> collect = value.stream().map(String::toUpperCase).collect(Collectors.toList());
//then
assertThat(collect).isEmpty();
}
@Test
public void givenOptional_whenPresent_thenShouldExecuteProperCallback() {
//given
Optional<String> value = Optional.of("properValue");
AtomicInteger successCounter = new AtomicInteger(0);
AtomicInteger onEmptyOptionalCounter = new AtomicInteger(0);
//when
value.ifPresentOrElse((v) -> successCounter.incrementAndGet(), onEmptyOptionalCounter::incrementAndGet);
//then
assertThat(successCounter.get()).isEqualTo(1);
assertThat(onEmptyOptionalCounter.get()).isEqualTo(0);
}
@Test
public void givenOptional_whenNotPresent_thenShouldExecuteProperCallback() {
//given
Optional<String> value = Optional.empty();
AtomicInteger successCounter = new AtomicInteger(0);
AtomicInteger onEmptyOptionalCounter = new AtomicInteger(0);
//when
value.ifPresentOrElse((v) -> successCounter.incrementAndGet(), onEmptyOptionalCounter::incrementAndGet);
//then
assertThat(successCounter.get()).isEqualTo(0);
assertThat(onEmptyOptionalCounter.get()).isEqualTo(1);
}
@Test
public void givenOptional_whenPresent_thenShouldTakeAValueFromIt() {
//given
String expected = "properValue";
Optional<String> value = Optional.of(expected);
Optional<String> defaultValue = Optional.of("default");
//when
Optional<String> result = value.or(() -> defaultValue);
//then
assertThat(result.get()).isEqualTo(expected);
}
@Test
public void givenOptional_whenEmpty_thenShouldTakeAValueFromOr() {
//given
String defaultString = "default";
Optional<String> value = Optional.empty();
Optional<String> defaultValue = Optional.of(defaultString);
//when
Optional<String> result = value.or(() -> defaultValue);
//then
assertThat(result.get()).isEqualTo(defaultString);
}
}

View File

@ -192,7 +192,7 @@
<ethereumj-core.version>1.5.0-RELEASE</ethereumj-core.version>
<web3j.core.version>3.3.1</web3j.core.version>
<spring.boot.version>1.5.6.RELEASE</spring.boot.version>
<jsonpath.version>2.4.0</jsonpath.version>
<jsonpath.version>2.8.0</jsonpath.version>
<spring-boot-maven-plugin.version>2.0.4.RELEASE</spring-boot-maven-plugin.version>
<compiler.plugin.version>3.1</compiler.plugin.version>
</properties>

View File

@ -21,7 +21,7 @@
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>json-path</artifactId>
<version>${rest-assured.version}</version>
<version>${json-path.version}</version>
<scope>test</scope>
</dependency>
<dependency>
@ -59,7 +59,7 @@
<properties>
<h2.version>2.1.214</h2.version>
<rest-assured.version>3.1.1</rest-assured.version>
<json-path.version>5.3.2</json-path.version>
<spring-boot.version>2.5.0</spring-boot.version>
</properties>

View File

@ -13,7 +13,6 @@
</parent>
<dependencies>
<!-- json-path -->
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
@ -22,8 +21,7 @@
</dependencies>
<properties>
<!-- json-path -->
<json-path.version>2.4.0</json-path.version>
<json-path.version>2.8.0</json-path.version>
</properties>
</project>

View File

@ -82,7 +82,7 @@
<properties>
<commons-io.version>1.3.2</commons-io.version>
<json-path.version>2.7.0</json-path.version>
<json-path.version>2.8.0</json-path.version>
<jaxb-runtime.version>2.3.5</jaxb-runtime.version>
<jakarta.servlet.jsp.jstl>2.0.0</jakarta.servlet.jsp.jstl>
<io.rest-assured.version>3.0.0</io.rest-assured.version>

View File

@ -237,7 +237,7 @@
<javax.version>4.0.1</javax.version>
<javax-servlet-api.version>2.3.3</javax-servlet-api.version>
<htmlunit.version>2.32</htmlunit.version>
<json-path.version>2.4.0</json-path.version>
<json-path.version>2.8.0</json-path.version>
<start-class>com.baeldung.SpringMVCApplication</start-class>
</properties>

View File

@ -120,7 +120,7 @@
<rest-assured.version>3.0.1</rest-assured.version>
<rest-assured-json-schema-validator.version>3.0.0</rest-assured-json-schema-validator.version>
<json-schema-validator.version>2.2.6</json-schema-validator.version>
<json-path.version>3.0.1</json-path.version>
<json-path.version>5.3.2</json-path.version>
</properties>
</project>