diff --git a/spring-context/src/test/java/org/springframework/context/annotation/configuration/AutowiredConfigurationTests.java b/spring-context/src/test/java/org/springframework/context/annotation/configuration/AutowiredConfigurationTests.java index 9b9a6e5e37..4ffe1f8106 100644 --- a/spring-context/src/test/java/org/springframework/context/annotation/configuration/AutowiredConfigurationTests.java +++ b/spring-context/src/test/java/org/springframework/context/annotation/configuration/AutowiredConfigurationTests.java @@ -277,7 +277,7 @@ class AutowiredConfigurationTests { @Bean public TestBean testBean(Optional colour, Optional> colours) { - if (!colour.isPresent() && !colours.isPresent()) { + if (colour.isEmpty() && colours.isEmpty()) { return new TestBean(""); } else { diff --git a/spring-core/src/testFixtures/java/org/springframework/core/testfixture/TestGroupsCondition.java b/spring-core/src/testFixtures/java/org/springframework/core/testfixture/TestGroupsCondition.java index 010f33b7eb..56e99435ae 100644 --- a/spring-core/src/testFixtures/java/org/springframework/core/testfixture/TestGroupsCondition.java +++ b/spring-core/src/testFixtures/java/org/springframework/core/testfixture/TestGroupsCondition.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,7 +44,7 @@ class TestGroupsCondition implements ExecutionCondition { @Override public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { Optional optional = findAnnotation(context.getElement(), EnabledForTestGroups.class); - if (!optional.isPresent()) { + if (optional.isEmpty()) { return ENABLED_BY_DEFAULT; } TestGroup[] testGroups = optional.get().value(); diff --git a/spring-test/src/main/java/org/springframework/test/context/junit/jupiter/AbstractExpressionEvaluatingCondition.java b/spring-test/src/main/java/org/springframework/test/context/junit/jupiter/AbstractExpressionEvaluatingCondition.java index 7ee6391692..a124a6f72a 100644 --- a/spring-test/src/main/java/org/springframework/test/context/junit/jupiter/AbstractExpressionEvaluatingCondition.java +++ b/spring-test/src/main/java/org/springframework/test/context/junit/jupiter/AbstractExpressionEvaluatingCondition.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -89,8 +89,7 @@ abstract class AbstractExpressionEvaluatingCondition implements ExecutionConditi Function expressionExtractor, Function reasonExtractor, Function loadContextExtractor, boolean enabledOnTrue, ExtensionContext context) { - Assert.state(context.getElement().isPresent(), "No AnnotatedElement"); - AnnotatedElement element = context.getElement().get(); + AnnotatedElement element = context.getElement().orElseThrow(() -> new IllegalStateException("No AnnotatedElement")); Optional annotation = findMergedAnnotation(element, annotationType); if (annotation.isEmpty()) { @@ -152,8 +151,7 @@ abstract class AbstractExpressionEvaluatingCondition implements ExecutionConditi private boolean evaluateExpression(String expression, boolean loadContext, Class annotationType, ExtensionContext context) { - Assert.state(context.getElement().isPresent(), "No AnnotatedElement"); - AnnotatedElement element = context.getElement().get(); + AnnotatedElement element = context.getElement().orElseThrow(() -> new IllegalStateException("No AnnotatedElement")); GenericApplicationContext gac = null; ApplicationContext applicationContext; diff --git a/spring-web/src/main/java/org/springframework/http/codec/multipart/MultipartHttpMessageWriter.java b/spring-web/src/main/java/org/springframework/http/codec/multipart/MultipartHttpMessageWriter.java index eeb1c59093..2ca17063e5 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/multipart/MultipartHttpMessageWriter.java +++ b/spring-web/src/main/java/org/springframework/http/codec/multipart/MultipartHttpMessageWriter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -283,7 +283,7 @@ public class MultipartHttpMessageWriter extends MultipartWriterSupport .filter(partWriter -> partWriter.canWrite(finalBodyType, contentType)) .findFirst(); - if (!writer.isPresent()) { + if (writer.isEmpty()) { return Flux.error(new CodecException("No suitable writer found for part: " + name)); }