This is an automated email from the ASF dual-hosted git repository. aledsage pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git
commit 2be6cd47f906d0806486d2e00216a2d064ca65d0 Author: Paul Campbell <pcampb...@kemitix.net> AuthorDate: Thu Oct 11 16:53:32 2018 +0100 Extract nested tests for findMappedName into top level class TestNG isn't good at running a subset of tests without a log of ceremony attached (e.g. config files and annotations). --- .../javalang/ReflectionsFindMappedNameTest.java | 145 +++++++++++++++++++++ .../brooklyn/util/javalang/ReflectionsTest.java | 139 +------------------- 2 files changed, 146 insertions(+), 138 deletions(-) diff --git a/utils/common/src/test/java/org/apache/brooklyn/util/javalang/ReflectionsFindMappedNameTest.java b/utils/common/src/test/java/org/apache/brooklyn/util/javalang/ReflectionsFindMappedNameTest.java new file mode 100644 index 0000000..d4bb0f6 --- /dev/null +++ b/utils/common/src/test/java/org/apache/brooklyn/util/javalang/ReflectionsFindMappedNameTest.java @@ -0,0 +1,145 @@ +package org.apache.brooklyn.util.javalang; + +import org.assertj.core.api.WithAssertions; +import org.testng.annotations.Test; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +/** + * Tests for {@link Reflections#findMappedNameAndLog(Map, String)} and + * {@link Reflections#findMappedNameMaybe(Map, String)} methods. + */ +public class ReflectionsFindMappedNameTest implements WithAssertions { + + @Test + public void givenRenamesIsNullThenReturnOriginalName() { + //given + final Map<String, String> renames = null; + final String originalName = createAName(); + //when + final String result = Reflections.findMappedNameAndLog(renames, originalName); + //then + assertThat(result).isEqualTo(originalName); + } + + @Test + public void givenRenamesIsEmptyThenReturnOriginalName() { + //given + final Map<String, String> renames = new HashMap<>(); + final String originalName = createAName(); + //when + final String result = Reflections.findMappedNameAndLog(renames, originalName); + //then + assertThat(result).isEqualTo(originalName); + } + + @Test + public void givenRenamesHasNoMatchThenReturnOriginalName() { + //given + final Map<String, String> renames = new HashMap<>(); + renames.put(createAName(), createAName()); + final String originalName = createAName(); + //when + final String result = Reflections.findMappedNameAndLog(renames, originalName); + //then + assertThat(result).isEqualTo(originalName); + } + + @Test + public void givenRenamesHasMatchThenReturnUpdatedName() { + //given + final Map<String, String> renames = new HashMap<>(); + final String originalName = createAName(); + final String updatedName = createAName(); + renames.put(originalName, updatedName); + //when + final String result = Reflections.findMappedNameAndLog(renames, originalName); + //then + assertThat(result).isEqualTo(updatedName); + } + + @Test + public void givenInnerClassHasNoMatchThenReturnOriginalName() { + //given + final Map<String, String> renames = new HashMap<>(); + final String originalName = createAName() + "$" + createAName(); + //when + final String result = Reflections.findMappedNameAndLog(renames, originalName); + //then + assertThat(result).isEqualTo(originalName); + } + + @Test + public void givenInnerClassHasMatchThenReturnUpdatedName() { + //given + final Map<String, String> renames = new HashMap<>(); + final String originalName = createAName() + "$" + createAName(); + final String updatedName = createAName(); + renames.put(originalName, updatedName); + //when + final String result = Reflections.findMappedNameAndLog(renames, originalName); + //then + assertThat(result).isEqualTo(updatedName); + } + + @Test + public void givenInnerClassWhenOnlyOuterClassHasMatchThenReturnUpdatedName() { + //given + final Map<String, String> renames = new HashMap<>(); + final String originalOuterClass = createAName(); + final String originalInnerClass = createAName(); + final String originalName = originalOuterClass + "$" + originalInnerClass; + final String updatedOuterClass = createAName(); + final String updatedName = updatedOuterClass + "$" + originalInnerClass; + renames.put(originalOuterClass, updatedOuterClass); + //when + final String result = Reflections.findMappedNameAndLog(renames, originalName); + //then + assertThat(result).isEqualTo(updatedName); + } + + @Test + public void givenInnerClassWhenOuterAndInnerClassHasMatchThenReturnInnerClassUpdatedName() { + //given + final Map<String, String> renames = new HashMap<>(); + // the outer class has been renamed + final String originalOuterClass = createAName(); + final String updatedOuterClass = createAName(); + renames.put(originalOuterClass, updatedOuterClass); + // the inner class has an explicit rename to a different outer class + final String originalInnerClass = createAName(); + final String originalName = originalOuterClass + "$" + originalInnerClass; + final String updatedName = createAName() + "$" + createAName(); + renames.put(originalName, updatedName); + //when + final String result = Reflections.findMappedNameAndLog(renames, originalName); + //then + // the explicit rename overrides the outer class rename + assertThat(result).isEqualTo(updatedName); + } + + //wrap_blah_aws-java-sdk-bundle-1.11.245.jar\:* : wrap_blah_aws-java-sdk-bundle-1.11.411.jar\:* + @Test + public void allClassesInOneBundleAreNowInOtherBundle() { + //given + final Map<String, String> renames = new HashMap<>(); + final String wildcard = "*"; + final String originalBundle = "wrap_blah_aws-java-sdk-bundle-1.11.245.jar:"; + final String updatedBundle = "wrap_blah_aws-java-sdk-bundle-1.11.411.jar:"; + renames.put(originalBundle + wildcard, updatedBundle + wildcard); + final String className = createAName(); + final String originalName = originalBundle + className; + final String updatedName = updatedBundle + className; + //when + final String result = Reflections.findMappedNameAndLog(renames, originalName); + //then + assertThat(result).isSameAs(updatedName); + } + + private String createAName() { + return UUID.randomUUID().toString(); + } + +} diff --git a/utils/common/src/test/java/org/apache/brooklyn/util/javalang/ReflectionsTest.java b/utils/common/src/test/java/org/apache/brooklyn/util/javalang/ReflectionsTest.java index 06c5f47..a46f6ee 100644 --- a/utils/common/src/test/java/org/apache/brooklyn/util/javalang/ReflectionsTest.java +++ b/utils/common/src/test/java/org/apache/brooklyn/util/javalang/ReflectionsTest.java @@ -38,7 +38,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import com.google.common.collect.Sets; -public class ReflectionsTest implements WithAssertions { +public class ReflectionsTest { @Test public void testFindPublicMethodsOrderedBySuper() throws Exception { @@ -229,143 +229,6 @@ public class ReflectionsTest implements WithAssertions { Assert.assertEquals(Reflections.getAllInterfaces(C.class), ImmutableList.of(M.class, K.class, I.class, J.class, L.class)); } - /** - * Tests for {@link Reflections#findMappedNameAndLog(Map, String)} and - * {@link Reflections#findMappedNameMaybe(Map, String)} methods. - */ - public class FindMappedName { - - @Test - public void givenRenamesIsNullThenReturnOriginalName() { - //given - final Map<String, String> renames = null; - final String originalName = createAName(); - //when - final String result = Reflections.findMappedNameAndLog(renames, originalName); - //then - assertThat(result).isEqualTo(originalName); - } - - @Test - public void givenRenamesIsEmptyThenReturnOriginalName() { - //given - final Map<String, String> renames = new HashMap<>(); - final String originalName = createAName(); - //when - final String result = Reflections.findMappedNameAndLog(renames, originalName); - //then - assertThat(result).isEqualTo(originalName); - } - - @Test - public void givenRenamesHasNoMatchThenReturnOriginalName() { - //given - final Map<String, String> renames = new HashMap<>(); - renames.put(createAName(), createAName()); - final String originalName = createAName(); - //when - final String result = Reflections.findMappedNameAndLog(renames, originalName); - //then - assertThat(result).isEqualTo(originalName); - } - - @Test - public void givenRenamesHasMatchThenReturnUpdatedName() { - //given - final Map<String, String> renames = new HashMap<>(); - final String originalName = createAName(); - final String updatedName = createAName(); - renames.put(originalName, updatedName); - //when - final String result = Reflections.findMappedNameAndLog(renames, originalName); - //then - assertThat(result).isEqualTo(updatedName); - } - - @Test - public void givenInnerClassHasNoMatchThenReturnOriginalName() { - //given - final Map<String, String> renames = new HashMap<>(); - final String originalName = createAName() + "$" + createAName(); - //when - final String result = Reflections.findMappedNameAndLog(renames, originalName); - //then - assertThat(result).isEqualTo(originalName); - } - - @Test - public void givenInnerClassHasMatchThenReturnUpdatedName() { - //given - final Map<String, String> renames = new HashMap<>(); - final String originalName = createAName() + "$" + createAName(); - final String updatedName = createAName(); - renames.put(originalName, updatedName); - //when - final String result = Reflections.findMappedNameAndLog(renames, originalName); - //then - assertThat(result).isEqualTo(updatedName); - } - - @Test - public void givenInnerClassWhenOnlyOuterClassHasMatchThenReturnUpdatedName() { - //given - final Map<String, String> renames = new HashMap<>(); - final String originalOuterClass = createAName(); - final String originalInnerClass = createAName(); - final String originalName = originalOuterClass + "$" + originalInnerClass; - final String updatedOuterClass = createAName(); - final String updatedName = updatedOuterClass + "$" + originalInnerClass; - renames.put(originalOuterClass, updatedOuterClass); - //when - final String result = Reflections.findMappedNameAndLog(renames, originalName); - //then - assertThat(result).isEqualTo(updatedName); - } - - @Test - public void givenInnerClassWhenOuterAndInnerClassHasMatchThenReturnInnerClassUpdatedName() { - //given - final Map<String, String> renames = new HashMap<>(); - // the outer class has been renamed - final String originalOuterClass = createAName(); - final String updatedOuterClass = createAName(); - renames.put(originalOuterClass, updatedOuterClass); - // the inner class has an explicit rename to a different outer class - final String originalInnerClass = createAName(); - final String originalName = originalOuterClass + "$" + originalInnerClass; - final String updatedName = createAName() + "$" + createAName(); - renames.put(originalName, updatedName); - //when - final String result = Reflections.findMappedNameAndLog(renames, originalName); - //then - // the explicit rename overrides the outer class rename - assertThat(result).isEqualTo(updatedName); - } - - //wrap_blah_aws-java-sdk-bundle-1.11.245.jar\:* : wrap_blah_aws-java-sdk-bundle-1.11.411.jar\:* - @Test - public void allClassesInOneBundleAreNowInOtherBundle() { - //given - final Map<String, String> renames = new HashMap<>(); - final String wildcard = "*"; - final String originalBundle = "wrap_blah_aws-java-sdk-bundle-1.11.245.jar:"; - final String updatedBundle = "wrap_blah_aws-java-sdk-bundle-1.11.411.jar:"; - renames.put(originalBundle + wildcard, updatedBundle + wildcard); - final String className = createAName(); - final String originalName = originalBundle + className; - final String updatedName = updatedBundle + className; - //when - final String result = Reflections.findMappedNameAndLog(renames, originalName); - //then - assertThat(result).isSameAs(updatedName); - } - - private String createAName() { - return UUID.randomUUID().toString(); - } - - } - public static abstract class PublicSuperClass { public abstract void methodOnSuperClass(); }