Browse Source

Polish tests for configuration constants

See gh-30851
pull/28156/merge
Sam Brannen 1 year ago
parent
commit
0eda44186a
  1. 2
      spring-aop/src/test/java/org/springframework/aop/interceptor/CustomizableTraceInterceptorTests.java
  2. 5
      spring-jdbc/src/test/java/org/springframework/jdbc/datasource/IsolationLevelDataSourceAdapterTests.java
  3. 18
      spring-jms/src/test/java/org/springframework/jms/listener/DefaultMessageListenerContainerTests.java
  4. 20
      spring-jms/src/test/java/org/springframework/jms/listener/endpoint/JmsActivationSpecConfigTests.java
  5. 18
      spring-jms/src/test/java/org/springframework/jms/support/JmsAccessorTests.java
  6. 6
      spring-tx/src/test/java/org/springframework/transaction/support/TransactionSupportTests.java

2
spring-aop/src/test/java/org/springframework/aop/interceptor/CustomizableTraceInterceptorTests.java

@ -179,7 +179,7 @@ class CustomizableTraceInterceptorTests { @@ -179,7 +179,7 @@ class CustomizableTraceInterceptorTests {
@Test
@SuppressWarnings("deprecation")
void supportedPlaceholderValues() {
assertThat(ALLOWED_PLACEHOLDERS).containsAll(getPlaceholderConstantValues());
assertThat(ALLOWED_PLACEHOLDERS).containsExactlyInAnyOrderElementsOf(getPlaceholderConstantValues());
}
private List<String> getPlaceholderConstantValues() {

5
spring-jdbc/src/test/java/org/springframework/jdbc/datasource/IsolationLevelDataSourceAdapterTests.java

@ -63,14 +63,15 @@ class IsolationLevelDataSourceAdapterTests { @@ -63,14 +63,15 @@ class IsolationLevelDataSourceAdapterTests {
Integer isolationLevel = adapter.getIsolationLevel();
if ("ISOLATION_DEFAULT".equals(name)) {
assertThat(isolationLevel).isNull();
uniqueValues.add(ISOLATION_DEFAULT);
}
else {
Integer expected = IsolationLevelDataSourceAdapter.constants.get(name);
assertThat(isolationLevel).isEqualTo(expected);
uniqueValues.add(isolationLevel);
}
uniqueValues.add(isolationLevel);
});
assertThat(uniqueValues).hasSize(IsolationLevelDataSourceAdapter.constants.size());
assertThat(uniqueValues).containsExactlyInAnyOrderElementsOf(IsolationLevelDataSourceAdapter.constants.values());
}
@Test

18
spring-jms/src/test/java/org/springframework/jms/listener/DefaultMessageListenerContainerTests.java

@ -18,6 +18,8 @@ package org.springframework.jms.listener; @@ -18,6 +18,8 @@ package org.springframework.jms.listener;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;
@ -37,7 +39,6 @@ import org.springframework.util.backoff.FixedBackOff; @@ -37,7 +39,6 @@ import org.springframework.util.backoff.FixedBackOff;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.assertThatNoException;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
@ -160,16 +161,23 @@ class DefaultMessageListenerContainerTests { @@ -160,16 +161,23 @@ class DefaultMessageListenerContainerTests {
@Test
void setCacheLevelNameToAllSupportedValues() {
DefaultMessageListenerContainer container = new DefaultMessageListenerContainer();
Set<Integer> uniqueValues = new HashSet<>();
streamCacheConstants()
.map(Field::getName)
.forEach(name -> assertThatNoException().isThrownBy(() -> container.setCacheLevelName(name)));
.forEach(name -> {
container.setCacheLevelName(name);
int cacheLevel = container.getCacheLevel();
assertThat(cacheLevel).isBetween(0, 4);
uniqueValues.add(cacheLevel);
});
assertThat(uniqueValues).hasSize(5);
}
private static Stream<Field> streamCacheConstants() {
private static Stream<String> streamCacheConstants() {
return Arrays.stream(DefaultMessageListenerContainer.class.getFields())
.filter(ReflectionUtils::isPublicStaticFinal)
.filter(field -> field.getName().startsWith("CACHE_"));
.filter(field -> field.getName().startsWith("CACHE_"))
.map(Field::getName);
}
private static DefaultMessageListenerContainer createRunningContainer() {

20
spring-jms/src/test/java/org/springframework/jms/listener/endpoint/JmsActivationSpecConfigTests.java

@ -18,6 +18,8 @@ package org.springframework.jms.listener.endpoint; @@ -18,6 +18,8 @@ package org.springframework.jms.listener.endpoint;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Stream;
import jakarta.jms.Session;
@ -25,8 +27,8 @@ import org.junit.jupiter.api.Test; @@ -25,8 +27,8 @@ import org.junit.jupiter.api.Test;
import org.springframework.util.ReflectionUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.assertThatNoException;
/**
* Tests for {@link JmsActivationSpecConfig}.
@ -53,15 +55,21 @@ class JmsActivationSpecConfigTests { @@ -53,15 +55,21 @@ class JmsActivationSpecConfigTests {
*/
@Test
void setAcknowledgeModeNameToAllSupportedValues() {
streamAcknowledgeModeConstants()
.map(Field::getName)
.forEach(name -> assertThatNoException().isThrownBy(() -> specConfig.setAcknowledgeModeName(name)));
Set<Integer> uniqueValues = new HashSet<>();
streamAcknowledgeModeConstants().forEach(name -> {
specConfig.setAcknowledgeModeName(name);
int acknowledgeMode = specConfig.getAcknowledgeMode();
assertThat(acknowledgeMode).isBetween(0, 3);
uniqueValues.add(acknowledgeMode);
});
assertThat(uniqueValues).hasSize(4);
}
private static Stream<Field> streamAcknowledgeModeConstants() {
private static Stream<String> streamAcknowledgeModeConstants() {
return Arrays.stream(Session.class.getFields())
.filter(ReflectionUtils::isPublicStaticFinal);
.filter(ReflectionUtils::isPublicStaticFinal)
.map(Field::getName);
}
}

18
spring-jms/src/test/java/org/springframework/jms/support/JmsAccessorTests.java

@ -18,6 +18,8 @@ package org.springframework.jms.support; @@ -18,6 +18,8 @@ package org.springframework.jms.support;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Stream;
import jakarta.jms.Session;
@ -27,7 +29,6 @@ import org.springframework.util.ReflectionUtils; @@ -27,7 +29,6 @@ import org.springframework.util.ReflectionUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.assertThatNoException;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
@ -84,15 +85,22 @@ class JmsAccessorTests { @@ -84,15 +85,22 @@ class JmsAccessorTests {
*/
@Test
void setSessionAcknowledgeModeNameToAllSupportedValues() {
Set<Integer> uniqueValues = new HashSet<>();
streamAcknowledgeModeConstants()
.map(Field::getName)
.forEach(name -> assertThatNoException().isThrownBy(() -> accessor.setSessionAcknowledgeModeName(name)));
.forEach(name -> {
accessor.setSessionAcknowledgeModeName(name);
int sessionAcknowledgeMode = accessor.getSessionAcknowledgeMode();
assertThat(sessionAcknowledgeMode).isBetween(0, 3);
uniqueValues.add(sessionAcknowledgeMode);
});
assertThat(uniqueValues).hasSize(4);
}
private static Stream<Field> streamAcknowledgeModeConstants() {
private static Stream<String> streamAcknowledgeModeConstants() {
return Arrays.stream(Session.class.getFields())
.filter(ReflectionUtils::isPublicStaticFinal);
.filter(ReflectionUtils::isPublicStaticFinal)
.map(Field::getName);
}
@Test

6
spring-tx/src/test/java/org/springframework/transaction/support/TransactionSupportTests.java

@ -293,7 +293,7 @@ class TransactionSupportTests { @@ -293,7 +293,7 @@ class TransactionSupportTests {
assertThat(transactionSynchronization).isEqualTo(expected);
uniqueValues.add(transactionSynchronization);
});
assertThat(uniqueValues).hasSize(AbstractPlatformTransactionManager.constants.size());
assertThat(uniqueValues).containsExactlyInAnyOrderElementsOf(AbstractPlatformTransactionManager.constants.values());
}
@Test
@ -348,7 +348,7 @@ class TransactionSupportTests { @@ -348,7 +348,7 @@ class TransactionSupportTests {
assertThat(propagationBehavior).isEqualTo(expected);
uniqueValues.add(propagationBehavior);
});
assertThat(uniqueValues).hasSize(DefaultTransactionDefinition.propagationConstants.size());
assertThat(uniqueValues).containsExactlyInAnyOrderElementsOf(DefaultTransactionDefinition.propagationConstants.values());
}
@Test
@ -383,7 +383,7 @@ class TransactionSupportTests { @@ -383,7 +383,7 @@ class TransactionSupportTests {
assertThat(isolationLevel).isEqualTo(expected);
uniqueValues.add(isolationLevel);
});
assertThat(uniqueValues).hasSize(DefaultTransactionDefinition.isolationConstants.size());
assertThat(uniqueValues).containsExactlyInAnyOrderElementsOf(DefaultTransactionDefinition.isolationConstants.values());
}
@Test

Loading…
Cancel
Save