Skip to content

Commit 7fcd1de

Browse files
committed
Use AssertJ's isEmpty() instead of hasSize(0)
Achieved via global search-and-replace.
1 parent d5b0b2b commit 7fcd1de

File tree

79 files changed

+260
-295
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+260
-295
lines changed

spring-aop/src/test/java/org/springframework/aop/support/AbstractRegexpMethodPointcutTests.java

Lines changed: 0 additions & 114 deletions
This file was deleted.

spring-aop/src/test/java/org/springframework/aop/support/JdkRegexpMethodPointcutTests.java

Lines changed: 84 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,14 +16,93 @@
1616

1717
package org.springframework.aop.support;
1818

19+
import java.io.IOException;
20+
21+
import org.junit.jupiter.api.Test;
22+
23+
import org.springframework.beans.testfixture.beans.TestBean;
24+
import org.springframework.core.testfixture.io.SerializationTestUtils;
25+
26+
import static org.assertj.core.api.Assertions.assertThat;
27+
1928
/**
29+
* @author Rod Johnson
30+
* @author Dmitriy Kopylenko
31+
* @author Chris Beams
2032
* @author Dmitriy Kopylenko
2133
*/
22-
public class JdkRegexpMethodPointcutTests extends AbstractRegexpMethodPointcutTests {
34+
class JdkRegexpMethodPointcutTests {
35+
36+
private AbstractRegexpMethodPointcut rpc = new JdkRegexpMethodPointcut();
37+
38+
39+
@Test
40+
void noPatternSupplied() throws Exception {
41+
noPatternSuppliedTests(rpc);
42+
}
43+
44+
@Test
45+
void serializationWithNoPatternSupplied() throws Exception {
46+
rpc = SerializationTestUtils.serializeAndDeserialize(rpc);
47+
noPatternSuppliedTests(rpc);
48+
}
49+
50+
private void noPatternSuppliedTests(AbstractRegexpMethodPointcut rpc) throws Exception {
51+
assertThat(rpc.matches(Object.class.getMethod("hashCode"), String.class)).isFalse();
52+
assertThat(rpc.matches(Object.class.getMethod("wait"), Object.class)).isFalse();
53+
assertThat(rpc.getPatterns()).isEmpty();
54+
}
55+
56+
@Test
57+
void exactMatch() throws Exception {
58+
rpc.setPattern("java.lang.Object.hashCode");
59+
exactMatchTests(rpc);
60+
rpc = SerializationTestUtils.serializeAndDeserialize(rpc);
61+
exactMatchTests(rpc);
62+
}
63+
64+
private void exactMatchTests(AbstractRegexpMethodPointcut rpc) throws Exception {
65+
// assumes rpc.setPattern("java.lang.Object.hashCode");
66+
assertThat(rpc.matches(Object.class.getMethod("hashCode"), String.class)).isTrue();
67+
assertThat(rpc.matches(Object.class.getMethod("hashCode"), Object.class)).isTrue();
68+
assertThat(rpc.matches(Object.class.getMethod("wait"), Object.class)).isFalse();
69+
}
70+
71+
@Test
72+
void specificMatch() throws Exception {
73+
rpc.setPattern("java.lang.String.hashCode");
74+
assertThat(rpc.matches(Object.class.getMethod("hashCode"), String.class)).isTrue();
75+
assertThat(rpc.matches(Object.class.getMethod("hashCode"), Object.class)).isFalse();
76+
}
77+
78+
@Test
79+
void wildcard() throws Exception {
80+
rpc.setPattern(".*Object.hashCode");
81+
assertThat(rpc.matches(Object.class.getMethod("hashCode"), Object.class)).isTrue();
82+
assertThat(rpc.matches(Object.class.getMethod("wait"), Object.class)).isFalse();
83+
}
84+
85+
@Test
86+
void wildcardForOneClass() throws Exception {
87+
rpc.setPattern("java.lang.Object.*");
88+
assertThat(rpc.matches(Object.class.getMethod("hashCode"), String.class)).isTrue();
89+
assertThat(rpc.matches(Object.class.getMethod("wait"), String.class)).isTrue();
90+
}
91+
92+
@Test
93+
void matchesObjectClass() throws Exception {
94+
rpc.setPattern("java.lang.Object.*");
95+
assertThat(rpc.matches(Exception.class.getMethod("hashCode"), IOException.class)).isTrue();
96+
// Doesn't match a method from Throwable
97+
assertThat(rpc.matches(Exception.class.getMethod("getMessage"), Exception.class)).isFalse();
98+
}
2399

24-
@Override
25-
protected AbstractRegexpMethodPointcut getRegexpMethodPointcut() {
26-
return new JdkRegexpMethodPointcut();
100+
@Test
101+
void withExclusion() throws Exception {
102+
this.rpc.setPattern(".*get.*");
103+
this.rpc.setExcludedPattern(".*Age.*");
104+
assertThat(this.rpc.matches(TestBean.class.getMethod("getName"), TestBean.class)).isTrue();
105+
assertThat(this.rpc.matches(TestBean.class.getMethod("getAge"), TestBean.class)).isFalse();
27106
}
28107

29108
}

spring-beans/src/test/java/org/springframework/beans/BeanWrapperEnumTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public void testStandardEnumSetWithAutoGrowing() {
144144
bw.setAutoGrowNestedPaths(true);
145145
assertThat(gb.getStandardEnumSet()).isNull();
146146
bw.getPropertyValue("standardEnumSet.class");
147-
assertThat(gb.getStandardEnumSet()).hasSize(0);
147+
assertThat(gb.getStandardEnumSet()).isEmpty();
148148
}
149149

150150
@Test

spring-beans/src/test/java/org/springframework/beans/factory/BeanFactoryUtilsTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public void testHierarchicalCountBeansWithOverride() {
103103
public void testHierarchicalNamesWithNoMatch() {
104104
List<String> names = Arrays.asList(
105105
BeanFactoryUtils.beanNamesForTypeIncludingAncestors(this.listableBeanFactory, NoOp.class));
106-
assertThat(names).hasSize(0);
106+
assertThat(names).isEmpty();
107107
}
108108

109109
@Test
@@ -278,7 +278,7 @@ public void testHierarchicalResolutionWithOverride() {
278278
public void testHierarchicalNamesForAnnotationWithNoMatch() {
279279
List<String> names = Arrays.asList(
280280
BeanFactoryUtils.beanNamesForAnnotationIncludingAncestors(this.listableBeanFactory, Override.class));
281-
assertThat(names).hasSize(0);
281+
assertThat(names).isEmpty();
282282
}
283283

284284
@Test

spring-beans/src/test/java/org/springframework/beans/factory/config/PropertyResourceConfigurerTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ public void testPropertyPlaceholderConfigurerWithSelfReferencingPlaceholderInAli
577577

578578
TestBean tb = (TestBean) factory.getBean("tb");
579579
assertThat(tb).isNotNull();
580-
assertThat(factory.getAliases("tb")).hasSize(0);
580+
assertThat(factory.getAliases("tb")).isEmpty();
581581
}
582582

583583
@Test

spring-beans/src/test/java/org/springframework/beans/factory/config/YamlMapFactoryBeanTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public class YamlMapFactoryBeanTests {
4747
public void testSetIgnoreResourceNotFound() {
4848
this.factory.setResolutionMethod(YamlMapFactoryBean.ResolutionMethod.OVERRIDE_AND_IGNORE);
4949
this.factory.setResources(new FileSystemResource("non-exsitent-file.yml"));
50-
assertThat(this.factory.getObject()).hasSize(0);
50+
assertThat(this.factory.getObject()).isEmpty();
5151
}
5252

5353
@Test

spring-beans/src/test/java/org/springframework/beans/factory/support/BeanFactoryGenericsTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ void parameterizedInstanceFactoryMethodWithInvalidClassName() {
762762
assertThat(bf.getType("mock")).isNull();
763763
assertThat(bf.getType("mock")).isNull();
764764
Map<String, Runnable> beans = bf.getBeansOfType(Runnable.class);
765-
assertThat(beans).hasSize(0);
765+
assertThat(beans).isEmpty();
766766
}
767767

768768
@Test
@@ -828,8 +828,8 @@ void testGenericMatchingWithBeanNameDifferentiation() {
828828
assertThat(numberStoreNames).hasSize(2);
829829
assertThat(numberStoreNames[0]).isEqualTo("doubleStore");
830830
assertThat(numberStoreNames[1]).isEqualTo("floatStore");
831-
assertThat(doubleStoreNames).hasSize(0);
832-
assertThat(floatStoreNames).hasSize(0);
831+
assertThat(doubleStoreNames).isEmpty();
832+
assertThat(floatStoreNames).isEmpty();
833833
}
834834

835835
@Test

spring-beans/src/test/java/org/springframework/beans/factory/support/DefaultSingletonBeanRegistryTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void testSingletons() {
5151

5252
beanRegistry.destroySingletons();
5353
assertThat(beanRegistry.getSingletonCount()).isEqualTo(0);
54-
assertThat(beanRegistry.getSingletonNames()).hasSize(0);
54+
assertThat(beanRegistry.getSingletonNames()).isEmpty();
5555
}
5656

5757
@Test
@@ -72,7 +72,7 @@ public void testDisposableBean() {
7272

7373
beanRegistry.destroySingletons();
7474
assertThat(beanRegistry.getSingletonCount()).isEqualTo(0);
75-
assertThat(beanRegistry.getSingletonNames()).hasSize(0);
75+
assertThat(beanRegistry.getSingletonNames()).isEmpty();
7676
assertThat(tb.wasDestroyed()).isTrue();
7777
}
7878

spring-beans/src/test/java/org/springframework/beans/factory/xml/EventPublicationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ void beanEventReceived() throws Exception {
9090
assertThat(componentDefinition1.getBeanDefinitions()).hasSize(1);
9191
BeanDefinition beanDefinition2 = componentDefinition2.getBeanDefinitions()[0];
9292
assertThat(beanDefinition2.getPropertyValues().getPropertyValue("name").getValue()).isEqualTo(new TypedStringValue("Juergen Hoeller"));
93-
assertThat(componentDefinition2.getBeanReferences()).hasSize(0);
93+
assertThat(componentDefinition2.getBeanReferences()).isEmpty();
9494
assertThat(componentDefinition2.getInnerBeanDefinitions()).hasSize(1);
9595
BeanDefinition innerBd2 = componentDefinition2.getInnerBeanDefinitions()[0];
9696
assertThat(innerBd2.getPropertyValues().getPropertyValue("name").getValue()).isEqualTo(new TypedStringValue("Eva Schallmeiner"));

spring-beans/src/test/java/org/springframework/beans/propertyeditors/PropertiesEditorTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public void nullValue() {
139139
PropertiesEditor pe= new PropertiesEditor();
140140
pe.setAsText(null);
141141
Properties p = (Properties) pe.getValue();
142-
assertThat(p).hasSize(0);
142+
assertThat(p).isEmpty();
143143
}
144144

145145
@Test

spring-context-indexer/src/test/java/org/springframework/context/index/processor/CandidateComponentsIndexerTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,13 @@ void createCompiler(@TempDir Path tempDir) throws IOException {
8282
@Test
8383
void noCandidate() {
8484
CandidateComponentsMetadata metadata = compile(SampleNone.class);
85-
assertThat(metadata.getItems()).hasSize(0);
85+
assertThat(metadata.getItems()).isEmpty();
8686
}
8787

8888
@Test
8989
void noAnnotation() {
9090
CandidateComponentsMetadata metadata = compile(CandidateComponentsIndexerTests.class);
91-
assertThat(metadata.getItems()).hasSize(0);
91+
assertThat(metadata.getItems()).isEmpty();
9292
}
9393

9494
@Test
@@ -214,7 +214,7 @@ void embeddedCandidatesAreDetected()
214214
@Test
215215
void embeddedNonStaticCandidateAreIgnored() {
216216
CandidateComponentsMetadata metadata = compile(SampleNonStaticEmbedded.class);
217-
assertThat(metadata.getItems()).hasSize(0);
217+
assertThat(metadata.getItems()).isEmpty();
218218
}
219219

220220
private void testComponent(Class<?>... classes) {

spring-context-support/src/test/java/org/springframework/cache/jcache/interceptor/CacheRemoveAllOperationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public void simpleRemoveAll() {
4242
CacheRemoveAllOperation operation = createSimpleOperation();
4343

4444
CacheInvocationParameter[] allParameters = operation.getAllParameters();
45-
assertThat(allParameters).hasSize(0);
45+
assertThat(allParameters).isEmpty();
4646
}
4747

4848
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ public void testCannotRemoveAdvisorWhenFrozen() throws Throwable {
796796
advised.removeAdvisor(0);
797797
// Check it still works: proxy factory state shouldn't have been corrupted
798798
assertThat(proxied.getAge()).isEqualTo(target.getAge());
799-
assertThat(advised.getAdvisors()).hasSize(0);
799+
assertThat(advised.getAdvisors()).isEmpty();
800800
}
801801

802802
@Test

spring-context/src/test/java/org/springframework/beans/factory/xml/XmlBeanFactoryTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,7 +1530,7 @@ void stringConstructorArrayNoType() {
15301530
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONSTRUCTOR_ARG_CONTEXT);
15311531
ConstructorArrayTestBean bean = (ConstructorArrayTestBean) xbf.getBean("constructorArrayNoType");
15321532
assertThat(bean.array instanceof String[]).isTrue();
1533-
assertThat(((String[]) bean.array)).hasSize(0);
1533+
assertThat(((String[]) bean.array)).isEmpty();
15341534
}
15351535

15361536
@Test
@@ -1541,7 +1541,7 @@ void stringConstructorArrayNoTypeNonLenient() {
15411541
bd.setLenientConstructorResolution(false);
15421542
ConstructorArrayTestBean bean = (ConstructorArrayTestBean) xbf.getBean("constructorArrayNoType");
15431543
assertThat(bean.array instanceof String[]).isTrue();
1544-
assertThat(((String[]) bean.array)).hasSize(0);
1544+
assertThat(((String[]) bean.array)).isEmpty();
15451545
}
15461546

15471547
@Test

0 commit comments

Comments
 (0)