2 * Svjatoslav Commons - shared library of common functionality.
3 * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
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.
10 package eu.svjatoslav.commons.string;
12 import static org.junit.Assert.fail;
14 import org.junit.Before;
15 import org.junit.Test;
17 public class WildCardMatcherTest {
19 WildCardMatcher matcher;
22 public void setUp() throws Exception {
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);
41 private static void testWildcard(final String string, final String pattern,
42 final boolean expectedResult) {
44 final boolean result = WildCardMatcher.match(string, pattern);
46 if (result != expectedResult) {
47 fail("Wildcard match failed.");