From 38285e0e1147042b519957958083e537e6d90fc9 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Wed, 12 Aug 2020 10:34:39 +0000 Subject: Minor unification of tests. --- .../com/yahoo/test/CollectionPatternMatcher.java | 45 ---------------------- .../java/com/yahoo/test/PartialOrderTester.java | 12 +++--- .../main/java/com/yahoo/test/PatternMatcher.java | 38 ------------------ .../main/java/com/yahoo/test/TotalOrderTester.java | 12 +++--- .../com/yahoo/test/PatternMatchersTestCase.java | 40 ------------------- 5 files changed, 10 insertions(+), 137 deletions(-) delete mode 100644 testutil/src/main/java/com/yahoo/test/CollectionPatternMatcher.java delete mode 100644 testutil/src/main/java/com/yahoo/test/PatternMatcher.java delete mode 100644 testutil/src/test/java/com/yahoo/test/PatternMatchersTestCase.java (limited to 'testutil') 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> { - - 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 strings = (Collection) o; - for (String s : strings) - if (s.matches(pattern)) - return true; - return false; - } - - @Factory - public static Matcher> 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> extends OrderTester { 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 { - - 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 Matcher 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> extends OrderTester { 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 Steinar Knutsen - */ -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")); - } - -} -- cgit v1.2.3