diff options
Diffstat (limited to 'testutil')
5 files changed, 10 insertions, 137 deletions
diff --git a/testutil/src/main/java/com/yahoo/test/CollectionPatternMatcher.java b/testutil/src/main/java/com/yahoo/test/CollectionPatternMatcher.java deleted file mode 100644 index 609a5558027..00000000000 --- a/testutil/src/main/java/com/yahoo/test/CollectionPatternMatcher.java +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.test; - -import org.hamcrest.BaseMatcher; -import org.hamcrest.Description; -import org.hamcrest.Factory; -import org.hamcrest.Matcher; - -import java.util.Collection; - -/** - * Checks if a collection of strings contains at least one string with the expected regex pattern. - * - * @author gjoranv - * @since 5.1.8 - */ -public class CollectionPatternMatcher extends BaseMatcher<Collection<String>> { - - private final String pattern; - - public CollectionPatternMatcher(String pattern) { - this.pattern = pattern; - } - - @Override - public void describeTo(Description description) { - description.appendText("contains a string that matches expression '" + pattern + "'"); - } - - @Override - public boolean matches(Object o) { - @SuppressWarnings("unchecked") - Collection<String> strings = (Collection<String>) o; - for (String s : strings) - if (s.matches(pattern)) - return true; - return false; - } - - @Factory - public static <T> Matcher<Collection<String>> containsStringWithPattern(String pattern) { - return new CollectionPatternMatcher(pattern); - } - -} diff --git a/testutil/src/main/java/com/yahoo/test/PartialOrderTester.java b/testutil/src/main/java/com/yahoo/test/PartialOrderTester.java index c5fa71ddc62..6152cbf5b25 100644 --- a/testutil/src/main/java/com/yahoo/test/PartialOrderTester.java +++ b/testutil/src/main/java/com/yahoo/test/PartialOrderTester.java @@ -1,10 +1,8 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.test; -import static org.junit.Assert.assertThat; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.Matchers.lessThanOrEqualTo; -import static org.hamcrest.Matchers.greaterThanOrEqualTo; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; /** * PartialOrderTester implements a partial order test for OrderTester @@ -16,14 +14,14 @@ import static org.hamcrest.Matchers.greaterThanOrEqualTo; public class PartialOrderTester<T extends Comparable<T>> extends OrderTester<T> { protected void lessTest(T a, T b) throws AssertionError { - assertThat(a + " must be less than or equal to " + b, a.compareTo(b), lessThanOrEqualTo(0)); + assertTrue(a + " must be less than or equal to " + b, a.compareTo(b) <= 0); } protected void greaterTest(T a, T b) throws AssertionError { - assertThat(a + " must be greater than or equal to " + b, a.compareTo(b), greaterThanOrEqualTo(0)); + assertTrue(a + " must be greater than or equal to " + b, a.compareTo(b) >= 0); } protected void equalTest(T a, T b) throws AssertionError { - assertThat(a + " must be compared equal to " + b, a.compareTo(b), is(0)); + assertEquals(a + " must be compared equal to " + b, 0, a.compareTo(b)); } } diff --git a/testutil/src/main/java/com/yahoo/test/PatternMatcher.java b/testutil/src/main/java/com/yahoo/test/PatternMatcher.java deleted file mode 100644 index 0aafcf2f1be..00000000000 --- a/testutil/src/main/java/com/yahoo/test/PatternMatcher.java +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.test; - -import org.hamcrest.BaseMatcher; -import org.hamcrest.Description; -import org.hamcrest.Factory; -import org.hamcrest.Matcher; - -/** - * Matches a string against an expected regex pattern. - * - * @author gjoranv - * @since 5.1.7 - */ -public class PatternMatcher extends BaseMatcher<String> { - - private final String pattern; - - public PatternMatcher(String pattern) { - this.pattern = pattern; - } - - @Override - public void describeTo(Description description) { - description.appendText("matches expression '" + pattern + "'"); - } - - @Override - public boolean matches(Object o) { - return ((String)o).matches(pattern); - } - - @Factory - public static <T> Matcher<String> matchesPattern(String pattern) { - return new PatternMatcher(pattern); - } - -} diff --git a/testutil/src/main/java/com/yahoo/test/TotalOrderTester.java b/testutil/src/main/java/com/yahoo/test/TotalOrderTester.java index d9acd845428..05a8545d606 100644 --- a/testutil/src/main/java/com/yahoo/test/TotalOrderTester.java +++ b/testutil/src/main/java/com/yahoo/test/TotalOrderTester.java @@ -1,10 +1,8 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.test; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; -import static org.hamcrest.Matchers.lessThanOrEqualTo; -import static org.hamcrest.Matchers.greaterThanOrEqualTo; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; /** * TotalOrderTester implements a total order test for OrderTester @@ -24,14 +22,14 @@ import static org.hamcrest.Matchers.greaterThanOrEqualTo; public class TotalOrderTester<T extends Comparable<T>> extends OrderTester<T> { protected void lessTest(T a, T b) throws AssertionError { - assertThat(a + " must be less than " + b, a.compareTo(b), lessThanOrEqualTo(-1)); + assertTrue(a + " must be less than " + b, a.compareTo(b) <= -1); } protected void greaterTest(T a, T b) throws AssertionError { - assertThat(a + " must be greater than " + b, a.compareTo(b), greaterThanOrEqualTo(1)); + assertTrue(a + " must be greater than " + b, a.compareTo(b) >= 1); } protected void equalTest(T a, T b) throws AssertionError { - assertThat(a + " must be compared equal to " + b, a.compareTo(b), is(0)); + assertEquals(a + " must be compared equal to " + b, 0, a.compareTo(b)); } } diff --git a/testutil/src/test/java/com/yahoo/test/PatternMatchersTestCase.java b/testutil/src/test/java/com/yahoo/test/PatternMatchersTestCase.java deleted file mode 100644 index b17d5b36252..00000000000 --- a/testutil/src/test/java/com/yahoo/test/PatternMatchersTestCase.java +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.test; - -import static org.junit.Assert.*; - -import java.util.Arrays; - -import org.junit.Test; - -/** - * Check CollectionPatternMatcher, LinePatternMatcher and PatternMatcher. - * - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> - */ -public class PatternMatchersTestCase { - - @Test - public final void testCollections() { - CollectionPatternMatcher cm = new CollectionPatternMatcher("a.*"); - String[] coll = new String[] {}; - assertEquals(false, cm.matches(Arrays.asList(coll))); - coll = new String[] { "ba", "ab" }; - assertEquals(true, cm.matches(Arrays.asList(coll))); - } - - @Test - public final void testLines() { - LinePatternMatcher lp = new LinePatternMatcher("a"); - assertEquals(true, lp.matches("a\nab")); - assertEquals(false, lp.matches("ab\nb")); - } - - @Test - public final void testPatterns() { - PatternMatcher m = new PatternMatcher(".*a.*"); - assertEquals(true, m.matches("ab")); - assertEquals(false, m.matches("b")); - } - -} |