Convert assertThat(x instanceof X).isTrue() to assertThat(x).isInstanceOf()

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

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

See gh-36504
This commit is contained in:
Sam Brannen
2026-03-19 15:13:12 +01:00
parent 4357bbd31b
commit a40ec44cb7
70 changed files with 176 additions and 175 deletions
@@ -63,7 +63,7 @@ class AopNamespaceHandlerScopeIntegrationTests {
@Test
void singletonScoping() throws Exception {
assertThat(AopUtils.isAopProxy(singletonScoped)).as("Should be AOP proxy").isTrue();
assertThat(singletonScoped instanceof TestBean).as("Should be target class proxy").isTrue();
assertThat(singletonScoped).as("Should be target class proxy").isInstanceOf(TestBean.class);
String rob = "Rob Harrop";
String bram = "Bram Smeets";
assertThat(singletonScoped.getName()).isEqualTo(rob);
@@ -81,7 +81,7 @@ class AopNamespaceHandlerScopeIntegrationTests {
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(oldRequest));
assertThat(AopUtils.isAopProxy(requestScoped)).as("Should be AOP proxy").isTrue();
assertThat(requestScoped instanceof TestBean).as("Should be target class proxy").isTrue();
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();
@@ -168,7 +168,7 @@ class AdvisorAutoProxyCreatorIntegrationTests {
BeanFactory bf = getBeanFactory();
Object bean = bf.getBean(TXMANAGER_BEAN_NAME);
assertThat(bean instanceof CallCountingTransactionManager).isTrue();
assertThat(bean).isInstanceOf(CallCountingTransactionManager.class);
CallCountingTransactionManager txMan = (CallCountingTransactionManager) bf.getBean(TXMANAGER_BEAN_NAME);
Rollback rb = (Rollback) bf.getBean("rollback");
@@ -185,7 +185,7 @@ class ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests {
// should be dynamic proxy, implementing both interfaces
assertThat(AopUtils.isJdkDynamicProxy(bean)).isTrue();
assertThat(bean instanceof AnotherScopeTestInterface).isTrue();
assertThat(bean).isInstanceOf(AnotherScopeTestInterface.class);
assertThat(bean.getName()).isEqualTo(DEFAULT_NAME);
bean.setName(MODIFIED_NAME);
@@ -206,7 +206,7 @@ class ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests {
// should be a class-based proxy
assertThat(AopUtils.isCglibProxy(bean)).isTrue();
assertThat(bean instanceof RequestScopedTestBean).isTrue();
assertThat(bean).isInstanceOf(RequestScopedTestBean.class);
assertThat(bean.getName()).isEqualTo(DEFAULT_NAME);
bean.setName(MODIFIED_NAME);
@@ -248,7 +248,7 @@ class ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests {
// should be dynamic proxy, implementing both interfaces
assertThat(AopUtils.isJdkDynamicProxy(bean)).isTrue();
assertThat(bean instanceof AnotherScopeTestInterface).isTrue();
assertThat(bean).isInstanceOf(AnotherScopeTestInterface.class);
assertThat(bean.getName()).isEqualTo(DEFAULT_NAME);
bean.setName(MODIFIED_NAME);
@@ -275,8 +275,8 @@ class ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests {
// should be a class-based proxy
assertThat(AopUtils.isCglibProxy(bean)).isTrue();
assertThat(bean instanceof ScopedTestBean).isTrue();
assertThat(bean instanceof SessionScopedTestBean).isTrue();
assertThat(bean).isInstanceOf(ScopedTestBean.class);
assertThat(bean).isInstanceOf(SessionScopedTestBean.class);
assertThat(bean.getName()).isEqualTo(DEFAULT_NAME);
bean.setName(MODIFIED_NAME);
@@ -166,7 +166,7 @@ class ClassPathBeanDefinitionScannerScopeIntegrationTests {
// should be dynamic proxy, implementing both interfaces
assertThat(AopUtils.isJdkDynamicProxy(bean)).isTrue();
assertThat(bean instanceof AnotherScopeTestInterface).isTrue();
assertThat(bean).isInstanceOf(AnotherScopeTestInterface.class);
assertThat(bean.getName()).isEqualTo(DEFAULT_NAME);
bean.setName(MODIFIED_NAME);
@@ -187,7 +187,7 @@ class ClassPathBeanDefinitionScannerScopeIntegrationTests {
// should be a class-based proxy
assertThat(AopUtils.isCglibProxy(bean)).isTrue();
assertThat(bean instanceof RequestScopedTestBean).isTrue();
assertThat(bean).isInstanceOf(RequestScopedTestBean.class);
assertThat(bean.getName()).isEqualTo(DEFAULT_NAME);
bean.setName(MODIFIED_NAME);
@@ -229,7 +229,7 @@ class ClassPathBeanDefinitionScannerScopeIntegrationTests {
// should be dynamic proxy, implementing both interfaces
assertThat(AopUtils.isJdkDynamicProxy(bean)).isTrue();
assertThat(bean instanceof AnotherScopeTestInterface).isTrue();
assertThat(bean).isInstanceOf(AnotherScopeTestInterface.class);
assertThat(bean.getName()).isEqualTo(DEFAULT_NAME);
bean.setName(MODIFIED_NAME);
@@ -256,8 +256,8 @@ class ClassPathBeanDefinitionScannerScopeIntegrationTests {
// should be a class-based proxy
assertThat(AopUtils.isCglibProxy(bean)).isTrue();
assertThat(bean instanceof ScopedTestBean).isTrue();
assertThat(bean instanceof SessionScopedTestBean).isTrue();
assertThat(bean).isInstanceOf(ScopedTestBean.class);
assertThat(bean).isInstanceOf(SessionScopedTestBean.class);
assertThat(bean.getName()).isEqualTo(DEFAULT_NAME);
bean.setName(MODIFIED_NAME);