1
1
/*
2
- * Copyright 2002-2007 the original author or authors.
2
+ * Copyright 2002-2015 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
16
17
17
package org .springframework .util ;
18
18
19
- import junit .framework .TestCase ;
19
+ import org .junit .Test ;
20
+
21
+ import static org .junit .Assert .*;
20
22
21
23
/**
22
24
* @author Juergen Hoeller
23
25
* @author Johan Gorter
24
26
*/
25
- public class PatternMatchUtilsTests extends TestCase {
27
+ public class PatternMatchUtilsTests {
26
28
29
+ @ Test
27
30
public void testTrivial () {
28
31
assertEquals (false , PatternMatchUtils .simpleMatch ((String ) null , "" ));
29
32
assertEquals (false , PatternMatchUtils .simpleMatch ("1" , null ));
30
33
doTest ("*" , "123" , true );
31
34
doTest ("123" , "123" , true );
32
35
}
33
36
37
+ @ Test
34
38
public void testStartsWith () {
35
39
doTest ("get*" , "getMe" , true );
36
40
doTest ("get*" , "setMe" , false );
37
41
}
38
42
43
+ @ Test
39
44
public void testEndsWith () {
40
45
doTest ("*Test" , "getMeTest" , true );
41
46
doTest ("*Test" , "setMe" , false );
42
47
}
43
48
49
+ @ Test
44
50
public void testBetween () {
45
51
doTest ("*stuff*" , "getMeTest" , false );
46
52
doTest ("*stuff*" , "getstuffTest" , true );
@@ -49,13 +55,15 @@ public void testBetween() {
49
55
doTest ("*stuff*" , "stuff" , true );
50
56
}
51
57
58
+ @ Test
52
59
public void testStartsEnds () {
53
60
doTest ("on*Event" , "onMyEvent" , true );
54
61
doTest ("on*Event" , "onEvent" , true );
55
62
doTest ("3*3" , "3" , false );
56
63
doTest ("3*3" , "33" , true );
57
64
}
58
65
66
+ @ Test
59
67
public void testStartsEndsBetween () {
60
68
doTest ("12*45*78" , "12345678" , true );
61
69
doTest ("12*45*78" , "123456789" , false );
@@ -66,6 +74,7 @@ public void testStartsEndsBetween() {
66
74
doTest ("3*3*3" , "333" , true );
67
75
}
68
76
77
+ @ Test
69
78
public void testRidiculous () {
70
79
doTest ("*1*2*3*" , "0011002001010030020201030" , true );
71
80
doTest ("1*2*3*4" , "10300204" , false );
@@ -74,6 +83,22 @@ public void testRidiculous() {
74
83
doTest ("*1*2*3*" , "132" , false );
75
84
}
76
85
86
+ @ Test
87
+ public void testPatternVariants () {
88
+ doTest ("*a" , "*" , false );
89
+ doTest ("*a" , "a" , true );
90
+ doTest ("*a" , "b" , false );
91
+ doTest ("*a" , "aa" , true );
92
+ doTest ("*a" , "ba" , true );
93
+ doTest ("*a" , "ab" , false );
94
+ doTest ("**a" , "*" , false );
95
+ doTest ("**a" , "a" , true );
96
+ doTest ("**a" , "b" , false );
97
+ doTest ("**a" , "aa" , true );
98
+ doTest ("**a" , "ba" , true );
99
+ doTest ("**a" , "ab" , false );
100
+ }
101
+
77
102
private void doTest (String pattern , String str , boolean shouldMatch ) {
78
103
assertEquals (shouldMatch , PatternMatchUtils .simpleMatch (pattern , str ));
79
104
}
0 commit comments