diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index 9369c55..12abf68 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -1,4 +1,5 @@ eclipse.preferences.version=1 +org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 org.eclipse.jdt.core.compiler.compliance=11 org.eclipse.jdt.core.compiler.source=11 diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..4a74214 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,11 @@ +# Changelog +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [0.6.0] - unreleased + +### Breaking Changes + +* [#6](https://github.com/itsallcode/hamcrest-auto-matcher/pull/6): Rename packages to `org.itsallcode` diff --git a/README.md b/README.md index 41badf2..50cbd70 100644 --- a/README.md +++ b/README.md @@ -15,9 +15,11 @@ Writing a hamcrest matcher for your model classes by extending [`TypeSafeDiagnos * Good layout of actual and expected property values is hard to get right. * Each property occurs in multiple places which violates the [DRY](https://en.wikipedia.org/wiki/Don't_repeat_yourself) principle. -## Requirements +## Project Information -Java 11 +* [Changelog](CHANGELOG.md) +* Requirements + * Java 11 ## How to use hamcrest-auto-matcher in your project @@ -44,9 +46,9 @@ dependencies { ``` -### Using [`AutoMatcher`](src/main/java/com/github/hamstercommunity/matcher/auto/AutoMatcher.java) +### Using [`AutoMatcher`](src/main/java/org/itsallcode/matcher/auto/AutoMatcher.java) -Assume you have two model classes [`DemoModel`](src/test/java/com/github/hamstercommunity/matcher/model/DemoModel.java) and [`DemoAttribute`](src/test/java/com/github/hamstercommunity/matcher/model/DemoAttribute.java): +Assume you have two model classes [`DemoModel`](src/test/java/org/itsallcode/matcher/model/DemoModel.java) and [`DemoAttribute`](src/test/java/org/itsallcode/matcher/model/DemoAttribute.java): ```java public class DemoModel { @@ -116,9 +118,11 @@ public class DemoAttribute { } ``` -Use [`AutoMatcher.equalTo()`](src/main/java/com/github/hamstercommunity/matcher/auto/AutoMatcher.java) to create a matcher for your expected model instance. This will use reflection to determine expected property values based on getter methods: +Use [`AutoMatcher.equalTo()`](src/main/java/org/itsallcode/matcher/auto/AutoMatcher.java) to create a matcher for your expected model instance. This will use reflection to determine expected property values based on getter methods: ```java +org.itsallcode.matcher.auto.AutoMatcher; + DemoModel expected = ...; DemoModel actual = ...; assertThat(actual, AutoMatcher.equalTo(expected)); @@ -130,8 +134,8 @@ Expected: {id=<4711>, longVal=null, name="name1", attr=null, stringArray=null, c but: {longVal was <42L>} ``` -### Using [`ConfigurableMatcher`](src/main/java/com/github/hamstercommunity/matcher/config/ConfigurableMatcher.java) -If `AutoMatcher` does not work for your model classes, you can still use [`ConfigurableMatcher`](src/main/java/com/github/hamstercommunity/matcher/config/ConfigurableMatcher.java) and [`MatcherConfig`](src/main/java/com/github/hamstercommunity/matcher/config/MatcherConfig.java) which allows you to specify properties and custom matchers explicitly but is much easier to use than `TypeSafeDiagnosingMatcher`. +### Using [`ConfigurableMatcher`](src/main/java/org/itsallcode/matcher/config/ConfigurableMatcher.java) +If `AutoMatcher` does not work for your model classes, you can still use [`ConfigurableMatcher`](src/main/java/org/itsallcode/matcher/config/ConfigurableMatcher.java) and [`MatcherConfig`](src/main/java/org/itsallcode/matcher/config/MatcherConfig.java) which allows you to specify properties and custom matchers explicitly but is much easier to use than `TypeSafeDiagnosingMatcher`. ```java public class DemoModelMatcher { @@ -148,7 +152,7 @@ public class DemoModelMatcher { } } ``` -Also see [`DemoModelMatcher`](src/test/java/com/github/hamstercommunity/matcher/model/DemoModelMatcher.java) as an example. +Also see [`DemoModelMatcher`](src/test/java/org/itsallcode/matcher/model/DemoModelMatcher.java) as an example. ## Development @@ -198,7 +202,7 @@ open build/reports/jacoco/test/html/index.html signing.secretKeyRingFile= ``` -2. Increment version number in `build.gradle` and `README.md`, commit and push. +2. Increment version number in `build.gradle` and `README.md`, update `CHANGELOG.md`, commit and push. 3. Optional: run the following command to do a dry-run: ```sh diff --git a/src/main/java/com/github/hamstercommunity/matcher/BaseTypeSafeDiagnosingMatcher.java b/src/main/java/org/itsallcode/matcher/BaseTypeSafeDiagnosingMatcher.java similarity index 96% rename from src/main/java/com/github/hamstercommunity/matcher/BaseTypeSafeDiagnosingMatcher.java rename to src/main/java/org/itsallcode/matcher/BaseTypeSafeDiagnosingMatcher.java index ec9d69b..7747f30 100644 --- a/src/main/java/com/github/hamstercommunity/matcher/BaseTypeSafeDiagnosingMatcher.java +++ b/src/main/java/org/itsallcode/matcher/BaseTypeSafeDiagnosingMatcher.java @@ -1,4 +1,4 @@ -package com.github.hamstercommunity.matcher; +package org.itsallcode.matcher; import org.hamcrest.Description; import org.hamcrest.TypeSafeDiagnosingMatcher; diff --git a/src/main/java/com/github/hamstercommunity/matcher/DescriptionBuilder.java b/src/main/java/org/itsallcode/matcher/DescriptionBuilder.java similarity index 95% rename from src/main/java/com/github/hamstercommunity/matcher/DescriptionBuilder.java rename to src/main/java/org/itsallcode/matcher/DescriptionBuilder.java index 26f1093..e9d17de 100644 --- a/src/main/java/com/github/hamstercommunity/matcher/DescriptionBuilder.java +++ b/src/main/java/org/itsallcode/matcher/DescriptionBuilder.java @@ -1,4 +1,4 @@ -package com.github.hamstercommunity.matcher; +package org.itsallcode.matcher; import org.hamcrest.*; diff --git a/src/main/java/com/github/hamstercommunity/matcher/MismatchReporter.java b/src/main/java/org/itsallcode/matcher/MismatchReporter.java similarity index 97% rename from src/main/java/com/github/hamstercommunity/matcher/MismatchReporter.java rename to src/main/java/org/itsallcode/matcher/MismatchReporter.java index faa35d3..90861d4 100644 --- a/src/main/java/com/github/hamstercommunity/matcher/MismatchReporter.java +++ b/src/main/java/org/itsallcode/matcher/MismatchReporter.java @@ -1,4 +1,4 @@ -package com.github.hamstercommunity.matcher; +package org.itsallcode.matcher; import org.hamcrest.Description; import org.hamcrest.Matcher; diff --git a/src/main/java/com/github/hamstercommunity/matcher/auto/AutoConfigBuilder.java b/src/main/java/org/itsallcode/matcher/auto/AutoConfigBuilder.java similarity index 81% rename from src/main/java/com/github/hamstercommunity/matcher/auto/AutoConfigBuilder.java rename to src/main/java/org/itsallcode/matcher/auto/AutoConfigBuilder.java index 0a2faa4..347c863 100644 --- a/src/main/java/com/github/hamstercommunity/matcher/auto/AutoConfigBuilder.java +++ b/src/main/java/org/itsallcode/matcher/auto/AutoConfigBuilder.java @@ -1,4 +1,4 @@ -package com.github.hamstercommunity.matcher.auto; +package org.itsallcode.matcher.auto; import static java.util.Arrays.asList; import static java.util.stream.Collectors.toList; @@ -20,10 +20,9 @@ import org.hamcrest.Matchers; import org.hamcrest.collection.IsArray; import org.hamcrest.collection.IsMapContaining; - -import com.github.hamstercommunity.matcher.config.ConfigurableMatcher; -import com.github.hamstercommunity.matcher.config.MatcherConfig; -import com.github.hamstercommunity.matcher.config.MatcherConfig.Builder; +import org.itsallcode.matcher.config.ConfigurableMatcher; +import org.itsallcode.matcher.config.MatcherConfig; +import org.itsallcode.matcher.config.MatcherConfig.Builder; class AutoConfigBuilder { @@ -37,7 +36,7 @@ class AutoConfigBuilder { private final T expected; private final Builder configBuilder; - private AutoConfigBuilder(T expected) { + private AutoConfigBuilder(final T expected) { this.expected = expected; this.configBuilder = MatcherConfig.builder(expected); } @@ -54,7 +53,7 @@ private MatcherConfig build() { return configBuilder.build(); } - public static Matcher createEqualToMatcher(T expected) { + public static Matcher createEqualToMatcher(final T expected) { if (expected.getClass().isArray()) { return createArrayMatcher(expected); } @@ -72,7 +71,7 @@ public static Matcher createEqualToMatcher(T expected) { } @SuppressWarnings("unchecked") - private static Matcher createArrayMatcher(Object expected) { + private static Matcher createArrayMatcher(final Object expected) { final Class componentType = (Class) expected.getClass().getComponentType(); if (componentType.isPrimitive()) { return (Matcher) Matchers.equalTo(expected); @@ -91,7 +90,7 @@ private static Matcher createArrayMatcher(Object expected) { } @SuppressWarnings("unchecked") - private static Matcher createMapContainsMatcher(T expected) { + private static Matcher createMapContainsMatcher(final T expected) { final Map expectedMap = (Map) expected; final Collection> matchers = new ArrayList<>(); @@ -108,11 +107,11 @@ private static Matcher createMapContainsMatcher(T expected) { private static ConfigurableMatcher mapSizeMatcher(final Map expectedMap) { @SuppressWarnings("unchecked") final MatcherConfig config = (MatcherConfig) MatcherConfig.builder(expectedMap) - .addEqualsProperty("size", map -> map.size()).build(); + .addEqualsProperty("size", Map::size).build(); return new ConfigurableMatcher<>(config); } - private static Matcher createIterableContainsMatcher(T expected) { + private static Matcher createIterableContainsMatcher(final T expected) { @SuppressWarnings("unchecked") final Iterable expectedIterable = (Iterable) expected; final Object[] elements = StreamSupport.stream(expectedIterable // @@ -123,38 +122,38 @@ private static Matcher createIterableContainsMatcher(T expected) { return matcher; } - private boolean isNotBlackListed(Method method) { + private boolean isNotBlackListed(final Method method) { final Set blacklist = new HashSet<>( asList("getClass", "getProtectionDomain", "getClassLoader", "getURLs")); return !blacklist.contains(method.getName()); } - private boolean isGetterMethodSignature(Method method) { + private boolean isGetterMethodSignature(final Method method) { return method.getParameterCount() == 0 // && !method.getReturnType().equals(Void.TYPE); } - private boolean isGetterMethodName(Method method) { + private boolean isGetterMethodName(final Method method) { final String methodName = method.getName(); return methodName.startsWith("get") // || methodName.startsWith("is"); } - private void addConfigForGetter(Method method) { + private void addConfigForGetter(final Method method) { final String propertyName = getPropertyName(method.getName()); LOG.finest(() -> "Adding general property '" + propertyName + "' for getter " + method); configBuilder.addProperty(propertyName, createGetter(method), AutoMatcher::equalTo); } - private boolean hasArrayReturnType(Method method) { + private boolean hasArrayReturnType(final Method method) { return method.getReturnType().isArray(); } - private

Function createGetter(Method method) { - return (object) -> getPropertyValue(method, object); + private

Function createGetter(final Method method) { + return object -> getPropertyValue(method, object); } - private boolean hasSimpleReturnType(Method method) { + private boolean hasSimpleReturnType(final Method method) { final Class type = method.getReturnType(); if (type.isPrimitive() || type.isEnum()) { return true; @@ -171,7 +170,7 @@ private static boolean isSimpleType(final Class type) { return false; } - private String getPropertyName(String methodName) { + private String getPropertyName(final String methodName) { int prefixLength = 3; if (methodName.startsWith("is")) { prefixLength = 2; @@ -184,8 +183,8 @@ private String decapitalize(final String string) { return Character.toLowerCase(string.charAt(0)) + string.substring(1); } - @SuppressWarnings("unchecked") - private static P getPropertyValue(Method method, T object) { + @SuppressWarnings({ "unchecked", "java:S3011" }) // Need to use reflection and setAccessible() + private static P getPropertyValue(final Method method, final T object) { final Class declaringClass = method.getDeclaringClass(); if (!declaringClass.isInstance(object)) { throw new AssertionError("Expected object of type " + declaringClass.getName() + " but got " @@ -197,7 +196,7 @@ private static P getPropertyValue(Method method, T object) { try { return (P) method.invoke(object); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { - throw new RuntimeException("Error invoking method " + method + " on object " + object + " of type " + throw new IllegalStateException("Error invoking method " + method + " on object " + object + " of type " + object.getClass().getName(), e); } } diff --git a/src/main/java/com/github/hamstercommunity/matcher/auto/AutoMatcher.java b/src/main/java/org/itsallcode/matcher/auto/AutoMatcher.java similarity index 63% rename from src/main/java/com/github/hamstercommunity/matcher/auto/AutoMatcher.java rename to src/main/java/org/itsallcode/matcher/auto/AutoMatcher.java index 79338cf..b864903 100644 --- a/src/main/java/com/github/hamstercommunity/matcher/auto/AutoMatcher.java +++ b/src/main/java/org/itsallcode/matcher/auto/AutoMatcher.java @@ -1,4 +1,4 @@ -package com.github.hamstercommunity.matcher.auto; +package org.itsallcode.matcher.auto; import static java.util.stream.Collectors.toList; import static org.hamcrest.Matchers.emptyIterable; @@ -8,8 +8,7 @@ import org.hamcrest.Matcher; import org.hamcrest.Matchers; - -import com.github.hamstercommunity.matcher.config.ConfigurableMatcher; +import org.itsallcode.matcher.config.ConfigurableMatcher; /** * This class configures and creates a {@link ConfigurableMatcher} using @@ -21,12 +20,13 @@ private AutoMatcher() { // not instantiable } - public static Matcher equalTo(T expected) { + public static Matcher equalTo(final T expected) { return AutoConfigBuilder.createEqualToMatcher(expected); } @SafeVarargs - public static Matcher> contains(T... expected) { + @SuppressWarnings({ "java:S1452", "varargs" }) // Wildcard type required here + public static Matcher> contains(final T... expected) { if (expected.length == 0) { return emptyIterable(); } @@ -34,14 +34,15 @@ public static Matcher> contains(T... expected) { } @SafeVarargs - public static Matcher> containsInAnyOrder(T... expected) { + @SuppressWarnings({ "java:S1452", "varargs" }) // Wildcard type required here + public static Matcher> containsInAnyOrder(final T... expected) { if (expected.length == 0) { return emptyIterable(); } return Matchers.containsInAnyOrder(getMatchers(expected)); } - private static List> getMatchers(T[] expected) { + private static List> getMatchers(final T[] expected) { return Arrays.stream(expected) // .map(AutoMatcher::equalTo) // .collect(toList()); diff --git a/src/main/java/com/github/hamstercommunity/matcher/config/ConfigurableMatcher.java b/src/main/java/org/itsallcode/matcher/config/ConfigurableMatcher.java similarity index 91% rename from src/main/java/com/github/hamstercommunity/matcher/config/ConfigurableMatcher.java rename to src/main/java/org/itsallcode/matcher/config/ConfigurableMatcher.java index 40ea299..30d824c 100644 --- a/src/main/java/com/github/hamstercommunity/matcher/config/ConfigurableMatcher.java +++ b/src/main/java/org/itsallcode/matcher/config/ConfigurableMatcher.java @@ -1,6 +1,6 @@ -package com.github.hamstercommunity.matcher.config; +package org.itsallcode.matcher.config; -import com.github.hamstercommunity.matcher.*; +import org.itsallcode.matcher.*; public class ConfigurableMatcher extends BaseTypeSafeDiagnosingMatcher { private final MatcherConfig config; diff --git a/src/main/java/com/github/hamstercommunity/matcher/config/MatcherConfig.java b/src/main/java/org/itsallcode/matcher/config/MatcherConfig.java similarity index 99% rename from src/main/java/com/github/hamstercommunity/matcher/config/MatcherConfig.java rename to src/main/java/org/itsallcode/matcher/config/MatcherConfig.java index 38a0f80..9439742 100644 --- a/src/main/java/com/github/hamstercommunity/matcher/config/MatcherConfig.java +++ b/src/main/java/org/itsallcode/matcher/config/MatcherConfig.java @@ -1,4 +1,4 @@ -package com.github.hamstercommunity.matcher.config; +package org.itsallcode.matcher.config; import static java.util.stream.Collectors.toList; diff --git a/src/main/java/com/github/hamstercommunity/matcher/config/PropertyConfig.java b/src/main/java/org/itsallcode/matcher/config/PropertyConfig.java similarity index 94% rename from src/main/java/com/github/hamstercommunity/matcher/config/PropertyConfig.java rename to src/main/java/org/itsallcode/matcher/config/PropertyConfig.java index 9975673..86603aa 100644 --- a/src/main/java/com/github/hamstercommunity/matcher/config/PropertyConfig.java +++ b/src/main/java/org/itsallcode/matcher/config/PropertyConfig.java @@ -1,4 +1,4 @@ -package com.github.hamstercommunity.matcher.config; +package org.itsallcode.matcher.config; import java.util.function.Function; diff --git a/src/test/java/com/github/hamstercommunity/matcher/auto/AutoMatcherArrayTest.java b/src/test/java/org/itsallcode/matcher/auto/AutoMatcherArrayTest.java similarity index 95% rename from src/test/java/com/github/hamstercommunity/matcher/auto/AutoMatcherArrayTest.java rename to src/test/java/org/itsallcode/matcher/auto/AutoMatcherArrayTest.java index c59d37a..f3ba860 100644 --- a/src/test/java/com/github/hamstercommunity/matcher/auto/AutoMatcherArrayTest.java +++ b/src/test/java/org/itsallcode/matcher/auto/AutoMatcherArrayTest.java @@ -1,7 +1,7 @@ -package com.github.hamstercommunity.matcher.auto; +package org.itsallcode.matcher.auto; -import static com.github.hamstercommunity.matcher.auto.TestUtil.assertValuesDoNotMatch; -import static com.github.hamstercommunity.matcher.auto.TestUtil.assertValuesMatch; +import static org.itsallcode.matcher.auto.TestUtil.assertValuesDoNotMatch; +import static org.itsallcode.matcher.auto.TestUtil.assertValuesMatch; import org.junit.Test; diff --git a/src/test/java/com/github/hamstercommunity/matcher/auto/AutoMatcherListTest.java b/src/test/java/org/itsallcode/matcher/auto/AutoMatcherListTest.java similarity index 81% rename from src/test/java/com/github/hamstercommunity/matcher/auto/AutoMatcherListTest.java rename to src/test/java/org/itsallcode/matcher/auto/AutoMatcherListTest.java index bf232ca..e53add8 100644 --- a/src/test/java/com/github/hamstercommunity/matcher/auto/AutoMatcherListTest.java +++ b/src/test/java/org/itsallcode/matcher/auto/AutoMatcherListTest.java @@ -1,18 +1,17 @@ -package com.github.hamstercommunity.matcher.auto; +package org.itsallcode.matcher.auto; -import static com.github.hamstercommunity.matcher.auto.TestUtil.assertValuesDoNotMatch; -import static com.github.hamstercommunity.matcher.auto.TestUtil.assertValuesMatch; import static java.util.Arrays.asList; import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; +import static org.itsallcode.matcher.auto.TestUtil.assertValuesDoNotMatch; +import static org.itsallcode.matcher.auto.TestUtil.assertValuesMatch; import java.util.ArrayList; import java.util.LinkedList; +import org.itsallcode.matcher.model.DemoAttribute; import org.junit.Test; -import com.github.hamstercommunity.matcher.model.DemoAttribute; - public class AutoMatcherListTest { @Test diff --git a/src/test/java/com/github/hamstercommunity/matcher/auto/AutoMatcherMapTest.java b/src/test/java/org/itsallcode/matcher/auto/AutoMatcherMapTest.java similarity index 84% rename from src/test/java/com/github/hamstercommunity/matcher/auto/AutoMatcherMapTest.java rename to src/test/java/org/itsallcode/matcher/auto/AutoMatcherMapTest.java index 19d450b..dca63a9 100644 --- a/src/test/java/com/github/hamstercommunity/matcher/auto/AutoMatcherMapTest.java +++ b/src/test/java/org/itsallcode/matcher/auto/AutoMatcherMapTest.java @@ -1,9 +1,9 @@ -package com.github.hamstercommunity.matcher.auto; +package org.itsallcode.matcher.auto; -import static com.github.hamstercommunity.matcher.auto.TestUtil.assertValuesDoNotMatch; -import static com.github.hamstercommunity.matcher.auto.TestUtil.assertValuesMatch; import static java.util.Collections.*; import static org.hamcrest.MatcherAssert.assertThat; +import static org.itsallcode.matcher.auto.TestUtil.assertValuesDoNotMatch; +import static org.itsallcode.matcher.auto.TestUtil.assertValuesMatch; import java.util.HashMap; import java.util.TreeMap; diff --git a/src/test/java/com/github/hamstercommunity/matcher/auto/AutoMatcherTest.java b/src/test/java/org/itsallcode/matcher/auto/AutoMatcherTest.java similarity index 86% rename from src/test/java/com/github/hamstercommunity/matcher/auto/AutoMatcherTest.java rename to src/test/java/org/itsallcode/matcher/auto/AutoMatcherTest.java index e61c307..128405f 100644 --- a/src/test/java/com/github/hamstercommunity/matcher/auto/AutoMatcherTest.java +++ b/src/test/java/org/itsallcode/matcher/auto/AutoMatcherTest.java @@ -1,10 +1,10 @@ -package com.github.hamstercommunity.matcher.auto; +package org.itsallcode.matcher.auto; -import static com.github.hamstercommunity.matcher.auto.TestUtil.assertValuesDoNotMatch; import static java.util.Arrays.asList; import static java.util.Collections.emptyList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.not; +import static org.itsallcode.matcher.auto.TestUtil.assertValuesDoNotMatch; import static org.junit.Assert.assertThrows; import java.io.File; @@ -15,12 +15,12 @@ import java.time.Instant; import java.util.*; +import org.hamcrest.Matcher; +import org.itsallcode.matcher.model.DemoAttribute; +import org.itsallcode.matcher.model.DemoModel; import org.junit.Before; import org.junit.Test; -import com.github.hamstercommunity.matcher.model.DemoAttribute; -import com.github.hamstercommunity.matcher.model.DemoModel; - public class AutoMatcherTest { private DemoModel value1; @@ -37,23 +37,26 @@ public void setup() { } @Test + @SuppressWarnings("unchecked") public void testIncompatibleTypes() { + final Matcher matcher = (Matcher) AutoMatcher.equalTo(value1); assertThrows( "Expected object of type " + DemoModel.class.getName() + " but got " + Integer.class.getName() + ": 1", AssertionError.class, - () -> assertThat(1, AutoMatcher.equalTo(value1))); + () -> assertThat(1, (Matcher) matcher)); } @Test + @SuppressWarnings("unchecked") public void testIncompatibleListMemberTypes() { final Object actual = asList(1); final Object expected = asList(new DemoAttribute("attr")); - + final Matcher matcher = (Matcher) AutoMatcher.equalTo(expected); assertThrows( "Expected object of type " + DemoAttribute.class.getName() + " but got " + Integer.class.getName() + ": 1", AssertionError.class, - () -> assertThat(actual, AutoMatcher.equalTo(expected))); + () -> assertThat(actual, (Matcher) matcher)); } @Test @@ -250,17 +253,17 @@ public void testAutoMatcherWorksForSimpleTypeUuid() { assertValuesDoNotMatch(UUID.randomUUID(), UUID.randomUUID()); } - private DemoModel model(String name, int id) { + private DemoModel model(final String name, final int id) { return model(name, id, asList(model(name + "-child1", id, emptyList()), model(name + "-child2", id, emptyList()))); } - private DemoModel model(String name, int id, List children) { + private DemoModel model(final String name, final int id, final List children) { return new DemoModel(id, name + "-" + id, id * 2L, attr(name + "-attr-" + id), new String[] { name + "-item1-" + id, name + "-item2-" + id }, children); } - private DemoAttribute attr(String value) { + private DemoAttribute attr(final String value) { return new DemoAttribute(value); } } diff --git a/src/test/java/com/github/hamstercommunity/matcher/auto/TestUtil.java b/src/test/java/org/itsallcode/matcher/auto/TestUtil.java similarity index 73% rename from src/test/java/com/github/hamstercommunity/matcher/auto/TestUtil.java rename to src/test/java/org/itsallcode/matcher/auto/TestUtil.java index 234a990..5006a8d 100644 --- a/src/test/java/com/github/hamstercommunity/matcher/auto/TestUtil.java +++ b/src/test/java/org/itsallcode/matcher/auto/TestUtil.java @@ -1,4 +1,4 @@ -package com.github.hamstercommunity.matcher.auto; +package org.itsallcode.matcher.auto; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.not; @@ -8,14 +8,14 @@ private TestUtil() { // not instantiable } - public static void assertValuesMatch(T value1, T value2) { + public static void assertValuesMatch(final T value1, final T value2) { assertThat(value1, AutoMatcher.equalTo(value1)); assertThat(value2, AutoMatcher.equalTo(value2)); assertThat(value2, AutoMatcher.equalTo(value1)); assertThat(value1, AutoMatcher.equalTo(value2)); } - public static void assertValuesDoNotMatch(T value1, T value2) { + public static void assertValuesDoNotMatch(final T value1, final T value2) { assertThat("expect not match", value1, not(AutoMatcher.equalTo(value2))); assertThat("expect match", value1, AutoMatcher.equalTo(value1)); assertThat("expect match", value2, AutoMatcher.equalTo(value2)); diff --git a/src/test/java/com/github/hamstercommunity/matcher/model/AutoDemoModelMatcherTest.java b/src/test/java/org/itsallcode/matcher/model/AutoDemoModelMatcherTest.java similarity index 78% rename from src/test/java/com/github/hamstercommunity/matcher/model/AutoDemoModelMatcherTest.java rename to src/test/java/org/itsallcode/matcher/model/AutoDemoModelMatcherTest.java index 9c38ae5..023685e 100644 --- a/src/test/java/com/github/hamstercommunity/matcher/model/AutoDemoModelMatcherTest.java +++ b/src/test/java/org/itsallcode/matcher/model/AutoDemoModelMatcherTest.java @@ -1,13 +1,12 @@ -package com.github.hamstercommunity.matcher.model; +package org.itsallcode.matcher.model; import java.util.function.Function; import org.hamcrest.Matcher; +import org.itsallcode.matcher.auto.AutoMatcher; import org.j8unit.runners.J8Unit4; import org.junit.runner.RunWith; -import com.github.hamstercommunity.matcher.auto.AutoMatcher; - /** * Unit test for {@link AutoMatcher} using {@link DemoModel} */ diff --git a/src/test/java/com/github/hamstercommunity/matcher/model/ConfigurableDemoModelMatcherTest.java b/src/test/java/org/itsallcode/matcher/model/ConfigurableDemoModelMatcherTest.java similarity index 88% rename from src/test/java/com/github/hamstercommunity/matcher/model/ConfigurableDemoModelMatcherTest.java rename to src/test/java/org/itsallcode/matcher/model/ConfigurableDemoModelMatcherTest.java index afa7d43..aaf6be8 100644 --- a/src/test/java/com/github/hamstercommunity/matcher/model/ConfigurableDemoModelMatcherTest.java +++ b/src/test/java/org/itsallcode/matcher/model/ConfigurableDemoModelMatcherTest.java @@ -1,4 +1,4 @@ -package com.github.hamstercommunity.matcher.model; +package org.itsallcode.matcher.model; import java.util.function.Function; diff --git a/src/test/java/com/github/hamstercommunity/matcher/model/DemoAttribute.java b/src/test/java/org/itsallcode/matcher/model/DemoAttribute.java similarity index 74% rename from src/test/java/com/github/hamstercommunity/matcher/model/DemoAttribute.java rename to src/test/java/org/itsallcode/matcher/model/DemoAttribute.java index 373768d..cd791bc 100644 --- a/src/test/java/com/github/hamstercommunity/matcher/model/DemoAttribute.java +++ b/src/test/java/org/itsallcode/matcher/model/DemoAttribute.java @@ -1,6 +1,6 @@ -package com.github.hamstercommunity.matcher.model; +package org.itsallcode.matcher.model; -import com.github.hamstercommunity.matcher.config.ConfigurableMatcher; +import org.itsallcode.matcher.config.ConfigurableMatcher; /** * A model class used for testing and demonstrating {@link ConfigurableMatcher}. diff --git a/src/test/java/com/github/hamstercommunity/matcher/model/DemoAttributeMatcher.java b/src/test/java/org/itsallcode/matcher/model/DemoAttributeMatcher.java similarity index 72% rename from src/test/java/com/github/hamstercommunity/matcher/model/DemoAttributeMatcher.java rename to src/test/java/org/itsallcode/matcher/model/DemoAttributeMatcher.java index 9789800..e2bf78d 100644 --- a/src/test/java/com/github/hamstercommunity/matcher/model/DemoAttributeMatcher.java +++ b/src/test/java/org/itsallcode/matcher/model/DemoAttributeMatcher.java @@ -1,7 +1,7 @@ -package com.github.hamstercommunity.matcher.model; +package org.itsallcode.matcher.model; -import com.github.hamstercommunity.matcher.config.ConfigurableMatcher; -import com.github.hamstercommunity.matcher.config.MatcherConfig; +import org.itsallcode.matcher.config.ConfigurableMatcher; +import org.itsallcode.matcher.config.MatcherConfig; /** * A matcher for {@link DemoAttribute} used for testing diff --git a/src/test/java/com/github/hamstercommunity/matcher/model/DemoModel.java b/src/test/java/org/itsallcode/matcher/model/DemoModel.java similarity index 90% rename from src/test/java/com/github/hamstercommunity/matcher/model/DemoModel.java rename to src/test/java/org/itsallcode/matcher/model/DemoModel.java index a2b188b..cc7f72b 100644 --- a/src/test/java/com/github/hamstercommunity/matcher/model/DemoModel.java +++ b/src/test/java/org/itsallcode/matcher/model/DemoModel.java @@ -1,9 +1,9 @@ -package com.github.hamstercommunity.matcher.model; +package org.itsallcode.matcher.model; import java.util.Arrays; import java.util.List; -import com.github.hamstercommunity.matcher.config.ConfigurableMatcher; +import org.itsallcode.matcher.config.ConfigurableMatcher; /** * A model class used for testing and demonstrating {@link ConfigurableMatcher}. diff --git a/src/test/java/com/github/hamstercommunity/matcher/model/DemoModelMatcher.java b/src/test/java/org/itsallcode/matcher/model/DemoModelMatcher.java similarity index 80% rename from src/test/java/com/github/hamstercommunity/matcher/model/DemoModelMatcher.java rename to src/test/java/org/itsallcode/matcher/model/DemoModelMatcher.java index d49ba08..4661c60 100644 --- a/src/test/java/com/github/hamstercommunity/matcher/model/DemoModelMatcher.java +++ b/src/test/java/org/itsallcode/matcher/model/DemoModelMatcher.java @@ -1,9 +1,8 @@ -package com.github.hamstercommunity.matcher.model; +package org.itsallcode.matcher.model; import org.hamcrest.Matcher; - -import com.github.hamstercommunity.matcher.config.ConfigurableMatcher; -import com.github.hamstercommunity.matcher.config.MatcherConfig; +import org.itsallcode.matcher.config.ConfigurableMatcher; +import org.itsallcode.matcher.config.MatcherConfig; /** * A matcher for {@link DemoModel} used for testing {@link ConfigurableMatcher} diff --git a/src/test/java/com/github/hamstercommunity/matcher/model/DemoModelMatcherTest.java b/src/test/java/org/itsallcode/matcher/model/DemoModelMatcherTest.java similarity index 97% rename from src/test/java/com/github/hamstercommunity/matcher/model/DemoModelMatcherTest.java rename to src/test/java/org/itsallcode/matcher/model/DemoModelMatcherTest.java index f52a7ac..fadb0e5 100644 --- a/src/test/java/com/github/hamstercommunity/matcher/model/DemoModelMatcherTest.java +++ b/src/test/java/org/itsallcode/matcher/model/DemoModelMatcherTest.java @@ -1,4 +1,4 @@ -package com.github.hamstercommunity.matcher.model; +package org.itsallcode.matcher.model; import static java.util.Arrays.asList; import static java.util.Collections.emptyList; @@ -6,11 +6,10 @@ import java.util.Collections; import java.util.List; +import org.itsallcode.matcher.config.ConfigurableMatcher; +import org.itsallcode.matcher.test.MatcherTestBase; import org.junit.Test; -import com.github.hamstercommunity.matcher.config.ConfigurableMatcher; -import com.github.hamstercommunity.matcher.test.MatcherTestBase; - /** * This tests {@link ConfigurableMatcher} and demonstrates usage of * {@link MatcherTestBase}. diff --git a/src/test/java/com/github/hamstercommunity/matcher/test/MatcherTestBase.java b/src/test/java/org/itsallcode/matcher/test/MatcherTestBase.java similarity index 84% rename from src/test/java/com/github/hamstercommunity/matcher/test/MatcherTestBase.java rename to src/test/java/org/itsallcode/matcher/test/MatcherTestBase.java index 35ec978..50ef2f0 100644 --- a/src/test/java/com/github/hamstercommunity/matcher/test/MatcherTestBase.java +++ b/src/test/java/org/itsallcode/matcher/test/MatcherTestBase.java @@ -1,11 +1,11 @@ -package com.github.hamstercommunity.matcher.test; +package org.itsallcode.matcher.test; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.core.IsEqual.equalTo; import static org.hamcrest.core.IsNot.not; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.util.function.Function; @@ -48,14 +48,11 @@ default void assertFailureDescription(final String expectedDescription, final St final String expectedExceptionMessage = "\nExpected: " + expectedDescription + "\n" // + " but: " + actualDescription; - try { - assertThat(actual, createMatcher(expected)); - fail("Expected AssertionError"); - } catch (final AssertionError e) { - assertThat(e, instanceOf(AssertionError.class)); - assertEquals(expectedExceptionMessage, e.getMessage()); - assertThat(e.getMessage(), equalTo(expectedExceptionMessage)); - } + final Matcher matcher = createMatcher(expected); + final AssertionError error = assertThrows(AssertionError.class, () -> assertThat(actual, matcher)); + assertThat(error, instanceOf(AssertionError.class)); + assertEquals(expectedExceptionMessage, error.getMessage()); + assertThat(error.getMessage(), equalTo(expectedExceptionMessage)); } /**