Browse Source

Avoid String allocations with Assert.notNull()

pull/29447/head
Sam Brannen 2 years ago
parent
commit
9d73f81e9c
  1. 4
      spring-context-support/src/test/java/org/springframework/cache/jcache/interceptor/AbstractCacheOperationTests.java
  2. 4
      spring-context-support/src/test/java/org/springframework/cache/jcache/interceptor/AnnotationCacheOperationSourceTests.java
  3. 2
      spring-core-test/src/main/java/org/springframework/core/test/tools/DynamicClassLoader.java
  4. 2
      spring-test/src/main/java/org/springframework/test/context/aot/TestContextAotGenerator.java
  5. 4
      spring-test/src/main/java/org/springframework/test/context/cache/DefaultCacheAwareContextLoaderDelegate.java

4
spring-context-support/src/test/java/org/springframework/cache/jcache/interceptor/AbstractCacheOperationTests.java vendored

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2022 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.
@ -62,7 +62,7 @@ public abstract class AbstractCacheOperationTests<O extends JCacheOperation<?>> @@ -62,7 +62,7 @@ public abstract class AbstractCacheOperationTests<O extends JCacheOperation<?>>
Class<?> targetType, String methodName,
Class<?>... parameterTypes) {
Method method = ReflectionUtils.findMethod(targetType, methodName, parameterTypes);
Assert.notNull(method, "requested method '" + methodName + "'does not exist");
Assert.notNull(method, () -> "requested method '" + methodName + "'does not exist");
A cacheAnnotation = method.getAnnotation(annotationType);
return new DefaultCacheMethodDetails<>(method, cacheAnnotation, getCacheName(cacheAnnotation));
}

4
spring-context-support/src/test/java/org/springframework/cache/jcache/interceptor/AnnotationCacheOperationSourceTests.java vendored

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2022 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.
@ -202,7 +202,7 @@ public class AnnotationCacheOperationSourceTests extends AbstractJCacheTests { @@ -202,7 +202,7 @@ public class AnnotationCacheOperationSourceTests extends AbstractJCacheTests {
private JCacheOperation<?> getCacheOperation(Class<?> targetType, String methodName, Class<?>... parameterTypes) {
Method method = ReflectionUtils.findMethod(targetType, methodName, parameterTypes);
Assert.notNull(method, "requested method '" + methodName + "'does not exist");
Assert.notNull(method, () -> "requested method '" + methodName + "'does not exist");
return source.getCacheOperation(method, targetType);
}

2
spring-core-test/src/main/java/org/springframework/core/test/tools/DynamicClassLoader.java

@ -155,7 +155,7 @@ public class DynamicClassLoader extends ClassLoader { @@ -155,7 +155,7 @@ public class DynamicClassLoader extends ClassLoader {
private static Method lookupMethod(Class<?> target, String name, Class<?>... parameterTypes) {
Method method = ReflectionUtils.findMethod(target, name, parameterTypes);
Assert.notNull(method, "Expected method '" + name + "' on '" + target.getName());
Assert.notNull(method, () -> "Could not find method '%s' on '%s'".formatted(name, target.getName()));
return method;
}

2
spring-test/src/main/java/org/springframework/test/context/aot/TestContextAotGenerator.java

@ -205,7 +205,7 @@ public class TestContextAotGenerator { @@ -205,7 +205,7 @@ public class TestContextAotGenerator {
Class<?> testClass = mergedConfig.getTestClass();
ContextLoader contextLoader = mergedConfig.getContextLoader();
Assert.notNull(contextLoader, """
Assert.notNull(contextLoader, () -> """
Cannot load an ApplicationContext with a NULL 'contextLoader'. \
Consider annotating test class [%s] with @ContextConfiguration or \
@ContextHierarchy.""".formatted(testClass.getName()));

4
spring-test/src/main/java/org/springframework/test/context/cache/DefaultCacheAwareContextLoaderDelegate.java vendored

@ -184,7 +184,7 @@ public class DefaultCacheAwareContextLoaderDelegate implements CacheAwareContext @@ -184,7 +184,7 @@ public class DefaultCacheAwareContextLoaderDelegate implements CacheAwareContext
}
else {
String[] locations = mergedContextConfiguration.getLocations();
Assert.notNull(locations, """
Assert.notNull(locations, () -> """
Cannot load an ApplicationContext with a NULL 'locations' array. \
Consider annotating test class [%s] with @ContextConfiguration or \
@ContextHierarchy.""".formatted(mergedContextConfiguration.getTestClass().getName()));
@ -224,7 +224,7 @@ public class DefaultCacheAwareContextLoaderDelegate implements CacheAwareContext @@ -224,7 +224,7 @@ public class DefaultCacheAwareContextLoaderDelegate implements CacheAwareContext
private ContextLoader getContextLoader(MergedContextConfiguration mergedConfig) {
ContextLoader contextLoader = mergedConfig.getContextLoader();
Assert.notNull(contextLoader, """
Assert.notNull(contextLoader, () -> """
Cannot load an ApplicationContext with a NULL 'contextLoader'. \
Consider annotating test class [%s] with @ContextConfiguration or \
@ContextHierarchy.""".formatted(mergedConfig.getTestClass().getName()));

Loading…
Cancel
Save