Skip to content

Commit

Permalink
Move Versions to org.verapdf.version (#1281)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximPlusov authored Sep 14, 2022
1 parent 5135e13 commit 2eb8d16
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
*
*/
package org.verapdf;
package org.verapdf.version;

/**
* Simple interface for a <a href="http://semver.org/">semantic version
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
*
*/
package org.verapdf;
package org.verapdf.version;

/**
* @author <a href="mailto:[email protected]">Carl Wilson</a>
Expand Down
54 changes: 54 additions & 0 deletions core/src/main/java/org/verapdf/version/Versions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
*
*/
package org.verapdf.version;

/**
* @author <a href="mailto:[email protected]">Carl Wilson</a>
* <a href="https://github.com/carlwilson">carlwilson AT github</a>
*
* @version 0.1
*
* Created 26 May 2017:01:48:14
*/

public final class Versions {
public static final String PDFBOX_BUILD_INFO = "PDFBOX"; //$NON-NLS-1$
private static final String pdfBoxBuildInfo = "-" + PDFBOX_BUILD_INFO; //$NON-NLS-1$
private static final String snapshotBuildInfo = "-SNAPSHOT"; //$NON-NLS-1$
private static final String versionPrefix = "v"; //$NON-NLS-1$

/**
*
*/
private Versions() {
throw new AssertionError("Should never be here"); //$NON-NLS-1$
}

public static SemanticVersionNumber fromString(final String versionString) {
if (versionString == null)
throw new IllegalArgumentException("Argument versionString can not be null"); //$NON-NLS-1$
if (versionString.isEmpty())
throw new IllegalArgumentException("Argument versionString can not be empty"); //$NON-NLS-1$
String strippedVersion = (versionString.endsWith(pdfBoxBuildInfo)) ? versionString.replace(pdfBoxBuildInfo, "") //$NON-NLS-1$
: versionString;
strippedVersion = (strippedVersion.endsWith(snapshotBuildInfo)) ? strippedVersion.replace(snapshotBuildInfo, "") //$NON-NLS-1$
: strippedVersion;
strippedVersion = strippedVersion.startsWith(versionPrefix) ? strippedVersion.replaceFirst(versionPrefix, "") //$NON-NLS-1$
: strippedVersion;
return VersionNumberImpl.fromString(strippedVersion);
}

public static SemanticVersionNumber fromStrings(final String[] parts) {
return VersionNumberImpl.fromStrings(parts);
}

public static SemanticVersionNumber fromInts(final int[] parts) {
return VersionNumberImpl.fromInts(parts);
}

public static SemanticVersionNumber fromInts(final int major, final int minor, final int revision) {
return VersionNumberImpl.fromInts(major, minor, revision);
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
*
*/
package org.verapdf;
package org.verapdf.version;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
Expand All @@ -20,6 +20,7 @@
* Created 25 May 2017:22:31:17
*/

//Move Versions to org.verapdf.version
@SuppressWarnings("static-method")
public class SemanticVersionTest {
private static final String v1_0_0 = "1.0.0"; //$NON-NLS-1$
Expand All @@ -30,15 +31,15 @@ public class SemanticVersionTest {
private static final String v1_0_0pdf = "1.0.0-PDFBOX"; //$NON-NLS-1$
private static final String v1_0_0snap = "1.0.0-SNAPSHOT"; //$NON-NLS-1$
/**
* Test method for {@link org.verapdf.VersionNumberImpl#hashCode()}.
* Test method for {@link VersionNumberImpl#hashCode()}.
*/
@Test
public final void testHashCodeAndEquals() {
EqualsVerifier.forClass(VersionNumberImpl.class).verify();
}

/**
* Test method for {@link org.verapdf.VersionNumberImpl#fromString(java.lang.String)}.
* Test method for {@link VersionNumberImpl#fromString(java.lang.String)}.
*/
@Test
public final void testVersionNumberFromString() {
Expand All @@ -48,7 +49,7 @@ public final void testVersionNumberFromString() {
}

/**
* Test method for {@link org.verapdf.VersionNumberImpl#fromString(java.lang.String)}.
* Test method for {@link VersionNumberImpl#fromString(java.lang.String)}.
*/
@Test(expected=IllegalArgumentException.class)
public final void testVersionNumberFromNullString() {
Expand All @@ -57,15 +58,15 @@ public final void testVersionNumberFromNullString() {


/**
* Test method for {@link org.verapdf.VersionNumberImpl#fromString(java.lang.String)}.
* Test method for {@link VersionNumberImpl#fromString(java.lang.String)}.
*/
@Test(expected=IllegalArgumentException.class)
public final void testVersionNumberFromEmptyString() {
VersionNumberImpl.fromString(""); //$NON-NLS-1$
}

/**
* Test method for {@link org.verapdf.VersionNumberImpl#fromStrings(java.lang.String[])}.
* Test method for {@link VersionNumberImpl#fromStrings(java.lang.String[])}.
*/
@Test
public final void testVersionNumberImplStringArray() {
Expand All @@ -75,15 +76,15 @@ public final void testVersionNumberImplStringArray() {
}

/**
* Test method for {@link org.verapdf.VersionNumberImpl#fromStrings(java.lang.String[])}.
* Test method for {@link VersionNumberImpl#fromStrings(java.lang.String[])}.
*/
@Test(expected=IllegalArgumentException.class)
public final void testVersionNumberImplStringArrayNull() {
VersionNumberImpl.fromStrings(null);
}

/**
* Test method for {@link org.verapdf.VersionNumberImpl#fromStrings(java.lang.String[])}.
* Test method for {@link VersionNumberImpl#fromStrings(java.lang.String[])}.
*/
@Test(expected=IllegalArgumentException.class)
public final void testVersionNumberImplStringArrayBad() {
Expand All @@ -92,7 +93,7 @@ public final void testVersionNumberImplStringArrayBad() {
}

/**
* Test method for {@link org.verapdf.VersionNumberImpl#fromInts(int[])}.
* Test method for {@link VersionNumberImpl#fromInts(int[])}.
*/
@Test
public final void testVersionNumberImplIntArray() {
Expand All @@ -102,31 +103,31 @@ public final void testVersionNumberImplIntArray() {
}

/**
* Test method for {@link org.verapdf.VersionNumberImpl#fromInts(int[])}.
* Test method for {@link VersionNumberImpl#fromInts(int[])}.
*/
@Test(expected=IllegalArgumentException.class)
public final void testVersionNumberImplIntArrayNull() {
VersionNumberImpl.fromInts(null);
}

/**
* Test method for {@link org.verapdf.VersionNumberImpl#fromInts(int[])}.
* Test method for {@link VersionNumberImpl#fromInts(int[])}.
*/
@Test(expected=IllegalArgumentException.class)
public final void testVersionNumberImplIntArrayShort() {
VersionNumberImpl.fromInts(v1_0_0_shortints);
}

/**
* Test method for {@link org.verapdf.VersionNumberImpl#fromInts(int[])}.
* Test method for {@link VersionNumberImpl#fromInts(int[])}.
*/
@Test(expected=IllegalArgumentException.class)
public final void testVersionNumberImplIntArrayLong() {
VersionNumberImpl.fromInts(v1_0_0_longints);
}

/**
* Test method for {@link org.verapdf.VersionNumberImpl#VersionNumberImpl(int, int, int)}.
* Test method for {@link VersionNumberImpl#VersionNumberImpl(int, int, int)}.
*/
@Test
public final void testVersionNumberImplIntIntInt() {
Expand All @@ -136,31 +137,31 @@ public final void testVersionNumberImplIntIntInt() {
}

/**
* Test method for {@link org.verapdf.VersionNumberImpl#VersionNumberImpl(int, int, int)}.
* Test method for {@link VersionNumberImpl#VersionNumberImpl(int, int, int)}.
*/
@Test(expected=IllegalArgumentException.class)
public final void testVersionNumberImplIntIntIntMinusMajor() {
VersionNumberImpl.fromInts(-1, 0, 0);
}

/**
* Test method for {@link org.verapdf.VersionNumberImpl#VersionNumberImpl(int, int, int)}.
* Test method for {@link VersionNumberImpl#VersionNumberImpl(int, int, int)}.
*/
@Test(expected=IllegalArgumentException.class)
public final void testVersionNumberImplIntIntIntMinusMinor() {
VersionNumberImpl.fromInts(1, -1, 0);
}

/**
* Test method for {@link org.verapdf.VersionNumberImpl#VersionNumberImpl(int, int, int)}.
* Test method for {@link VersionNumberImpl#VersionNumberImpl(int, int, int)}.
*/
@Test(expected=IllegalArgumentException.class)
public final void testVersionNumberImplIntIntIntMinusRev() {
VersionNumberImpl.fromInts(1, 0, -1);
}

/**
* Test method for {@link org.verapdf.VersionNumberImpl#getVersionString()}.
* Test method for {@link VersionNumberImpl#getVersionString()}.
*/
@Test
public final void testGetVersionString() {
Expand All @@ -173,7 +174,7 @@ public final void testGetVersionString() {
}

/**
* Test method for {@link org.verapdf.VersionNumberImpl#compareTo(org.verapdf.VersionNumberImpl)}.
* Test method for {@link VersionNumberImpl#compareTo(VersionNumberImpl)}.
*/
@Test
public final void testCompareTo() {
Expand Down

0 comments on commit 2eb8d16

Please sign in to comment.