Use AssertJ's isEmpty() instead of hasSize(0) · spring-projects/spring-framework@7fcd1de (original) (raw)
1
1
`/*
`
2
``
`-
- Copyright 2002-2012 the original author or authors.
`
``
2
`+
- Copyright 2002-2022 the original author or authors.
`
3
3
` *
`
4
4
` * Licensed under the Apache License, Version 2.0 (the "License");
`
5
5
` * you may not use this file except in compliance with the License.
`
`@@ -16,14 +16,93 @@
`
16
16
``
17
17
`package org.springframework.aop.support;
`
18
18
``
``
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
+
19
28
`/**
`
``
29
`+
- @author Rod Johnson
`
``
30
`+
- @author Dmitriy Kopylenko
`
``
31
`+
- @author Chris Beams
`
20
32
` * @author Dmitriy Kopylenko
`
21
33
` */
`
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
`+
}
`
23
99
``
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();
`
27
106
` }
`
28
107
``
29
108
`}
`