Changed license to LGPLv3 or later.
[svjatoslav_commons.git] / src / test / java / eu / svjatoslav / commons / string / WildCardMatcherTest.java
1 /*
2  * Svjatoslav Commons - shared library of common functionality.
3  * Copyright ©2012-2014, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
4  * 
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of version 3 of the GNU Lesser General Public License
7  * or later as published by the Free Software Foundation.
8  */
9
10 package eu.svjatoslav.commons.string;
11
12 import static org.junit.Assert.fail;
13
14 import org.junit.Before;
15 import org.junit.Test;
16
17 public class WildCardMatcherTest {
18
19         private static void testWildcard(final String string, final String pattern,
20                         final boolean expectedResult) {
21
22                 final boolean result = WildCardMatcher.match(string, pattern);
23
24                 if (result != expectedResult)
25                         fail("Wildcard match failed.");
26
27         }
28
29         WildCardMatcher matcher;
30
31         @Before
32         public void setUp() throws Exception {
33
34         }
35
36         @Test
37         public void test() {
38
39                 testWildcard("IMG_9770.JPG", "*.J*", true);
40                 testWildcard("1", "1", true);
41                 testWildcard("1", "*", true);
42                 testWildcard("f", "1", false);
43                 testWildcard("Hello !", "Hell*!***", true);
44                 testWildcard("Hello !", "Hell*!", true);
45                 testWildcard("Hello !", "Hell*", true);
46                 testWildcard("Hello !", "Hell", false);
47                 testWildcard("Hello !", "* *", true);
48
49         }
50
51 }