Added tests for private methods.
This commit is contained in:
parent
f4169e56ed
commit
4f66ef8024
4 changed files with 257 additions and 129 deletions
|
@ -34,7 +34,6 @@ package net.thauvin.erik.semver;
|
||||||
import org.testng.Assert;
|
import org.testng.Assert;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import java.lang.annotation.Annotation;
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -194,131 +193,3 @@ public class VersionInfoTest {
|
||||||
Assert.assertEquals(versionInfo.getClassName(), version.className(), "getClassName(className)");
|
Assert.assertEquals(versionInfo.getClassName(), version.className(), "getClassName(className)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({"ClassExplicitlyAnnotation", "BadAnnotationImplementation"})
|
|
||||||
class VersionTest implements Version {
|
|
||||||
@Override
|
|
||||||
public Class<? extends Annotation> 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";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -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 <code>VersionProcessorTest</code> class.
|
||||||
|
*
|
||||||
|
* @author <a href="https://erik.thauvin.net/" target="_blank">Erik C. Thauvin</a>
|
||||||
|
* @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 )");
|
||||||
|
}
|
||||||
|
}
|
169
src/test/java/net/thauvin/erik/semver/VersionTest.java
Normal file
169
src/test/java/net/thauvin/erik/semver/VersionTest.java
Normal file
|
@ -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 <code>VersionTest</code> class.
|
||||||
|
*
|
||||||
|
* @author <a href="https://erik.thauvin.net/" target="_blank">Erik C. Thauvin</a>
|
||||||
|
* @created 2019-04-02
|
||||||
|
* @since 1.2.0
|
||||||
|
*/
|
||||||
|
@SuppressWarnings({"ClassExplicitlyAnnotation"})
|
||||||
|
class VersionTest implements Version {
|
||||||
|
@Override
|
||||||
|
public Class<? extends Annotation> 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";
|
||||||
|
}
|
||||||
|
}
|
9
test.properties
Normal file
9
test.properties
Normal file
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue