Avoid String allocations with Assert.notNull()

This commit is contained in:
Sam Brannen 2022-11-08 14:23:22 +01:00
parent 9e4cddf5db
commit 9d73f81e9c
5 changed files with 8 additions and 8 deletions

View File

@ -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<?>>
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));
}

View File

@ -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 {
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);
}

View File

@ -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;
}

View File

@ -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()));

View File

@ -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
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()));