From 4f66ef80245ac0f3aca35fb55d8f864788d11ecd Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Wed, 3 Apr 2019 02:20:41 -0700 Subject: [PATCH] Added tests for private methods. --- .../thauvin/erik/semver/VersionInfoTest.java | 129 ------------- .../erik/semver/VersionProcessorTest.java | 79 ++++++++ .../net/thauvin/erik/semver/VersionTest.java | 169 ++++++++++++++++++ test.properties | 9 + 4 files changed, 257 insertions(+), 129 deletions(-) create mode 100644 src/test/java/net/thauvin/erik/semver/VersionProcessorTest.java create mode 100644 src/test/java/net/thauvin/erik/semver/VersionTest.java create mode 100644 test.properties diff --git a/src/test/java/net/thauvin/erik/semver/VersionInfoTest.java b/src/test/java/net/thauvin/erik/semver/VersionInfoTest.java index 10cd936..470c122 100644 --- a/src/test/java/net/thauvin/erik/semver/VersionInfoTest.java +++ b/src/test/java/net/thauvin/erik/semver/VersionInfoTest.java @@ -34,7 +34,6 @@ package net.thauvin.erik.semver; import org.testng.Assert; import org.testng.annotations.Test; -import java.lang.annotation.Annotation; import java.util.Calendar; /** @@ -194,131 +193,3 @@ public class VersionInfoTest { Assert.assertEquals(versionInfo.getClassName(), version.className(), "getClassName(className)"); } } - -@SuppressWarnings({"ClassExplicitlyAnnotation", "BadAnnotationImplementation"}) -class VersionTest implements Version { - @Override - public Class annotationType() { - return null; - } - - @Override - public String buildMeta() { - return "007"; - } - - @Override - public String buildMetaKey() { - return "build.meta"; - } - - @Override - public String buildMetaPrefix() { - return "+"; - } - - @Override - public String buildMetaPrefixKey() { - return "build.meta.prefix"; - } - - @Override - public String className() { - return "MyTest"; - } - - @Override - public String keysPrefix() { - return "product."; - } - - @Override - public int major() { - return 2; - } - - @Override - public String majorKey() { - return "build.major"; - } - - @Override - public int minor() { - return 17; - } - - @Override - public String minorKey() { - return "build.minor"; - } - - @Override - public String packageName() { - return "com.foo.example"; - } - - @Override - public int patch() { - return 52; - } - - @Override - public String patchKey() { - return "build.patch"; - } - - @Override - public String preRelease() { - return "beta"; - } - - @Override - public String preReleaseKey() { - return "build.prerelease"; - } - - @Override - public String preReleasePrefix() { - return "-"; - } - - @Override - public String preReleasePrefixKey() { - return "build.prerelase.prefix"; - } - - @Override - public String project() { - return "My Test Project"; - } - - @Override - public String projectKey() { - return "build.project"; - } - - @Override - public String properties() { - return "test.properties"; - } - - @Override - public String separator() { - return "."; - } - - @Override - public String separatorKey() { - return "build.separator"; - } - - @Override - public String template() { - return "myversion.mustache"; - } - - @Override - public String type() { - return "kt"; - } -} diff --git a/src/test/java/net/thauvin/erik/semver/VersionProcessorTest.java b/src/test/java/net/thauvin/erik/semver/VersionProcessorTest.java new file mode 100644 index 0000000..93918d6 --- /dev/null +++ b/src/test/java/net/thauvin/erik/semver/VersionProcessorTest.java @@ -0,0 +1,79 @@ +/* + * VersionProcessorTest.java + * + * Copyright (c) 2016-2019, Erik C. Thauvin (erik@thauvin.net) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * Neither the name of this project nor the names of its contributors may be + * used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.thauvin.erik.semver; + +import org.testng.Assert; +import org.testng.annotations.Test; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.Properties; + +/** + * The VersionProcessorTest class. + * + * @author Erik C. Thauvin + * @created 2019-04-02 + * @since 1.2.0 + */ +public class VersionProcessorTest { + private final VersionProcessor processor = new VersionProcessor(); + private final Version version = new VersionTest(); + + @Test + public void testFindValues() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { + final Method method = processor.getClass().getDeclaredMethod("findValues", Version.class); + method.setAccessible(true); + final VersionInfo versionInfo = (VersionInfo) method.invoke(processor, version); + + Assert.assertEquals(versionInfo.getVersion(), "0-0-7:vodka++martini", "getVersion(0-0-7:vodka++martin)"); + Assert.assertEquals(versionInfo.getProject(), "James Bond", "getProject(James Bond)"); + } + + @Test + public void testParseIntProperty() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { + final Properties p = new Properties(); + p.setProperty("1", "1"); + p.setProperty("2", "2.1"); + p.setProperty("3", "zero"); + p.setProperty("4", " 4 "); + + final Method method = processor.getClass().getDeclaredMethod( + "parseIntProperty", Properties.class, String.class, int.class); + method.setAccessible(true); + + Assert.assertEquals(method.invoke(processor, p, "1", -1), 1, "parseIntProperty(1)"); + Assert.assertEquals(method.invoke(processor, p, "2", -1), -1, "parseIntProperty(2.1)"); + Assert.assertEquals(method.invoke(processor, p, "3", -1), -1, "parseIntProperty(zero)"); + Assert.assertEquals(method.invoke(processor, p, "4", -1), 4, "parseIntProperty( 4 )"); + } +} diff --git a/src/test/java/net/thauvin/erik/semver/VersionTest.java b/src/test/java/net/thauvin/erik/semver/VersionTest.java new file mode 100644 index 0000000..0d91ac2 --- /dev/null +++ b/src/test/java/net/thauvin/erik/semver/VersionTest.java @@ -0,0 +1,169 @@ +/* + * VersionTest.java + * + * Copyright (c) 2016-2019, Erik C. Thauvin (erik@thauvin.net) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * Neither the name of this project nor the names of its contributors may be + * used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.thauvin.erik.semver; + +import java.lang.annotation.Annotation; + +/** + * The VersionTest class. + * + * @author Erik C. Thauvin + * @created 2019-04-02 + * @since 1.2.0 + */ +@SuppressWarnings({"ClassExplicitlyAnnotation"}) +class VersionTest implements Version { + @Override + public Class annotationType() { + return null; + } + + @Override + public String buildMeta() { + return "007"; + } + + @Override + public String buildMetaKey() { + return "meta"; + } + + @Override + public String buildMetaPrefix() { + return "+"; + } + + @Override + public String buildMetaPrefixKey() { + return "meta.prefix"; + } + + @Override + public String className() { + return "MyTest"; + } + + @Override + public String keysPrefix() { + return "build."; + } + + @Override + public int major() { + return 2; + } + + @Override + public String majorKey() { + return "major"; + } + + @Override + public int minor() { + return 17; + } + + @Override + public String minorKey() { + return "minor"; + } + + @Override + public String packageName() { + return "com.foo.example"; + } + + @Override + public int patch() { + return 52; + } + + @Override + public String patchKey() { + return "patch"; + } + + @Override + public String preRelease() { + return "beta"; + } + + @Override + public String preReleaseKey() { + return "prerelease"; + } + + @Override + public String preReleasePrefix() { + return "-"; + } + + @Override + public String preReleasePrefixKey() { + return "prerelease.prefix"; + } + + @Override + public String project() { + return "My Test Project"; + } + + @Override + public String projectKey() { + return "project"; + } + + @Override + public String properties() { + return "test.properties"; + } + + @Override + public String separator() { + return "."; + } + + @Override + public String separatorKey() { + return "separator"; + } + + @Override + public String template() { + return "myversion.mustache"; + } + + @Override + public String type() { + return "kt"; + } +} diff --git a/test.properties b/test.properties new file mode 100644 index 0000000..98cab4c --- /dev/null +++ b/test.properties @@ -0,0 +1,9 @@ +build.major=0 +build.minor=0 +build.patch=7 +build.prerelease=vodka +build.prerelease.prefix=: +build.meta=martini +build.meta.prefix=++ +build.separator=- +build.project=James Bond