1 package tim.prune.gui.map;
3 import static org.junit.jupiter.api.Assertions.*;
5 import java.util.HashSet;
7 import org.junit.jupiter.api.Test;
10 * JUnit tests for site name utils
12 class SiteNameUtilsTest
16 void testPickServerNameWithoutWildcards()
18 testPickSingleUrl("abc", "abc");
19 testPickSingleUrl("ab[]c", "abc");
20 testPickSingleUrl("[]abc", "abc");
21 testPickSingleUrl("abc[]", "abc");
25 * Test a pattern without wildcards which should always produce the expected result
26 * @param inPattern pattern for site name
27 * @param inExpected expected resolved name
29 private void testPickSingleUrl(String inPattern, String inExpected)
31 for (int i=0; i<20; i++)
33 String resolved = SiteNameUtils.pickServerUrl(inPattern);
34 assertEquals(inExpected, resolved, "Failed: " + inPattern);
39 void testPickUsingWildcards()
41 testRandomPick("ab[123]c", new String[]{"ab1c", "ab2c", "ab3c"});
42 testRandomPick("1234.[abcd]", new String[]{"1234.a", "1234.b", "1234.c", "1234.d"});
46 * Test a pattern with wildcards which should produce several different results randomly
47 * @param inPattern pattern for site name
48 * @param inExpected array of expected resolved names
50 private void testRandomPick(String inPattern, String[] inExpected)
52 HashSet<String> results = new HashSet<String>();
53 for (int i=0; i<30; i++)
55 results.add(SiteNameUtils.pickServerUrl(inPattern));
57 // Check that all expected results were returned
58 assertEquals(inExpected.length, results.size());
59 for (String expec : inExpected) {
60 assertTrue(results.contains(expec));