diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2017-06-04 07:15:52 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2017-06-04 07:15:52 +0000 |
commit | aa5d06e1590c1cfd87e83ef308a2d6b6728b4ba4 (patch) | |
tree | 13281a6c8b77e1e4c4fe2bdebef6eb2b2b874632 /tests/src/com/android/loganalysis/util/RegexTrieTest.java | |
parent | 225b00c055a85a8f7cf31cb1241820583d50c0bd (diff) | |
parent | 6722a63f63ea406f42edb2c03b18bbb6fd8c24c6 (diff) | |
download | loganalysis-1b435b9bf53619aeaac270b38691177eb894f4a1.tar.gz |
release-request-777c0f47-a42e-446a-b45c-0bb1aaa9612e-for-git_oc-release-4066915 snap-temp-L92300000070444114android-security-8.0.0_r54android-security-8.0.0_r53android-security-8.0.0_r52android-cts-8.0_r1android-8.0.0_r9android-8.0.0_r7android-8.0.0_r51android-8.0.0_r50android-8.0.0_r49android-8.0.0_r48android-8.0.0_r47android-8.0.0_r46android-8.0.0_r45android-8.0.0_r44android-8.0.0_r43android-8.0.0_r42android-8.0.0_r41android-8.0.0_r40android-8.0.0_r4android-8.0.0_r39android-8.0.0_r38android-8.0.0_r37android-8.0.0_r36android-8.0.0_r35android-8.0.0_r32android-8.0.0_r31android-8.0.0_r30android-8.0.0_r3android-8.0.0_r29android-8.0.0_r28android-8.0.0_r2android-8.0.0_r17android-8.0.0_r16android-8.0.0_r15android-8.0.0_r13android-8.0.0_r12android-8.0.0_r11android-8.0.0_r10android-8.0.0_r1security-oc-releaseoreo-security-releaseoreo-releaseoreo-r6-releaseoreo-r5-releaseoreo-r4-releaseoreo-r3-releaseoreo-r2-release
Change-Id: I1c3ee7a1d2445ce2b48c6117f03ff416cff0b10f
Diffstat (limited to 'tests/src/com/android/loganalysis/util/RegexTrieTest.java')
-rw-r--r-- | tests/src/com/android/loganalysis/util/RegexTrieTest.java | 51 |
1 files changed, 34 insertions, 17 deletions
diff --git a/tests/src/com/android/loganalysis/util/RegexTrieTest.java b/tests/src/com/android/loganalysis/util/RegexTrieTest.java index 3b00e55..4b689b6 100644 --- a/tests/src/com/android/loganalysis/util/RegexTrieTest.java +++ b/tests/src/com/android/loganalysis/util/RegexTrieTest.java @@ -15,9 +15,18 @@ */ package com.android.loganalysis.util; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + import com.android.loganalysis.util.RegexTrie.CompPattern; -import junit.framework.TestCase; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; import java.util.ArrayList; import java.util.Arrays; @@ -25,25 +34,26 @@ import java.util.HashMap; import java.util.List; import java.util.regex.Pattern; -/** - * Set of unit tests to verify the behavior of the RegexTrie - */ -public class RegexTrieTest extends TestCase { +/** Set of unit tests to verify the behavior of the RegexTrie */ +@RunWith(JUnit4.class) +public class RegexTrieTest { private RegexTrie<Integer> mTrie = null; private static final Integer STORED_VAL = 42; private static final List<String> NULL_LIST = Arrays.asList((String)null); - @Override + @Before public void setUp() throws Exception { mTrie = new RegexTrie<Integer>(); } + @Test public void testStringPattern() { mTrie.put(STORED_VAL, "[p]art1", "[p]art2", "[p]art3"); Integer retrieved = mTrie.retrieve("part1", "part2", "part3"); assertEquals(STORED_VAL, retrieved); } + @Test public void testAlternation_single() { mTrie.put(STORED_VAL, "alpha|beta"); Integer retrieved; @@ -59,6 +69,7 @@ public class RegexTrieTest extends TestCase { assertNull(retrieved); } + @Test public void testAlternation_multiple() { mTrie.put(STORED_VAL, "a|alpha", "b|beta"); Integer retrieved; @@ -79,6 +90,7 @@ public class RegexTrieTest extends TestCase { assertNull(retrieved); } + @Test public void testGroups_fullMatch() { mTrie.put(STORED_VAL, "a|(alpha)", "b|(beta)"); Integer retrieved; @@ -109,6 +121,7 @@ public class RegexTrieTest extends TestCase { assertEquals(Arrays.asList("beta"), groups.get(1)); } + @Test public void testGroups_partialMatch() { mTrie.put(STORED_VAL, "a|(alpha)", "b|(beta)"); Integer retrieved; @@ -140,9 +153,8 @@ public class RegexTrieTest extends TestCase { assertEquals(Arrays.asList("beta"), groups.get(1)); } - /** - * Make sure that the wildcard functionality works - */ + /** Make sure that the wildcard functionality works */ + @Test public void testWildcard() { mTrie.put(STORED_VAL, "a", null); Integer retrieved; @@ -165,6 +177,7 @@ public class RegexTrieTest extends TestCase { * Make sure that if a wildcard and a more specific match could both match, that the more * specific match takes precedence */ + @Test public void testWildcard_precedence() { // Do one before and one after the wildcard to check for ordering effects mTrie.put(STORED_VAL + 1, "a", "(b)"); @@ -196,6 +209,7 @@ public class RegexTrieTest extends TestCase { * Verify a bugfix: make sure that no NPE results from calling #retrieve with a wildcard but * without a place to retrieve captures. */ + @Test public void testWildcard_noCapture() throws NullPointerException { mTrie.put(STORED_VAL, "a", null); String[] key = new String[] {"a", "b", "c"}; @@ -205,6 +219,7 @@ public class RegexTrieTest extends TestCase { // test passes if no exceptions were thrown } + @Test public void testMultiChild() { mTrie.put(STORED_VAL + 1, "a", "b"); mTrie.put(STORED_VAL + 2, "a", "c"); @@ -217,8 +232,9 @@ public class RegexTrieTest extends TestCase { } /** - * Make sure that {@link CompPattern#equals} works as expected. Shake a proverbial fist at Java + * Make sure that {@link CompPattern#equals} works as expected. Shake a proverbial fist at Java */ + @Test public void testCompPattern_equality() { String regex = "regex"; Pattern p1 = Pattern.compile(regex); @@ -229,19 +245,20 @@ public class RegexTrieTest extends TestCase { CompPattern cpOther = new CompPattern(pOther); // This is the problem with Pattern as implemented - assertFalse(p1.equals(p2)); - assertFalse(p2.equals(p1)); + assertNotEquals(p1, p2); + assertNotEquals(p2, p1); // Make sure that wrapped patterns with the same regex are considered equivalent - assertTrue(cp2.equals(p1)); - assertTrue(cp2.equals(p2)); - assertTrue(cp2.equals(cp1)); + assertEquals(cp2, p1); + assertEquals(cp2, p1); + assertEquals(cp2, cp1); // And make sure that wrapped patterns with different regexen are still considered different - assertFalse(cp2.equals(pOther)); - assertFalse(cp2.equals(cpOther)); + assertNotEquals(cp2, pOther); + assertNotEquals(cp2, cpOther); } + @Test public void testCompPattern_hashmap() { HashMap<CompPattern, Integer> map = new HashMap<CompPattern, Integer>(); String regex = "regex"; |