Browse Source

Convert assertThat(x instanceof X).isFalse() to assertThat(x).isNotInstanceOf()

Search:  assertThat\((.+?) instanceof (.+?)\)(.*?)\.isFalse\(\)

Replace: assertThat($1)$3.isNotInstanceOf($2.class)

See gh-36504
pull/36513/head
Sam Brannen 6 days ago
parent
commit
399f779c43
  1. 6
      integration-tests/src/test/java/org/springframework/aop/config/AopNamespaceHandlerScopeIntegrationTests.java
  2. 2
      spring-aop/src/test/java/org/springframework/aop/interceptor/ExposeBeanNameAdvisorsTests.java
  3. 2
      spring-context/src/test/java/org/springframework/aop/aspectj/BeanNamePointcutAtAspectTests.java
  4. 10
      spring-context/src/test/java/org/springframework/aop/aspectj/BeanNamePointcutTests.java
  5. 2
      spring-context/src/test/java/org/springframework/aop/framework/AbstractAopProxyTests.java
  6. 2
      spring-context/src/test/java/org/springframework/context/annotation/configuration/ScopingTests.java
  7. 8
      spring-context/src/test/java/org/springframework/context/i18n/LocaleContextHolderTests.java
  8. 24
      spring-context/src/test/java/org/springframework/scripting/groovy/GroovyScriptFactoryTests.java
  9. 2
      spring-webflux/src/test/java/org/springframework/web/reactive/resource/EncodedResourceResolverTests.java
  10. 2
      spring-webmvc/src/test/java/org/springframework/web/servlet/resource/EncodedResourceResolverTests.java

6
integration-tests/src/test/java/org/springframework/aop/config/AopNamespaceHandlerScopeIntegrationTests.java

@ -84,7 +84,7 @@ class AopNamespaceHandlerScopeIntegrationTests { @@ -84,7 +84,7 @@ class AopNamespaceHandlerScopeIntegrationTests {
assertThat(requestScoped).as("Should be target class proxy").isInstanceOf(TestBean.class);
assertThat(AopUtils.isAopProxy(testBean)).as("Should be AOP proxy").isTrue();
assertThat(testBean instanceof TestBean).as("Regular bean should be JDK proxy").isFalse();
assertThat(testBean).as("Regular bean should be JDK proxy").isNotInstanceOf(TestBean.class);
String rob = "Rob Harrop";
String bram = "Bram Smeets";
@ -109,12 +109,12 @@ class AopNamespaceHandlerScopeIntegrationTests { @@ -109,12 +109,12 @@ class AopNamespaceHandlerScopeIntegrationTests {
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request));
assertThat(AopUtils.isAopProxy(sessionScoped)).as("Should be AOP proxy").isTrue();
assertThat(sessionScoped instanceof TestBean).as("Should not be target class proxy").isFalse();
assertThat(sessionScoped).as("Should not be target class proxy").isNotInstanceOf(TestBean.class);
assertThat(sessionScopedAlias).isSameAs(sessionScoped);
assertThat(AopUtils.isAopProxy(testBean)).as("Should be AOP proxy").isTrue();
assertThat(testBean instanceof TestBean).as("Regular bean should be JDK proxy").isFalse();
assertThat(testBean).as("Regular bean should be JDK proxy").isNotInstanceOf(TestBean.class);
String rob = "Rob Harrop";
String bram = "Bram Smeets";

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

@ -54,7 +54,7 @@ class ExposeBeanNameAdvisorsTests { @@ -54,7 +54,7 @@ class ExposeBeanNameAdvisorsTests {
pf.addAdvisor(ExposeBeanNameAdvisors.createAdvisorWithoutIntroduction(beanName));
ITestBean proxy = (ITestBean) pf.getProxy();
assertThat(proxy instanceof NamedBean).as("No introduction").isFalse();
assertThat(proxy).as("No introduction").isNotInstanceOf(NamedBean.class);
// Requires binding
proxy.getAge();
}

2
spring-context/src/test/java/org/springframework/aop/aspectj/BeanNamePointcutAtAspectTests.java

@ -76,7 +76,7 @@ class BeanNamePointcutAtAspectTests { @@ -76,7 +76,7 @@ class BeanNamePointcutAtAspectTests {
@Test
void nonMatchingBeanName() {
assertThat(testBean3 instanceof Advised).as("Didn't expect a proxy").isFalse();
assertThat(testBean3).as("Didn't expect a proxy").isNotInstanceOf(Advised.class);
testBean3.setAge(20);
assertThat(counterAspect.count).isEqualTo(0);

10
spring-context/src/test/java/org/springframework/aop/aspectj/BeanNamePointcutTests.java

@ -84,14 +84,14 @@ class BeanNamePointcutTests { @@ -84,14 +84,14 @@ class BeanNamePointcutTests {
@Test
void nonMatchingBeanName() {
assertThat(this.testBean2 instanceof Advised).as("Non-matching bean must *not* be advised (proxied)").isFalse();
assertThat(this.testBean2).as("Non-matching bean must *not* be advised (proxied)").isNotInstanceOf(Advised.class);
this.testBean2.setAge(20);
assertThat(this.counterAspect.getCount()).as("Advice must *not* have been executed").isEqualTo(0);
}
@Test
void nonMatchingNestedBeanName() {
assertThat(this.testBeanContainingNestedBean.getDoctor() instanceof Advised).as("Non-matching bean must *not* be advised (proxied)").isFalse();
assertThat(this.testBeanContainingNestedBean.getDoctor()).as("Non-matching bean must *not* be advised (proxied)").isNotInstanceOf(Advised.class);
}
@Test
@ -101,12 +101,12 @@ class BeanNamePointcutTests { @@ -101,12 +101,12 @@ class BeanNamePointcutTests {
assertThat(this.testFactoryBean1.get("myKey")).isEqualTo("myValue");
assertThat(this.counterAspect.getCount()).as("Advice not executed: must have been").isEqualTo(2);
FactoryBean<?> fb = (FactoryBean<?>) ctx.getBean("&testFactoryBean1");
assertThat((fb instanceof Advised)).as("FactoryBean itself must *not* be advised").isFalse();
assertThat((fb)).as("FactoryBean itself must *not* be advised").isNotInstanceOf(Advised.class);
}
@Test
void matchingFactoryBeanItself() {
assertThat((this.testFactoryBean2 instanceof Advised)).as("Matching bean must *not* be advised (proxied)").isFalse();
assertThat((this.testFactoryBean2)).as("Matching bean must *not* be advised (proxied)").isNotInstanceOf(Advised.class);
FactoryBean<?> fb = (FactoryBean<?>) ctx.getBean("&testFactoryBean2");
assertThat(fb).as("FactoryBean itself must be advised").isInstanceOf(Advised.class);
assertThat(Map.class.isAssignableFrom(fb.getObjectType())).isTrue();
@ -117,7 +117,7 @@ class BeanNamePointcutTests { @@ -117,7 +117,7 @@ class BeanNamePointcutTests {
@Test
void pointcutAdvisorCombination() {
assertThat(this.interceptThis).as("Matching bean must be advised (proxied)").isInstanceOf(Advised.class);
assertThat(this.dontInterceptThis instanceof Advised).as("Non-matching bean must *not* be advised (proxied)").isFalse();
assertThat(this.dontInterceptThis).as("Non-matching bean must *not* be advised (proxied)").isNotInstanceOf(Advised.class);
interceptThis.setAge(20);
assertThat(testInterceptor.interceptionCount).isEqualTo(1);
dontInterceptThis.setAge(20);

2
spring-context/src/test/java/org/springframework/aop/framework/AbstractAopProxyTests.java

@ -854,7 +854,7 @@ abstract class AbstractAopProxyTests { @@ -854,7 +854,7 @@ abstract class AbstractAopProxyTests {
assertThat(proxied.getAge()).isEqualTo(10);
assertThat(mba.getCalls()).isEqualTo(1);
assertThat(proxied instanceof Advised).as("Cannot be cast to Advised").isFalse();
assertThat(proxied).as("Cannot be cast to Advised").isNotInstanceOf(Advised.class);
}
@Test

2
spring-context/src/test/java/org/springframework/context/annotation/configuration/ScopingTests.java

@ -153,7 +153,7 @@ class ScopingTests { @@ -153,7 +153,7 @@ class ScopingTests {
// get hidden bean
Object bean = ctx.getBean("scopedTarget." + beanName);
assertThat(bean instanceof ScopedObject).isFalse();
assertThat(bean).isNotInstanceOf(ScopedObject.class);
}
@Test

8
spring-context/src/test/java/org/springframework/context/i18n/LocaleContextHolderTests.java

@ -67,13 +67,13 @@ class LocaleContextHolderTests { @@ -67,13 +67,13 @@ class LocaleContextHolderTests {
LocaleContextHolder.setLocale(Locale.GERMAN);
assertThat(LocaleContextHolder.getLocale()).isEqualTo(Locale.GERMAN);
assertThat(LocaleContextHolder.getTimeZone()).isEqualTo(TimeZone.getDefault());
assertThat(LocaleContextHolder.getLocaleContext() instanceof TimeZoneAwareLocaleContext).isFalse();
assertThat(LocaleContextHolder.getLocaleContext()).isNotInstanceOf(TimeZoneAwareLocaleContext.class);
assertThat(LocaleContextHolder.getLocaleContext().getLocale()).isEqualTo(Locale.GERMAN);
LocaleContextHolder.setLocale(Locale.GERMANY);
assertThat(LocaleContextHolder.getLocale()).isEqualTo(Locale.GERMANY);
assertThat(LocaleContextHolder.getTimeZone()).isEqualTo(TimeZone.getDefault());
assertThat(LocaleContextHolder.getLocaleContext() instanceof TimeZoneAwareLocaleContext).isFalse();
assertThat(LocaleContextHolder.getLocaleContext()).isNotInstanceOf(TimeZoneAwareLocaleContext.class);
assertThat(LocaleContextHolder.getLocaleContext().getLocale()).isEqualTo(Locale.GERMANY);
LocaleContextHolder.setLocale(null);
@ -119,7 +119,7 @@ class LocaleContextHolderTests { @@ -119,7 +119,7 @@ class LocaleContextHolderTests {
LocaleContextHolder.setLocale(Locale.GERMANY);
assertThat(LocaleContextHolder.getLocale()).isEqualTo(Locale.GERMANY);
assertThat(LocaleContextHolder.getTimeZone()).isEqualTo(TimeZone.getDefault());
assertThat(LocaleContextHolder.getLocaleContext() instanceof TimeZoneAwareLocaleContext).isFalse();
assertThat(LocaleContextHolder.getLocaleContext()).isNotInstanceOf(TimeZoneAwareLocaleContext.class);
assertThat(LocaleContextHolder.getLocaleContext().getLocale()).isEqualTo(Locale.GERMANY);
LocaleContextHolder.setTimeZone(TimeZone.getTimeZone("GMT+1"));
@ -139,7 +139,7 @@ class LocaleContextHolderTests { @@ -139,7 +139,7 @@ class LocaleContextHolderTests {
LocaleContextHolder.setTimeZone(null);
assertThat(LocaleContextHolder.getLocale()).isEqualTo(Locale.GERMAN);
assertThat(LocaleContextHolder.getTimeZone()).isEqualTo(TimeZone.getDefault());
assertThat(LocaleContextHolder.getLocaleContext() instanceof TimeZoneAwareLocaleContext).isFalse();
assertThat(LocaleContextHolder.getLocaleContext()).isNotInstanceOf(TimeZoneAwareLocaleContext.class);
assertThat(LocaleContextHolder.getLocaleContext().getLocale()).isEqualTo(Locale.GERMAN);
LocaleContextHolder.setTimeZone(TimeZone.getTimeZone("GMT+2"));

24
spring-context/src/test/java/org/springframework/scripting/groovy/GroovyScriptFactoryTests.java

@ -78,8 +78,8 @@ class GroovyScriptFactoryTests { @@ -78,8 +78,8 @@ class GroovyScriptFactoryTests {
assertThat(AopUtils.isAopProxy(calc)).as("Shouldn't get proxy when refresh is disabled").isFalse();
assertThat(AopUtils.isAopProxy(messenger)).as("Shouldn't get proxy when refresh is disabled").isFalse();
assertThat(calc instanceof Refreshable).as("Scripted object should not be instance of Refreshable").isFalse();
assertThat(messenger instanceof Refreshable).as("Scripted object should not be instance of Refreshable").isFalse();
assertThat(calc).as("Scripted object should not be instance of Refreshable").isNotInstanceOf(Refreshable.class);
assertThat(messenger).as("Scripted object should not be instance of Refreshable").isNotInstanceOf(Refreshable.class);
assertThat(calc).isEqualTo(calc);
assertThat(messenger).isEqualTo(messenger);
@ -107,8 +107,8 @@ class GroovyScriptFactoryTests { @@ -107,8 +107,8 @@ class GroovyScriptFactoryTests {
assertThat(AopUtils.isAopProxy(calc)).as("Shouldn't get proxy when refresh is disabled").isFalse();
assertThat(AopUtils.isAopProxy(messenger)).as("Shouldn't get proxy when refresh is disabled").isFalse();
assertThat(calc instanceof Refreshable).as("Scripted object should not be instance of Refreshable").isFalse();
assertThat(messenger instanceof Refreshable).as("Scripted object should not be instance of Refreshable").isFalse();
assertThat(calc).as("Scripted object should not be instance of Refreshable").isNotInstanceOf(Refreshable.class);
assertThat(messenger).as("Scripted object should not be instance of Refreshable").isNotInstanceOf(Refreshable.class);
assertThat(calc).isEqualTo(calc);
assertThat(messenger).isEqualTo(messenger);
@ -130,7 +130,7 @@ class GroovyScriptFactoryTests { @@ -130,7 +130,7 @@ class GroovyScriptFactoryTests {
ConfigurableMessenger messenger2 = (ConfigurableMessenger) ctx.getBean("messengerPrototype");
assertThat(AopUtils.isAopProxy(messenger)).as("Shouldn't get proxy when refresh is disabled").isFalse();
assertThat(messenger instanceof Refreshable).as("Scripted object should not be instance of Refreshable").isFalse();
assertThat(messenger).as("Scripted object should not be instance of Refreshable").isNotInstanceOf(Refreshable.class);
assertThat(messenger2).isNotSameAs(messenger);
assertThat(messenger2.getClass()).isSameAs(messenger.getClass());
@ -149,7 +149,7 @@ class GroovyScriptFactoryTests { @@ -149,7 +149,7 @@ class GroovyScriptFactoryTests {
ConfigurableMessenger messenger2 = (ConfigurableMessenger) ctx.getBean("messengerPrototype");
assertThat(AopUtils.isAopProxy(messenger)).as("Shouldn't get proxy when refresh is disabled").isFalse();
assertThat(messenger instanceof Refreshable).as("Scripted object should not be instance of Refreshable").isFalse();
assertThat(messenger).as("Scripted object should not be instance of Refreshable").isNotInstanceOf(Refreshable.class);
assertThat(messenger2).isNotSameAs(messenger);
assertThat(messenger2.getClass()).isSameAs(messenger.getClass());
@ -168,7 +168,7 @@ class GroovyScriptFactoryTests { @@ -168,7 +168,7 @@ class GroovyScriptFactoryTests {
Messenger messenger = (Messenger) ctx.getBean("messengerInstance");
assertThat(AopUtils.isAopProxy(messenger)).as("Shouldn't get proxy when refresh is disabled").isFalse();
assertThat(messenger instanceof Refreshable).as("Scripted object should not be instance of Refreshable").isFalse();
assertThat(messenger).as("Scripted object should not be instance of Refreshable").isNotInstanceOf(Refreshable.class);
String desiredMessage = "Hello World!";
assertThat(messenger.getMessage()).as("Message is incorrect").isEqualTo(desiredMessage);
@ -182,7 +182,7 @@ class GroovyScriptFactoryTests { @@ -182,7 +182,7 @@ class GroovyScriptFactoryTests {
Messenger messenger = (Messenger) ctx.getBean("messengerInstance");
assertThat(AopUtils.isAopProxy(messenger)).as("Shouldn't get proxy when refresh is disabled").isFalse();
assertThat(messenger instanceof Refreshable).as("Scripted object should not be instance of Refreshable").isFalse();
assertThat(messenger).as("Scripted object should not be instance of Refreshable").isNotInstanceOf(Refreshable.class);
String desiredMessage = "Hello World!";
assertThat(messenger.getMessage()).as("Message is incorrect").isEqualTo(desiredMessage);
@ -196,7 +196,7 @@ class GroovyScriptFactoryTests { @@ -196,7 +196,7 @@ class GroovyScriptFactoryTests {
Messenger messenger = (Messenger) ctx.getBean("messengerInstanceInline");
assertThat(AopUtils.isAopProxy(messenger)).as("Shouldn't get proxy when refresh is disabled").isFalse();
assertThat(messenger instanceof Refreshable).as("Scripted object should not be instance of Refreshable").isFalse();
assertThat(messenger).as("Scripted object should not be instance of Refreshable").isNotInstanceOf(Refreshable.class);
String desiredMessage = "Hello World!";
assertThat(messenger.getMessage()).as("Message is incorrect").isEqualTo(desiredMessage);
@ -210,7 +210,7 @@ class GroovyScriptFactoryTests { @@ -210,7 +210,7 @@ class GroovyScriptFactoryTests {
Messenger messenger = (Messenger) ctx.getBean("messengerInstanceInline");
assertThat(AopUtils.isAopProxy(messenger)).as("Shouldn't get proxy when refresh is disabled").isFalse();
assertThat(messenger instanceof Refreshable).as("Scripted object should not be instance of Refreshable").isFalse();
assertThat(messenger).as("Scripted object should not be instance of Refreshable").isNotInstanceOf(Refreshable.class);
String desiredMessage = "Hello World!";
assertThat(messenger.getMessage()).as("Message is incorrect").isEqualTo(desiredMessage);
@ -355,7 +355,7 @@ class GroovyScriptFactoryTests { @@ -355,7 +355,7 @@ class GroovyScriptFactoryTests {
CallCounter countingAspect = (CallCounter) ctx.getBean("getMessageAspect");
assertThat(AopUtils.isAopProxy(messenger)).isTrue();
assertThat(messenger instanceof Refreshable).isFalse();
assertThat(messenger).isNotInstanceOf(Refreshable.class);
assertThat(countingAspect.getCalls()).isEqualTo(0);
assertThat(messenger.getMessage()).isEqualTo("Hello World!");
assertThat(countingAspect.getCalls()).isEqualTo(1);
@ -387,7 +387,7 @@ class GroovyScriptFactoryTests { @@ -387,7 +387,7 @@ class GroovyScriptFactoryTests {
assertThat(ObjectUtils.containsElement(bd.getDependsOn(), "messenger")).isTrue();
Calculator calculator = (Calculator) ctx.getBean("calculator");
assertThat(calculator).isNotNull();
assertThat(calculator instanceof Refreshable).isFalse();
assertThat(calculator).isNotInstanceOf(Refreshable.class);
}
@Test

2
spring-webflux/src/test/java/org/springframework/web/reactive/resource/EncodedResourceResolverTests.java

@ -128,7 +128,7 @@ class EncodedResourceResolverTests { @@ -128,7 +128,7 @@ class EncodedResourceResolverTests {
assertThat(resolved.getDescription()).isEqualTo(getResource(file).getDescription());
assertThat(resolved.getFilename()).isEqualTo(getResource(file).getFilename());
assertThat(resolved instanceof HttpResource).isFalse();
assertThat(resolved).isNotInstanceOf(HttpResource.class);
}
@Test // SPR-13149

2
spring-webmvc/src/test/java/org/springframework/web/servlet/resource/EncodedResourceResolverTests.java

@ -116,7 +116,7 @@ class EncodedResourceResolverTests { @@ -116,7 +116,7 @@ class EncodedResourceResolverTests {
assertThat(resolved.getDescription()).isEqualTo(getResource(file).getDescription());
assertThat(resolved.getFilename()).isEqualTo(getResource(file).getFilename());
assertThat(resolved instanceof HttpResource).isFalse();
assertThat(resolved).isNotInstanceOf(HttpResource.class);
}
@Test // SPR-13149

Loading…
Cancel
Save