04518fa836481c10b8213fe9033b6d93177445be
[svjatoslav_commons.git] / src / test / java / eu / svjatoslav / commons / string / WildCardMatcherTest.java
1 /*
2  * Svjatoslav Commons - shared library of common functionality.
3  * Copyright (C) 2012, 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 2 of the GNU General Public License
7  * 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         WildCardMatcher matcher;
20
21         @Before
22         public void setUp() throws Exception {
23
24         }
25
26         @Test
27         public void test() {
28
29                 testWildcard("IMG_9770.JPG", "*.J*", true);
30                 testWildcard("1", "1", true);
31                 testWildcard("1", "*", true);
32                 testWildcard("f", "1", false);
33                 testWildcard("Hello !", "Hell*!***", true);
34                 testWildcard("Hello !", "Hell*!", true);
35                 testWildcard("Hello !", "Hell*", true);
36                 testWildcard("Hello !", "Hell", false);
37                 testWildcard("Hello !", "* *", true);
38
39         }
40
41         private static void testWildcard(final String string, final String pattern,
42                         final boolean expectedResult) {
43
44                 final boolean result = WildCardMatcher.match(string, pattern);
45
46                 if (result != expectedResult) {
47                         fail("Wildcard match failed.");
48                 }
49
50         }
51
52 }