@Test public void testFind() throws Exception { Pattern pat = Pattern.compile("(a[bB]c)"); LimitedTimeMatcher ltm = new LimitedTimeMatcher(pat, "foobar abc xyzzy aBc foobar", 1_000, "Test2"); ltm.run(); assertTrue(ltm.matched()); assertTrue(ltm.finished()); assertFalse(ltm.timedOut()); assertEquals("abc", ltm.group(1)); ltm.run(); assertTrue(ltm.matched()); assertTrue(ltm.finished()); assertFalse(ltm.timedOut()); assertEquals("aBc", ltm.group(1)); ltm.run(); assertFalse(ltm.matched()); assertTrue(ltm.finished()); assertFalse(ltm.timedOut()); try { ltm.group(); } catch (IllegalStateException e) { assertTrue("Should throw this exception", true); } }
@Test public void testTimeout() { Pattern pat = Pattern.compile("(x+x+)+y"); LimitedTimeMatcher ltm = new LimitedTimeMatcher(pat, "xxxxxxxxxxxxxxxxxxxxxxx", 1_000, "Test"); ltm.run(); assertTrue(ltm.timedOut()); }