11/*
2- * Copyright 2002-2007 the original author or authors.
2+ * Copyright 2002-2015 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.
1616
1717package org .springframework .util ;
1818
19- import junit .framework .TestCase ;
19+ import org .junit .Test ;
20+
21+ import static org .junit .Assert .*;
2022
2123/**
2224 * @author Juergen Hoeller
2325 * @author Johan Gorter
2426 */
25- public class PatternMatchUtilsTests extends TestCase {
27+ public class PatternMatchUtilsTests {
2628
29+ @ Test
2730 public void testTrivial () {
2831 assertEquals (false , PatternMatchUtils .simpleMatch ((String ) null , "" ));
2932 assertEquals (false , PatternMatchUtils .simpleMatch ("1" , null ));
3033 doTest ("*" , "123" , true );
3134 doTest ("123" , "123" , true );
3235 }
3336
37+ @ Test
3438 public void testStartsWith () {
3539 doTest ("get*" , "getMe" , true );
3640 doTest ("get*" , "setMe" , false );
3741 }
3842
43+ @ Test
3944 public void testEndsWith () {
4045 doTest ("*Test" , "getMeTest" , true );
4146 doTest ("*Test" , "setMe" , false );
4247 }
4348
49+ @ Test
4450 public void testBetween () {
4551 doTest ("*stuff*" , "getMeTest" , false );
4652 doTest ("*stuff*" , "getstuffTest" , true );
@@ -49,13 +55,15 @@ public void testBetween() {
4955 doTest ("*stuff*" , "stuff" , true );
5056 }
5157
58+ @ Test
5259 public void testStartsEnds () {
5360 doTest ("on*Event" , "onMyEvent" , true );
5461 doTest ("on*Event" , "onEvent" , true );
5562 doTest ("3*3" , "3" , false );
5663 doTest ("3*3" , "33" , true );
5764 }
5865
66+ @ Test
5967 public void testStartsEndsBetween () {
6068 doTest ("12*45*78" , "12345678" , true );
6169 doTest ("12*45*78" , "123456789" , false );
@@ -66,6 +74,7 @@ public void testStartsEndsBetween() {
6674 doTest ("3*3*3" , "333" , true );
6775 }
6876
77+ @ Test
6978 public void testRidiculous () {
7079 doTest ("*1*2*3*" , "0011002001010030020201030" , true );
7180 doTest ("1*2*3*4" , "10300204" , false );
@@ -74,6 +83,22 @@ public void testRidiculous() {
7483 doTest ("*1*2*3*" , "132" , false );
7584 }
7685
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+
77102 private void doTest (String pattern , String str , boolean shouldMatch ) {
78103 assertEquals (shouldMatch , PatternMatchUtils .simpleMatch (pattern , str ));
79104 }
0 commit comments