diff --git a/pom.xml b/pom.xml
index af9f04e..c023498 100644
--- a/pom.xml
+++ b/pom.xml
@@ -74,11 +74,25 @@ JUG supports 3 original official UUID generation methods as well as later additi
runtime
true
-
+
- junit
- junit
- ${version.junit}
+ org.junit.jupiter
+ junit-jupiter
+ ${version.junit5}
+ test
+
+
+
+ org.junit.jupiter
+ junit-jupiter-params
+ ${version.junit5}
+ test
+
+
+
+ org.hamcrest
+ hamcrest
+ 2.2
test
@@ -184,6 +198,12 @@ https://stackoverflow.com/questions/37958104/maven-javadoc-no-source-files-for-p
org.jacoco
jacoco-maven-plugin
+
+
+ perf/**
+ test/**
+
+
diff --git a/release-notes/VERSION b/release-notes/VERSION
index c3e3933..701c58a 100644
--- a/release-notes/VERSION
+++ b/release-notes/VERSION
@@ -8,6 +8,7 @@ Releases
#124: TimeBasedEpochGenerator should prevent overflow
(Chad P)
+#139: Upgrade tests from JUnit 4 to JUnit 5
- Update to `oss-parent` v69
5.1.1 (26-Sep-2025)
diff --git a/src/main/java/com/fasterxml/uuid/ext/LockedFile.java b/src/main/java/com/fasterxml/uuid/ext/LockedFile.java
index da1cb39..e75a4d8 100644
--- a/src/main/java/com/fasterxml/uuid/ext/LockedFile.java
+++ b/src/main/java/com/fasterxml/uuid/ext/LockedFile.java
@@ -39,8 +39,10 @@
*/
class LockedFile
{
+ private static final Logger LOGGER = LoggerFactory.getLogger(LockedFile.class);
- private static final Logger logger = LoggerFactory.getLogger(LockedFile.class);
+ // Wrapper just to allow test(s) to disable/re-route
+ static LoggerWrapper logger = new LoggerWrapper(LOGGER);
/**
* Expected file length comes from hex-timestamp (16 digits),
@@ -115,6 +117,11 @@ class LockedFile
mLock = lock;
}
+ // @since 5.2 for testing (for `LockedFileTest`)
+ static void logging(boolean enabled) {
+ logger = new LoggerWrapper(enabled ? LOGGER : null);
+ }
+
public void deactivate()
{
RandomAccessFile raf = mRAFile;
@@ -131,7 +138,7 @@ public long readStamp()
try {
size = (int) mChannel.size();
} catch (IOException ioe) {
- logger.error("Failed to read file size", ioe);
+ logger.error(ioe, "Failed to read file size");
return READ_ERROR;
}
@@ -151,7 +158,7 @@ public long readStamp()
try {
mRAFile.readFully(data);
} catch (IOException ie) {
- logger.error("(file '{}') Failed to read {} bytes", mFile, size, ie);
+ logger.error(ie, "(file '"+mFile+"') Failed to read "+size+" bytes");
return READ_ERROR;
}
@@ -168,25 +175,25 @@ public long readStamp()
dataStr = dataStr.trim();
long result = -1;
- String err = null;
+ String errMsg = null;
if (!dataStr.startsWith("[0")
|| dataStr.length() < 3
|| Character.toLowerCase(dataStr.charAt(2)) != 'x') {
- err = "does not start with '[0x' prefix";
+ errMsg = "does not start with '[0x' prefix";
} else {
int ix = dataStr.indexOf(']', 3);
if (ix <= 0) {
- err = "does not end with ']' marker";
+ errMsg = "does not end with ']' marker";
} else {
String hex = dataStr.substring(3, ix);
if (hex.length() > 16) {
- err = "length of the (hex) timestamp too long; expected 16, had "+hex.length()+" ('"+hex+"')";
+ errMsg = "length of the (hex) timestamp too long; expected 16, had "+hex.length()+" ('"+hex+"')";
} else {
try {
result = Long.parseLong(hex, 16);
} catch (NumberFormatException nex) {
- err = "does not contain a valid hex timestamp; got '"
+ errMsg = "does not contain a valid hex timestamp; got '"
+hex+"' (parse error: "+nex+")";
}
}
@@ -195,7 +202,7 @@ public long readStamp()
// Unsuccesful?
if (result < 0L) {
- logger.error("(file '{}') Malformed timestamp file contents: {}", mFile, err);
+ logger.error("(file '{}') Malformed timestamp file contents: {}", mFile, errMsg);
return READ_ERROR;
}
@@ -210,12 +217,11 @@ public void writeStamp(long stamp)
{
// Let's do sanity check first:
if (stamp <= mLastTimestamp) {
- /* same stamp is not dangerous, but pointless... so warning,
- * not an error:
- */
+ // same stamp is not dangerous, but pointless... so warning,
+ // not an error:
if (stamp == mLastTimestamp) {
logger.warn("(file '{}') Trying to re-write existing timestamp ({})", mFile, stamp);
- return;
+ return;
}
throw new IOException(""+mFile+" trying to overwrite existing value ("+mLastTimestamp+") with an earlier timestamp ("+stamp+")");
}
@@ -260,20 +266,58 @@ public void writeStamp(long stamp)
*/
protected static void doDeactivate(File f, RandomAccessFile raf,
- FileLock lock)
+ FileLock lock)
{
if (lock != null) {
try {
lock.release();
} catch (Throwable t) {
- logger.error("Failed to release lock (for file '{}')", f, t);
+ logger.error(t, "Failed to release lock (for file '"+f+"')");
}
}
if (raf != null) {
try {
raf.close();
} catch (Throwable t) {
- logger.error("Failed to close file '{}'", f, t);
+ logger.error(t, "Failed to close file '{"+f+"}'");
+ }
+ }
+ }
+
+ /*
+ //////////////////////////////////////////////////////////////
+ // Helper class(es)
+ //////////////////////////////////////////////////////////////
+ */
+
+ private static class LoggerWrapper {
+ private final Logger logger;
+
+ public LoggerWrapper(Logger l) {
+ logger = l;
+ }
+
+ public void error(Throwable t, String msg) {
+ if (logger != null) {
+ logger.error(msg, t);
+ }
+ }
+
+ public void error(String msg, Object arg1, Object arg2) {
+ if (logger != null) {
+ logger.error(msg, arg1, arg2);
+ }
+ }
+
+ public void warn(String msg) {
+ if (logger != null) {
+ logger.warn(msg);
+ }
+ }
+
+ public void warn(String msg, Object arg1, Object arg2) {
+ if (logger != null) {
+ logger.warn(msg, arg1, arg2);
}
}
}
diff --git a/src/test/java/com/fasterxml/uuid/EgressInterfaceFinderTest.java b/src/test/java/com/fasterxml/uuid/EgressInterfaceFinderTest.java
index 4b6eb77..04da277 100644
--- a/src/test/java/com/fasterxml/uuid/EgressInterfaceFinderTest.java
+++ b/src/test/java/com/fasterxml/uuid/EgressInterfaceFinderTest.java
@@ -2,7 +2,7 @@
import com.fasterxml.uuid.EgressInterfaceFinder.EgressResolutionException;
import com.fasterxml.uuid.EgressInterfaceFinder.Finder;
-import junit.framework.TestCase;
+import org.junit.jupiter.api.Test;
import java.net.InetAddress;
import java.net.InetSocketAddress;
@@ -10,11 +10,13 @@
import java.net.UnknownHostException;
import static com.fasterxml.uuid.EgressInterfaceFinder.DEFAULT_TIMEOUT_MILLIS;
+import static org.junit.jupiter.api.Assertions.*;
-public class EgressInterfaceFinderTest extends TestCase {
+public class EgressInterfaceFinderTest {
private final EgressInterfaceFinder finder = new EgressInterfaceFinder();
+ @Test
public void testUnspecifiedIPv4LocalAddress() throws UnknownHostException {
EgressResolutionException ex = null;
try {
@@ -22,15 +24,15 @@ public void testUnspecifiedIPv4LocalAddress() throws UnknownHostException {
} catch (EgressResolutionException e) {
ex = e;
}
- assertNotNull("EgressResolutionException was not thrown", ex);
+ assertNotNull(ex, "EgressResolutionException was not thrown");
String message = ex.getMessage();
- assertTrue(String.format(
+ assertTrue(message.startsWith("local address"), String.format(
"message [%s] does not begin with \"local address\"",
- message),
- message.startsWith("local address"));
+ message));
assertEquals(1, ex.getMessages().size());
}
+ @Test
public void testUnspecifiedIPv6LocalAddress() throws Exception {
EgressResolutionException ex = null;
try {
@@ -38,15 +40,15 @@ public void testUnspecifiedIPv6LocalAddress() throws Exception {
} catch (EgressResolutionException e) {
ex = e;
}
- assertNotNull("EgressResolutionException was not thrown", ex);
+ assertNotNull(ex, "EgressResolutionException was not thrown");
String message = ex.getMessage();
- assertTrue(String.format(
+ assertTrue(message.startsWith("local address"), String.format(
"message [%s] does not begin with \"local address\"",
- message),
- message.startsWith("local address"));
+ message));
assertEquals(1, ex.getMessages().size());
}
+ @Test
public void testFromLocalAddress() throws Exception {
NetworkInterface anInterface =
NetworkInterface.getNetworkInterfaces().nextElement();
@@ -54,6 +56,7 @@ public void testFromLocalAddress() throws Exception {
assertEquals(anInterface, finder.fromLocalAddress(anAddress));
}
+ @Test
public void testFromIncorrectLocalAddress() throws Exception {
EgressResolutionException ex = null;
try {
@@ -62,15 +65,15 @@ public void testFromIncorrectLocalAddress() throws Exception {
} catch (EgressResolutionException e) {
ex = e;
}
- assertNotNull("EgressResolutionException was not thrown", ex);
+ assertNotNull(ex, "EgressResolutionException was not thrown");
String message = ex.getMessage();
- assertTrue(String.format(
+ assertTrue(message.startsWith("no interface found"), String.format(
"message [%s] does not begin with \"no interface found\"",
- message),
- message.startsWith("no interface found"));
+ message));
assertEquals(1, ex.getMessages().size());
}
+ @Test
public void testFromRemoteDatagramSocketConnection() throws Exception {
if (!System.getProperty("os.name").startsWith("Mac")) {
String name = EgressInterfaceFinder.randomRootServerName();
@@ -79,22 +82,26 @@ public void testFromRemoteDatagramSocketConnection() throws Exception {
}
}
+ @Test
public void testFromRemoteSocketConnection() throws Exception {
String name = EgressInterfaceFinder.randomRootServerName();
InetSocketAddress address = new InetSocketAddress(name, 53);
finder.fromRemoteSocketConnection(DEFAULT_TIMEOUT_MILLIS, address);
}
+ @Test
public void testFromRemoteConnection() throws Exception {
String name = EgressInterfaceFinder.randomRootServerName();
InetSocketAddress address = new InetSocketAddress(name, 53);
finder.fromRemoteConnection(DEFAULT_TIMEOUT_MILLIS, address);
}
+ @Test
public void testFromRootNameServerConnection() throws Exception {
finder.fromRootNameserverConnection(DEFAULT_TIMEOUT_MILLIS);
}
+ @Test
public void testAggregateExceptions() {
EgressResolutionException ex = null;
final int[] counter = {0};
@@ -112,10 +119,11 @@ public NetworkInterface egressInterface()
} catch (EgressResolutionException e) {
ex = e;
}
- assertNotNull("EgressResolutionException was not thrown", ex);
+ assertNotNull(ex, "EgressResolutionException was not thrown");
assertEquals(9, ex.getMessages().size());
}
+ @Test
public void testDefaultMechanisms() throws Exception {
try {
finder.egressInterface();
diff --git a/src/test/java/com/fasterxml/uuid/EthernetAddressTest.java b/src/test/java/com/fasterxml/uuid/EthernetAddressTest.java
index 1695b32..f3b4629 100644
--- a/src/test/java/com/fasterxml/uuid/EthernetAddressTest.java
+++ b/src/test/java/com/fasterxml/uuid/EthernetAddressTest.java
@@ -17,12 +17,11 @@
package com.fasterxml.uuid;
+import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.*;
+
import com.fasterxml.uuid.impl.TimeBasedGenerator;
import java.net.InetSocketAddress;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-import junit.textui.TestRunner;
import java.util.Arrays;
import java.util.Random;
@@ -33,7 +32,7 @@
* @author Eric Bie
* @author Tatu Saloranta (changes for version 3.0)
*/
-public class EthernetAddressTest extends TestCase
+public class EthernetAddressTest
{
// constant defining the length of a valid ethernet address byte array
private static final int ETHERNET_ADDRESS_ARRAY_LENGTH = 6;
@@ -167,22 +166,6 @@ public class EthernetAddressTest extends TestCase
new EthernetAddress(0x0000cf74d8ef49b8L);
- public EthernetAddressTest(java.lang.String testName)
- {
- super(testName);
- }
-
- public static Test suite()
- {
- TestSuite suite = new TestSuite(EthernetAddressTest.class);
- return suite;
- }
-
- public static void main(String[] args)
- {
- TestRunner.run(suite());
- }
-
/**************************************************************************
* Begin Constructor tests
*************************************************************************/
@@ -190,6 +173,8 @@ public static void main(String[] args)
* Test of EthernetAddress(byte[]) constructor,
* of class com.fasterxml.uuid.EthernetAddress.
*/
+ @Test
+
public void testByteArrayEthernetAddressConstructor()
{
// lets test some error cases
@@ -245,47 +230,39 @@ public void testByteArrayEthernetAddressConstructor()
// gives us a null EthernetAddress (definition of null EthernetAddress)
EthernetAddress ethernet_address =
new EthernetAddress(new byte[ETHERNET_ADDRESS_ARRAY_LENGTH]);
- assertEquals(
- "EthernetAddress(byte[]) did not create expected EthernetAddress",
- NULL_ETHERNET_ADDRESS_LONG,
- ethernet_address.toLong());
+ assertEquals(NULL_ETHERNET_ADDRESS_LONG, ethernet_address.toLong(), "EthernetAddress(byte[]) did not create expected EthernetAddress");
// let's test creating an array from a good byte array
ethernet_address =
new EthernetAddress(VALID_ETHERNET_ADDRESS_BYTE_ARRAY);
- assertEquals(
- "EthernetAddress(byte[]) did not create expected EthernetAddress",
- VALID_ETHERNET_ADDRESS_LONG,
- ethernet_address.toLong());
+ assertEquals(VALID_ETHERNET_ADDRESS_LONG, ethernet_address.toLong(), "EthernetAddress(byte[]) did not create expected EthernetAddress");
}
/**
* Test of EthernetAddress(long) constructor,
* of class com.fasterxml.uuid.EthernetAddress.
*/
+ @Test
+
public void testLongEthernetAddressConstructor()
{
// let's test that creating a EthernetAddress from an zero long
// gives us a null EthernetAddress (definition of null EthernetAddress)
EthernetAddress ethernet_address =
new EthernetAddress(0x0000000000000000L);
- assertEquals(
- "EthernetAddress(long) did not create expected EthernetAddress",
- NULL_ETHERNET_ADDRESS_LONG,
- ethernet_address.toLong());
+ assertEquals(NULL_ETHERNET_ADDRESS_LONG, ethernet_address.toLong(), "EthernetAddress(long) did not create expected EthernetAddress");
// let's test creating an array from a good long
ethernet_address = new EthernetAddress(VALID_ETHERNET_ADDRESS_LONG);
- assertEquals(
- "EthernetAddress(long) did not create expected EthernetAddress",
- VALID_ETHERNET_ADDRESS_LONG,
- ethernet_address.toLong());
+ assertEquals(VALID_ETHERNET_ADDRESS_LONG, ethernet_address.toLong(), "EthernetAddress(long) did not create expected EthernetAddress");
}
/**
* Test of EthernetAddress(String) constructor,
* of class com.fasterxml.uuid.EthernetAddress.
*/
+ @Test
+
public void testStringEthernetAddressConstructor()
{
// test a null string case
@@ -408,6 +385,8 @@ public void testStringEthernetAddressConstructor()
/**
* Test of asByteArray method, of class com.fasterxml.uuid.EthernetAddress.
*/
+ @Test
+
public void testAsByteArray()
{
// we'll test making a couple EthernetAddresses and then check that
@@ -415,18 +394,14 @@ public void testAsByteArray()
// first we'll test the null EthernetAddress
EthernetAddress ethernet_address = new EthernetAddress(0L);
- assertEquals("Expected length of returned array wrong",
- ETHERNET_ADDRESS_ARRAY_LENGTH,
- ethernet_address.asByteArray().length);
+ assertEquals(ETHERNET_ADDRESS_ARRAY_LENGTH, ethernet_address.asByteArray().length, "Expected length of returned array wrong");
assertEthernetAddressArraysAreEqual(
NULL_ETHERNET_ADDRESS_BYTE_ARRAY, 0,
ethernet_address.asByteArray(), 0);
// now test a non-null EthernetAddress
ethernet_address = new EthernetAddress(VALID_ETHERNET_ADDRESS_LONG);
- assertEquals("Expected length of returned array wrong",
- ETHERNET_ADDRESS_ARRAY_LENGTH,
- ethernet_address.asByteArray().length);
+ assertEquals(ETHERNET_ADDRESS_ARRAY_LENGTH, ethernet_address.asByteArray().length, "Expected length of returned array wrong");
assertEthernetAddressArraysAreEqual(
VALID_ETHERNET_ADDRESS_BYTE_ARRAY, 0,
ethernet_address.asByteArray(), 0);
@@ -452,6 +427,8 @@ public void testAsByteArray()
/**
* Test of clone method, of class com.fasterxml.uuid.EthernetAddress.
*/
+ @Test
+
public void testClone()
{
// as lifted from the JDK Object JavaDoc for clone:
@@ -470,17 +447,16 @@ public void testClone()
// ARE true in the case of EthernetAddress clone() because it is
// the desired behavior.
EthernetAddress x = new EthernetAddress(VALID_ETHERNET_ADDRESS_STRING);
- assertTrue("x.clone() != x did not return true",
- x.clone() != x);
- assertTrue("x.clone().getClass() == x.getClass() did not return true",
- x.clone().getClass() == x.getClass());
- assertTrue("x.clone().equals(x) did not return true",
- x.clone().equals(x));
+ assertTrue(x.clone() != x, "x.clone() != x did not return true");
+ assertTrue(x.clone().getClass() == x.getClass(), "x.clone().getClass() == x.getClass() did not return true");
+ assertTrue(x.clone().equals(x), "x.clone().equals(x) did not return true");
}
/**
* Test of compareTo method, of class com.fasterxml.uuid.EthernetAddress.
*/
+ @Test
+
public void testCompareTo()
{
// first, let's make sure calling compareTo with null
@@ -594,71 +570,57 @@ public void testCompareTo()
/**
* Test of equals method, of class com.fasterxml.uuid.EthernetAddress.
*/
+ @Test
+
public void testEquals()
{
// test passing null to equals returns false
// (as specified in the JDK docs for Object)
EthernetAddress x =
new EthernetAddress(VALID_ETHERNET_ADDRESS_BYTE_ARRAY);
- assertFalse("equals(null) didn't return false",
- x.equals((Object)null));
+ assertFalse(x.equals((Object)null), "equals(null) didn't return false");
// test passing an object which is not a EthernetAddress returns false
- assertFalse("x.equals(non_EthernetAddress_object) didn't return false",
- x.equals(new Object()));
+ assertFalse(x.equals(new Object()), "x.equals(non_EthernetAddress_object) didn't return false");
// test a case where two EthernetAddresss are definitly not equal
EthernetAddress w =
new EthernetAddress(ANOTHER_VALID_ETHERNET_ADDRESS_BYTE_ARRAY);
- assertFalse("x == w didn't return false",
- x == w);
- assertFalse("x.equals(w) didn't return false",
- x.equals(w));
+ assertFalse(x == w, "x == w didn't return false");
+ assertFalse(x.equals(w), "x.equals(w) didn't return false");
// test refelexivity
- assertTrue("x.equals(x) didn't return true",
- x.equals(x));
+ assertTrue(x.equals(x), "x.equals(x) didn't return true");
// test symmetry
EthernetAddress y =
new EthernetAddress(VALID_ETHERNET_ADDRESS_BYTE_ARRAY);
- assertFalse("x == y didn't return false",
- x == y);
- assertTrue("y.equals(x) didn't return true",
- y.equals(x));
- assertTrue("x.equals(y) didn't return true",
- x.equals(y));
+ assertFalse(x == y, "x == y didn't return false");
+ assertTrue(y.equals(x), "y.equals(x) didn't return true");
+ assertTrue(x.equals(y), "x.equals(y) didn't return true");
// now we'll test transitivity
EthernetAddress z =
new EthernetAddress(VALID_ETHERNET_ADDRESS_BYTE_ARRAY);
- assertFalse("x == y didn't return false",
- x == y);
- assertFalse("x == y didn't return false",
- y == z);
- assertFalse("x == y didn't return false",
- x == z);
- assertTrue("x.equals(y) didn't return true",
- x.equals(y));
- assertTrue("y.equals(z) didn't return true",
- y.equals(z));
- assertTrue("x.equals(z) didn't return true",
- x.equals(z));
+ assertFalse(x == y, "x == y didn't return false");
+ assertFalse(y == z, "x == y didn't return false");
+ assertFalse(x == z, "x == y didn't return false");
+ assertTrue(x.equals(y), "x.equals(y) didn't return true");
+ assertTrue(y.equals(z), "y.equals(z) didn't return true");
+ assertTrue(x.equals(z), "x.equals(z) didn't return true");
// test consistancy (this test is just calling equals multiple times)
- assertFalse("x == y didn't return false",
- x == y);
- assertTrue("x.equals(y) didn't return true",
- x.equals(y));
- assertTrue("x.equals(y) didn't return true",
- x.equals(y));
- assertTrue("x.equals(y) didn't return true",
- x.equals(y));
+ assertFalse(x == y, "x == y didn't return false");
+ assertTrue(x.equals(y), "x.equals(y) didn't return true");
+ assertTrue(x.equals(y), "x.equals(y) didn't return true");
+ assertTrue(x.equals(y), "x.equals(y) didn't return true");
}
/**
* Test of toByteArray method, of class com.fasterxml.uuid.EthernetAddress.
*/
+ @Test
+
public void testToByteArray()
{
// we'll test making a couple EthernetAddresses and then check that the
@@ -666,18 +628,14 @@ public void testToByteArray()
// first we'll test the null EthernetAddress
EthernetAddress ethernet_address = new EthernetAddress(0L);
- assertEquals("Expected length of returned array wrong",
- ETHERNET_ADDRESS_ARRAY_LENGTH,
- ethernet_address.toByteArray().length);
+ assertEquals(ETHERNET_ADDRESS_ARRAY_LENGTH, ethernet_address.toByteArray().length, "Expected length of returned array wrong");
assertEthernetAddressArraysAreEqual(
NULL_ETHERNET_ADDRESS_BYTE_ARRAY, 0,
ethernet_address.toByteArray(), 0);
// now test a non-null EthernetAddress
ethernet_address = new EthernetAddress(VALID_ETHERNET_ADDRESS_LONG);
- assertEquals("Expected length of returned array wrong",
- ETHERNET_ADDRESS_ARRAY_LENGTH,
- ethernet_address.toByteArray().length);
+ assertEquals(ETHERNET_ADDRESS_ARRAY_LENGTH, ethernet_address.toByteArray().length, "Expected length of returned array wrong");
assertEthernetAddressArraysAreEqual(
VALID_ETHERNET_ADDRESS_BYTE_ARRAY, 0,
ethernet_address.toByteArray(), 0);
@@ -704,6 +662,8 @@ public void testToByteArray()
* Test of toByteArray(byte[]) method,
* of class com.fasterxml.uuid.EthernetAddress.
*/
+ @Test
+
public void testToByteArrayDest()
{
// constant for use in this test
@@ -767,9 +727,7 @@ public void testToByteArrayDest()
assertEthernetAddressArraysAreEqual(NULL_ETHERNET_ADDRESS_BYTE_ARRAY, 0, test_array, 0);
for (int i = 0; i < EXTRA_DATA_LENGTH; i++)
{
- assertEquals("Expected array fill value changed",
- (byte)'x',
- test_array[i + ETHERNET_ADDRESS_ARRAY_LENGTH]);
+ assertEquals((byte)'x', test_array[i + ETHERNET_ADDRESS_ARRAY_LENGTH], "Expected array fill value changed");
}
// now test a good EthernetAddress case with extra data in the array
@@ -783,9 +741,7 @@ public void testToByteArrayDest()
VALID_ETHERNET_ADDRESS_BYTE_ARRAY, 0, test_array, 0);
for (int i = 0; i < EXTRA_DATA_LENGTH; i++)
{
- assertEquals("Expected array fill value changed",
- (byte)'x',
- test_array[i + ETHERNET_ADDRESS_ARRAY_LENGTH]);
+ assertEquals((byte)'x', test_array[i + ETHERNET_ADDRESS_ARRAY_LENGTH], "Expected array fill value changed");
}
}
@@ -793,6 +749,8 @@ public void testToByteArrayDest()
* Test of toByteArray(byte[], int) method,
* of class com.fasterxml.uuid.EthernetAddress.
*/
+ @Test
+
public void testToByteArrayDestOffset()
{
// constant value for use in this test
@@ -905,9 +863,7 @@ public void testToByteArrayDestOffset()
assertEthernetAddressArraysAreEqual(
NULL_ETHERNET_ADDRESS_BYTE_ARRAY, 0, test_array, 0);
for (int i = 0; i < EXTRA_DATA_LENGTH; i++) {
- assertEquals("Expected array fill value changed",
- (byte)'x',
- test_array[i + ETHERNET_ADDRESS_ARRAY_LENGTH]);
+ assertEquals((byte)'x', test_array[i + ETHERNET_ADDRESS_ARRAY_LENGTH], "Expected array fill value changed");
}
// now test a null EthernetAddress case with extra data in the array
@@ -920,13 +876,9 @@ public void testToByteArrayDestOffset()
test_array, EXTRA_DATA_LENGTH/2);
for (int i = 0; i < EXTRA_DATA_LENGTH/2; i++)
{
- assertEquals("Expected array fill value changed",
- (byte)'x',
- test_array[i]);
- assertEquals("Expected array fill value changed",
- (byte)'x',
- test_array[i + ETHERNET_ADDRESS_ARRAY_LENGTH +
- EXTRA_DATA_LENGTH/2]);
+ assertEquals((byte)'x', test_array[i], "Expected array fill value changed");
+ assertEquals((byte)'x', test_array[i + ETHERNET_ADDRESS_ARRAY_LENGTH +
+ EXTRA_DATA_LENGTH/2], "Expected array fill value changed");
}
// now test a good EthernetAddress case with extra data in the array
@@ -940,9 +892,7 @@ public void testToByteArrayDestOffset()
VALID_ETHERNET_ADDRESS_BYTE_ARRAY, 0, test_array, 0);
for (int i = 0; i < EXTRA_DATA_LENGTH; i++)
{
- assertEquals("Expected array fill value changed",
- (byte)'x',
- test_array[i + ETHERNET_ADDRESS_ARRAY_LENGTH]);
+ assertEquals((byte)'x', test_array[i + ETHERNET_ADDRESS_ARRAY_LENGTH], "Expected array fill value changed");
}
// now test a good EthernetAddress case with extra data in the array
@@ -957,19 +907,17 @@ public void testToByteArrayDestOffset()
test_array, EXTRA_DATA_LENGTH/2);
for (int i = 0; i < EXTRA_DATA_LENGTH/2; i++)
{
- assertEquals("Expected array fill value changed",
- (byte)'x',
- test_array[i]);
- assertEquals("Expected array fill value changed",
- (byte)'x',
- test_array[i + ETHERNET_ADDRESS_ARRAY_LENGTH +
- EXTRA_DATA_LENGTH/2]);
+ assertEquals((byte)'x', test_array[i], "Expected array fill value changed");
+ assertEquals((byte)'x', test_array[i + ETHERNET_ADDRESS_ARRAY_LENGTH +
+ EXTRA_DATA_LENGTH/2], "Expected array fill value changed");
}
}
/**
* Test of toLong method, of class com.fasterxml.uuid.EthernetAddress.
*/
+ @Test
+
public void testToLong()
{
// test making a couple EthernetAddresss and then check that the toLong
@@ -977,21 +925,19 @@ public void testToLong()
// test the null EthernetAddress
EthernetAddress ethernet_address = new EthernetAddress(0L);
- assertEquals("null EthernetAddress long and toLong did not match",
- NULL_ETHERNET_ADDRESS_LONG,
- ethernet_address.toLong());
+ assertEquals(NULL_ETHERNET_ADDRESS_LONG, ethernet_address.toLong(), "null EthernetAddress long and toLong did not match");
// test a non-null EthernetAddress
ethernet_address =
new EthernetAddress(VALID_ETHERNET_ADDRESS_BYTE_ARRAY);
- assertEquals("EthernetAddress long and toLong results did not match",
- VALID_ETHERNET_ADDRESS_LONG,
- ethernet_address.toLong());
+ assertEquals(VALID_ETHERNET_ADDRESS_LONG, ethernet_address.toLong(), "EthernetAddress long and toLong results did not match");
}
/**
* Test of toString method, of class com.fasterxml.uuid.EthernetAddress.
*/
+ @Test
+
public void testToString()
{
// test making a few EthernetAddresss and check that the toString
@@ -999,17 +945,12 @@ public void testToString()
// test the null EthernetAddress
EthernetAddress ethernet_address = new EthernetAddress(0L);
- assertEquals("null EthernetAddress string and toString did not match",
- NULL_ETHERNET_ADDRESS_STRING.toLowerCase(),
- ethernet_address.toString().toLowerCase());
+ assertEquals(NULL_ETHERNET_ADDRESS_STRING.toLowerCase(), ethernet_address.toString().toLowerCase(), "null EthernetAddress string and toString did not match");
// test a non-null EthernetAddress
ethernet_address =
new EthernetAddress(VALID_ETHERNET_ADDRESS_BYTE_ARRAY);
- assertEquals(
- "EthernetAddress string and toString results did not match",
- MIXED_CASE_VALID_ETHERNET_ADDRESS_STRING.toLowerCase(),
- ethernet_address.toString().toLowerCase());
+ assertEquals(MIXED_CASE_VALID_ETHERNET_ADDRESS_STRING.toLowerCase(), ethernet_address.toString().toLowerCase(), "EthernetAddress string and toString results did not match");
// EthernetAddress implementation returns strings all lowercase.
// Although relying on this behavior in code is not recommended,
@@ -1018,21 +959,20 @@ public void testToString()
// who relies on this particular behavior.
ethernet_address =
new EthernetAddress(VALID_ETHERNET_ADDRESS_BYTE_ARRAY);
- assertFalse("mixed case EthernetAddress string and toString " +
- "matched (expected toString to be all lower case)",
- MIXED_CASE_VALID_ETHERNET_ADDRESS_STRING.equals(
- ethernet_address.toString()));
- assertEquals("mixed case string toLowerCase and " +
+ assertFalse(MIXED_CASE_VALID_ETHERNET_ADDRESS_STRING.equals(
+ ethernet_address.toString()), "mixed case EthernetAddress string and toString " +
+ "matched (expected toString to be all lower case)");
+ assertEquals(MIXED_CASE_VALID_ETHERNET_ADDRESS_STRING.toLowerCase(), ethernet_address.toString(), "mixed case string toLowerCase and " +
"toString results did not match (expected toString to " +
- "be all lower case)",
- MIXED_CASE_VALID_ETHERNET_ADDRESS_STRING.toLowerCase(),
- ethernet_address.toString());
+ "be all lower case)");
}
/**
* Test of valueOf(byte[]) method,
* of class com.fasterxml.uuid.EthernetAddress.
*/
+ @Test
+
public void testValueOfByteArray()
{
// lets test some error cases
@@ -1093,24 +1033,20 @@ public void testValueOfByteArray()
// gives us a null EthernetAddress (definition of null EthernetAddress)
EthernetAddress ethernet_address =
EthernetAddress.valueOf(new byte[ETHERNET_ADDRESS_ARRAY_LENGTH]);
- assertEquals(
- "EthernetAddress.valueOf did not create expected EthernetAddress",
- NULL_ETHERNET_ADDRESS_LONG,
- ethernet_address.toLong());
+ assertEquals(NULL_ETHERNET_ADDRESS_LONG, ethernet_address.toLong(), "EthernetAddress.valueOf did not create expected EthernetAddress");
// let's test creating an array from a good byte array
ethernet_address =
EthernetAddress.valueOf(VALID_ETHERNET_ADDRESS_BYTE_ARRAY);
- assertEquals(
- "EthernetAddress.valueOf did not create expected EthernetAddress",
- VALID_ETHERNET_ADDRESS_LONG,
- ethernet_address.toLong());
+ assertEquals(VALID_ETHERNET_ADDRESS_LONG, ethernet_address.toLong(), "EthernetAddress.valueOf did not create expected EthernetAddress");
}
/**
* Test of valueOf(int[]) method,
* of class com.fasterxml.uuid.EthernetAddress.
*/
+ @Test
+
public void testValueOfIntArray()
{
// lets test some error cases
@@ -1171,48 +1107,40 @@ public void testValueOfIntArray()
// gives a null EthernetAddress (definition of a null EthernetAddress)
EthernetAddress ethernet_address =
EthernetAddress.valueOf(new int[ETHERNET_ADDRESS_ARRAY_LENGTH]);
- assertEquals(
- "EthernetAddress.valueOf did not create expected EthernetAddress",
- NULL_ETHERNET_ADDRESS_LONG,
- ethernet_address.toLong());
+ assertEquals(NULL_ETHERNET_ADDRESS_LONG, ethernet_address.toLong(), "EthernetAddress.valueOf did not create expected EthernetAddress");
// let's test creating an array from a good int array
ethernet_address =
EthernetAddress.valueOf(VALID_ETHERNET_ADDRESS_INT_ARRAY);
- assertEquals(
- "EthernetAddress.valueOf did not create expected EthernetAddress",
- VALID_ETHERNET_ADDRESS_LONG,
- ethernet_address.toLong());
+ assertEquals(VALID_ETHERNET_ADDRESS_LONG, ethernet_address.toLong(), "EthernetAddress.valueOf did not create expected EthernetAddress");
}
/**
* Test of valueOf(long) method,
* of class com.fasterxml.uuid.EthernetAddress.
*/
+ @Test
+
public void testValueOfLong()
{
// let's test that creating a EthernetAddress from an zero long
// gives a null EthernetAddress (definition of a null EthernetAddress)
EthernetAddress ethernet_address =
EthernetAddress.valueOf(0x0000000000000000L);
- assertEquals(
- "EthernetAddress.valueOf did not create expected EthernetAddress",
- NULL_ETHERNET_ADDRESS_LONG,
- ethernet_address.toLong());
+ assertEquals(NULL_ETHERNET_ADDRESS_LONG, ethernet_address.toLong(), "EthernetAddress.valueOf did not create expected EthernetAddress");
// let's test creating an array from a good long
ethernet_address =
EthernetAddress.valueOf(VALID_ETHERNET_ADDRESS_LONG);
- assertEquals(
- "EthernetAddress.valueOf did not create expected EthernetAddress",
- VALID_ETHERNET_ADDRESS_LONG,
- ethernet_address.toLong());
+ assertEquals(VALID_ETHERNET_ADDRESS_LONG, ethernet_address.toLong(), "EthernetAddress.valueOf did not create expected EthernetAddress");
}
/**
* Test of valueOf(String) method,
* of class com.fasterxml.uuid.EthernetAddress.
*/
+ @Test
+
public void testValueOfString()
{
// test a null string case
@@ -1302,6 +1230,8 @@ public void testValueOfString()
*
* @since 3.0
*/
+ @Test
+
public void testFromInterface() throws Exception
{
EthernetAddress addr = EthernetAddress.fromInterface();
@@ -1309,12 +1239,16 @@ public void testFromInterface() throws Exception
assertNotNull(addr.toString());
}
+ @Test
+
public void testFromEgressInterface() {
EthernetAddress ifAddr = EthernetAddress.fromEgressInterface();
assertNotNull(ifAddr);
assertNotNull(ifAddr.toString());
}
+ @Test
+
public void testDefaultTimeBasedGenerator()
{
TimeBasedGenerator generator = Generators.defaultTimeBasedGenerator();
@@ -1324,6 +1258,8 @@ public void testDefaultTimeBasedGenerator()
assertNotNull(ifAddr.toString());
}
+ @Test
+
public void testBogus() throws Exception
{
// First, two using pseudo-random; verify they are different
@@ -1381,9 +1317,7 @@ private void goodStringEthernetAddressConstructorHelper(
fail("Caught unexpected exception: " + ex);
}
- assertEquals("EthernetAddresses were not equal",
- expectedEthernetAddressString.toLowerCase(),
- ethernet_address.toString().toLowerCase());
+ assertEquals(expectedEthernetAddressString.toLowerCase(), ethernet_address.toString().toLowerCase(), "EthernetAddresses were not equal");
}
private void badStringValueOfHelper(String ethernetAddressString)
@@ -1418,44 +1352,42 @@ private void goodStringValueOfHelper(String ethernetAddressString,
fail("Caught unexpected exception: " + ex);
}
- assertEquals("EthernetAddresses were not equal",
- expectedEthernetAddressString.toLowerCase(),
- ethernet_address.toString().toLowerCase());
+ assertEquals(expectedEthernetAddressString.toLowerCase(), ethernet_address.toString().toLowerCase(), "EthernetAddresses were not equal");
}
private void assertEthernetAddressesMatchHelper(EthernetAddress expected,
EthernetAddress actual)
{
- assertEquals("EthernetAddresses in long form did not match",
- expected.toLong(),
- actual.toLong());
- assertEquals("EthernetAddress equals did not match",
- expected,
- actual);
+ assertEquals(expected.toLong(), actual.toLong(), "EthernetAddresses in long form did not match");
+ assertEquals(expected, actual, "EthernetAddress equals did not match");
}
private void assertEthernetAddressEqualOrderHelper(
EthernetAddress ethernetAddress1,
EthernetAddress ethernetAddress2)
{
- assertTrue(ethernetAddress1 + " did not test as equal to " +
- ethernetAddress2,
- 0 == ethernetAddress1.compareTo(ethernetAddress2));
- assertTrue(ethernetAddress2 + " did not test as equal to " +
- ethernetAddress1,
- 0 == ethernetAddress2.compareTo(ethernetAddress1));
+ assertTrue(
+ 0 == ethernetAddress1.compareTo(ethernetAddress2),
+ ethernetAddress1 + " did not test as equal to " +
+ ethernetAddress2);
+ assertTrue(
+ 0 == ethernetAddress2.compareTo(ethernetAddress1),
+ ethernetAddress2 + " did not test as equal to " +
+ ethernetAddress1);
}
private void assertEthernetAddressGreaterOrderHelper(
EthernetAddress ethernetAddress1,
EthernetAddress ethernetAddress2)
{
- assertTrue(ethernetAddress1 + " did not test as larger then " +
- ethernetAddress2,
- 0 < ethernetAddress1.compareTo(ethernetAddress2));
- assertTrue(ethernetAddress2 + " did not test as smaller then " +
- ethernetAddress1,
- 0 > ethernetAddress2.compareTo(ethernetAddress1));
+ assertTrue(
+ 0 < ethernetAddress1.compareTo(ethernetAddress2),
+ ethernetAddress1 + " did not test as larger then " +
+ ethernetAddress2);
+ assertTrue(
+ 0 > ethernetAddress2.compareTo(ethernetAddress1),
+ ethernetAddress2 + " did not test as smaller then " +
+ ethernetAddress1);
}
private void assertEthernetAddressArraysAreEqual(byte[] array1,
@@ -1463,19 +1395,13 @@ private void assertEthernetAddressArraysAreEqual(byte[] array1,
byte[] array2,
int array2_start)
{
- assertTrue("Array1 start offset is invalid",
- 0 <= array1_start);
- assertTrue("Array2 start offset is invalid",
- 0 <= array2_start);
- assertTrue("Array1 is not long enough for the given start offset",
- array1.length >= ETHERNET_ADDRESS_ARRAY_LENGTH + array1_start);
- assertTrue("Array2 is not long enough for the given start offset",
- array2.length >= ETHERNET_ADDRESS_ARRAY_LENGTH + array2_start);
+ assertTrue(0 <= array1_start, "Array1 start offset is invalid");
+ assertTrue(0 <= array2_start, "Array2 start offset is invalid");
+ assertTrue(array1.length >= ETHERNET_ADDRESS_ARRAY_LENGTH + array1_start, "Array1 is not long enough for the given start offset");
+ assertTrue(array2.length >= ETHERNET_ADDRESS_ARRAY_LENGTH + array2_start, "Array2 is not long enough for the given start offset");
for (int i = 0; i < ETHERNET_ADDRESS_ARRAY_LENGTH; i++)
{
- assertEquals("Array1 and Array2 did not match (index #"+i+")",
- array1[i + array1_start],
- array2[i + array2_start]);
+ assertEquals(array1[i + array1_start], array2[i + array2_start], "Array1 and Array2 did not match (index #"+i+")");
}
}
@@ -1484,14 +1410,10 @@ private void assertEthernetAddressArraysAreNotEqual(byte[] array1,
byte[] array2,
int array2_start)
{
- assertTrue("Array1 start offset is invalid",
- 0 <= array1_start);
- assertTrue("Array2 start offset is invalid",
- 0 <= array2_start);
- assertTrue("Array1 is not long enough for the given start offset",
- array1.length >= ETHERNET_ADDRESS_ARRAY_LENGTH + array1_start);
- assertTrue("Array2 is not long enough for the given start offset",
- array2.length >= ETHERNET_ADDRESS_ARRAY_LENGTH + array2_start);
+ assertTrue(0 <= array1_start, "Array1 start offset is invalid");
+ assertTrue(0 <= array2_start, "Array2 start offset is invalid");
+ assertTrue(array1.length >= ETHERNET_ADDRESS_ARRAY_LENGTH + array1_start, "Array1 is not long enough for the given start offset");
+ assertTrue(array2.length >= ETHERNET_ADDRESS_ARRAY_LENGTH + array2_start, "Array2 is not long enough for the given start offset");
for (int i = 0; i < ETHERNET_ADDRESS_ARRAY_LENGTH; i++)
{
// as soon as we find a non-matching byte,
diff --git a/src/test/java/com/fasterxml/uuid/JugNamedTest.java b/src/test/java/com/fasterxml/uuid/JugNamedTest.java
index 33d41db..9e373cc 100644
--- a/src/test/java/com/fasterxml/uuid/JugNamedTest.java
+++ b/src/test/java/com/fasterxml/uuid/JugNamedTest.java
@@ -1,10 +1,9 @@
package com.fasterxml.uuid;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
@@ -13,15 +12,14 @@
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
+import java.util.stream.Stream;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.StringContains.containsString;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-@RunWith(Parameterized.class)
public class JugNamedTest {
- @Parameterized.Parameter
- public UseCase useCase;
+ private UseCase useCase;
private PrintStream oldStrOut;
private PrintStream oldStrErr;
@@ -30,9 +28,10 @@ public class JugNamedTest {
private final ByteArrayOutputStream errContent = new ByteArrayOutputStream();
private Jug jug_underTest;
- @Before
+ @BeforeEach
public void setup() {
- jug_underTest = new Jug();oldStrOut = System.out;
+ jug_underTest = new Jug();
+ oldStrOut = System.out;
oldStrErr = System.err;
PrintStream stubbedStream = new PrintStream(outContent);
System.setOut(stubbedStream);
@@ -40,14 +39,16 @@ public void setup() {
System.setErr(stubbedErrStream);
}
- @After
+ @AfterEach
public void cleanup() {
System.setOut(oldStrOut);
System.setErr(oldStrErr);
}
- @Test
- public void run_shouldProduceUUID() {
+ @ParameterizedTest
+ @MethodSource("useCases")
+ public void run_shouldProduceUUID(UseCase useCase) {
+ this.useCase = useCase;
// given
// when
@@ -62,8 +63,10 @@ public void run_shouldProduceUUID() {
UUID.fromString(actualUuid.substring(0, actualUuid.length() - 1)).getClass());
}
- @Test
- public void run_givenCount3_shouldProduceUUID() {
+ @ParameterizedTest
+ @MethodSource("useCases")
+ public void run_givenCount3_shouldProduceUUID(UseCase useCase) {
+ this.useCase = useCase;
// given
// when
@@ -80,8 +83,10 @@ public void run_givenCount3_shouldProduceUUID() {
}
}
- @Test
- public void run_givenPerformance_shouldProducePerformanceInfo() {
+ @ParameterizedTest
+ @MethodSource("useCases")
+ public void run_givenPerformance_shouldProducePerformanceInfo(UseCase useCase) {
+ this.useCase = useCase;
// given
// when
@@ -94,8 +99,10 @@ public void run_givenPerformance_shouldProducePerformanceInfo() {
assertThat(actualOutput, containsString("Performance: took"));
}
- @Test
- public void run_givenHelp_shouldProduceHelpInfo() {
+ @ParameterizedTest
+ @MethodSource("useCases")
+ public void run_givenHelp_shouldProduceHelpInfo(UseCase useCase) {
+ this.useCase = useCase;
// given
// when
@@ -109,8 +116,10 @@ public void run_givenHelp_shouldProduceHelpInfo() {
assertThat(actualOutput, containsString("Usage: java"));
}
- @Test
- public void run_givenVerbose_shouldProduceExtraInfo() {
+ @ParameterizedTest
+ @MethodSource("useCases")
+ public void run_givenVerbose_shouldProduceExtraInfo(UseCase useCase) {
+ this.useCase = useCase;
// given
// when
@@ -124,8 +133,10 @@ public void run_givenVerbose_shouldProduceExtraInfo() {
assertThat(actualOutput, containsString("Done."));
}
- @Test
- public void run_givenVerboseAndPerformance_shouldProduceExtraInfo() {
+ @ParameterizedTest
+ @MethodSource("useCases")
+ public void run_givenVerboseAndPerformance_shouldProduceExtraInfo(UseCase useCase) {
+ this.useCase = useCase;
// given
// when
@@ -141,12 +152,11 @@ public void run_givenVerboseAndPerformance_shouldProduceExtraInfo() {
assertThat(actualOutput, containsString("Performance: took"));
}
- @Parameterized.Parameters(name = "{index} -> {0}")
- public static List useCases() {
- return Arrays.asList(
+ static Stream useCases() {
+ return Stream.of(
new UseCase("n", "-n", "world", "-s", "url"),
new UseCase("n", "-n", "world", "-s", "dns")
- );
+ );
}
private static class UseCase {
diff --git a/src/test/java/com/fasterxml/uuid/JugNoArgsTest.java b/src/test/java/com/fasterxml/uuid/JugNoArgsTest.java
index 54499cf..df533c9 100644
--- a/src/test/java/com/fasterxml/uuid/JugNoArgsTest.java
+++ b/src/test/java/com/fasterxml/uuid/JugNoArgsTest.java
@@ -1,10 +1,10 @@
package com.fasterxml.uuid;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
@@ -13,12 +13,10 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.StringContains.containsString;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
-@RunWith(Parameterized.class)
public class JugNoArgsTest {
- @Parameterized.Parameter
- public String useCase;
+ private String useCase;
private PrintStream oldStrOut;
private PrintStream oldStrErr;
@@ -27,7 +25,7 @@ public class JugNoArgsTest {
private final ByteArrayOutputStream errContent = new ByteArrayOutputStream();
private Jug jug_underTest;
- @Before
+ @BeforeEach
public void setup() {
jug_underTest = new Jug();
oldStrOut = System.out;
@@ -38,14 +36,16 @@ public void setup() {
System.setErr(stubbedErrStream);
}
- @After
+ @AfterEach
public void cleanup() {
System.setOut(oldStrOut);
System.setErr(oldStrErr);
}
- @Test
- public void run_givenNoOptions_shouldProduceUUID() {
+ @ParameterizedTest
+ @ValueSource(strings = {"t", "o", "r", "e", "m"})
+ public void run_givenNoOptions_shouldProduceUUID(String useCase) {
+ this.useCase = useCase;
// given
// when
@@ -59,8 +59,10 @@ public void run_givenNoOptions_shouldProduceUUID() {
UUID.fromString(actualUuid.substring(0, actualUuid.length() - 1)).getClass());
}
- @Test
- public void run_givenCount1_shouldProduceUUID() {
+ @ParameterizedTest
+ @ValueSource(strings = {"t", "o", "r", "e", "m"})
+ public void run_givenCount1_shouldProduceUUID(String useCase) {
+ this.useCase = useCase;
// given
// when
@@ -76,8 +78,10 @@ public void run_givenCount1_shouldProduceUUID() {
UUID.fromString(actualUuid.substring(0, actualUuid.length() - 1)).getClass());
}
- @Test
- public void run_givenCount2_shouldProduce2UUIDs() {
+ @ParameterizedTest
+ @ValueSource(strings = {"t", "o", "r", "e", "m"})
+ public void run_givenCount2_shouldProduce2UUIDs(String useCase) {
+ this.useCase = useCase;
// given
// when
@@ -95,8 +99,10 @@ public void run_givenCount2_shouldProduce2UUIDs() {
}
}
- @Test
- public void run_givenEthernet_shouldProduceUUID() {
+ @ParameterizedTest
+ @ValueSource(strings = {"t", "o", "r", "e", "m"})
+ public void run_givenEthernet_shouldProduceUUID(String useCase) {
+ this.useCase = useCase;
// given
// when
@@ -112,8 +118,10 @@ public void run_givenEthernet_shouldProduceUUID() {
UUID.fromString(actualUuid.substring(0, actualUuid.length() - 1)).getClass());
}
- @Test
- public void run_givenName_shouldProduceUUID() {
+ @ParameterizedTest
+ @ValueSource(strings = {"t", "o", "r", "e", "m"})
+ public void run_givenName_shouldProduceUUID(String useCase) {
+ this.useCase = useCase;
// given
// when
@@ -129,8 +137,10 @@ public void run_givenName_shouldProduceUUID() {
UUID.fromString(actualUuid.substring(0, actualUuid.length() - 1)).getClass());
}
- @Test
- public void run_givenDnsNameSpace_shouldProduceUUID() {
+ @ParameterizedTest
+ @ValueSource(strings = {"t", "o", "r", "e", "m"})
+ public void run_givenDnsNameSpace_shouldProduceUUID(String useCase) {
+ this.useCase = useCase;
// given
// when
@@ -146,8 +156,10 @@ public void run_givenDnsNameSpace_shouldProduceUUID() {
UUID.fromString(actualUuid.substring(0, actualUuid.length() - 1)).getClass());
}
- @Test
- public void run_givenUrlNameSpace_shouldProduceUUID() {
+ @ParameterizedTest
+ @ValueSource(strings = {"t", "o", "r", "e", "m"})
+ public void run_givenUrlNameSpace_shouldProduceUUID(String useCase) {
+ this.useCase = useCase;
// given
// when
@@ -163,8 +175,10 @@ public void run_givenUrlNameSpace_shouldProduceUUID() {
UUID.fromString(actualUuid.substring(0, actualUuid.length() - 1)).getClass());
}
- @Test
- public void run_givenPerformance_shouldProducePerformanceInfo() {
+ @ParameterizedTest
+ @ValueSource(strings = {"t", "o", "r", "e", "m"})
+ public void run_givenPerformance_shouldProducePerformanceInfo(String useCase) {
+ this.useCase = useCase;
// given
// when
@@ -177,8 +191,10 @@ public void run_givenPerformance_shouldProducePerformanceInfo() {
assertThat(actualOutput, containsString("Performance: took"));
}
- @Test
- public void run_givenHelp_shouldProduceHelpInfo() {
+ @ParameterizedTest
+ @ValueSource(strings = {"t", "o", "r", "e", "m"})
+ public void run_givenHelp_shouldProduceHelpInfo(String useCase) {
+ this.useCase = useCase;
// given
// when
@@ -191,8 +207,10 @@ public void run_givenHelp_shouldProduceHelpInfo() {
assertThat(actualOutput, containsString("Usage: java"));
}
- @Test
- public void run_givenVerbose_shouldProduceExtraInfo() {
+ @ParameterizedTest
+ @ValueSource(strings = {"t", "o", "r", "e", "m"})
+ public void run_givenVerbose_shouldProduceExtraInfo(String useCase) {
+ this.useCase = useCase;
// given
// when
@@ -205,14 +223,4 @@ public void run_givenVerbose_shouldProduceExtraInfo() {
assertThat(actualOutput, containsString("Done."));
}
- @Parameterized.Parameters(name = "{index} -> type: {0}")
- public static List useCases() {
- return Arrays.asList(
- "t",
- "o",
- "r",
- "e",
- "m"
- );
- }
}
\ No newline at end of file
diff --git a/src/test/java/com/fasterxml/uuid/SimpleGenerationTest.java b/src/test/java/com/fasterxml/uuid/SimpleGenerationTest.java
index 50180f0..0a7dfca 100644
--- a/src/test/java/com/fasterxml/uuid/SimpleGenerationTest.java
+++ b/src/test/java/com/fasterxml/uuid/SimpleGenerationTest.java
@@ -2,10 +2,13 @@
import java.util.UUID;
-import junit.framework.TestCase;
+import org.junit.jupiter.api.Test;
-public class SimpleGenerationTest extends TestCase
+import static org.junit.jupiter.api.Assertions.*;
+
+public class SimpleGenerationTest
{
+ @Test
public void testIssue5() throws Exception
{
UUID uuid = Generators.randomBasedGenerator().generate();
diff --git a/src/test/java/com/fasterxml/uuid/UUIDComparatorTest.java b/src/test/java/com/fasterxml/uuid/UUIDComparatorTest.java
index 6103a66..eb7aa5a 100644
--- a/src/test/java/com/fasterxml/uuid/UUIDComparatorTest.java
+++ b/src/test/java/com/fasterxml/uuid/UUIDComparatorTest.java
@@ -22,11 +22,13 @@
import com.fasterxml.uuid.impl.TimeBasedEpochGenerator;
-import junit.framework.TestCase;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
public class UUIDComparatorTest
- extends TestCase
{
+ @Test
public void testIntComp()
{
assertEquals(0, UUIDComparator.compareUInts(123, 123));
@@ -47,6 +49,7 @@ public void testIntComp()
assertTrue(UUIDComparator.compareUInts(0xFFFFFF00, 0xFFFFFF17) < 0);
}
+ @Test
public void testLongComp()
{
assertEquals(0, UUIDComparator.compareULongs(123L, 123L));
@@ -75,6 +78,7 @@ public void testLongComp()
/*
* [Issue#13]
*/
+ @Test
public void testSorting()
{
String[] src = new String[] {
@@ -107,6 +111,7 @@ public void testSorting()
}
}
+ @Test
public void testSortingMV7() throws Exception {
final int count = 10000000;
Random entropy = new Random(0x666);
@@ -120,7 +125,7 @@ public void testSortingMV7() throws Exception {
HashSet unique = new HashSet(count);
for (int i = 0; i < created.size(); i++) {
- assertEquals("Error at: " + i, created.get(i), sortedUUID.get(i));
+ assertEquals(created.get(i), sortedUUID.get(i), "Error at: " + i);
if (!unique.add(created.get(i))) {
System.out.println("Duplicate at: " + i);
}
diff --git a/src/test/java/com/fasterxml/uuid/UUIDGeneratorTest.java b/src/test/java/com/fasterxml/uuid/UUIDGeneratorTest.java
index 1b86416..c260ed5 100644
--- a/src/test/java/com/fasterxml/uuid/UUIDGeneratorTest.java
+++ b/src/test/java/com/fasterxml/uuid/UUIDGeneratorTest.java
@@ -17,16 +17,13 @@
package com.fasterxml.uuid;
-import static org.junit.Assert.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.*;
import java.nio.ByteBuffer;
import java.security.MessageDigest;
import java.util.*;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-import junit.textui.TestRunner;
+import org.junit.jupiter.api.Test;
import com.fasterxml.uuid.impl.UUIDUtil;
import com.fasterxml.uuid.impl.NameBasedGenerator;
@@ -42,7 +39,7 @@
* @author Eric Bie
* @author Tatu Saloranta
*/
-public class UUIDGeneratorTest extends TestCase
+public class UUIDGeneratorTest
{
// size of the arrays to create for tests using arrays of values
// 19-Jun-2022, tatu: Reduce from 10000 since that seems to sometimes
@@ -50,26 +47,11 @@ public class UUIDGeneratorTest extends TestCase
// simplistic; not exposing an actual issue)
private static final int SIZE_OF_TEST_ARRAY = 9000;
- public UUIDGeneratorTest(java.lang.String testName)
- {
- super(testName);
- }
-
- public static Test suite()
- {
- TestSuite suite = new TestSuite(UUIDGeneratorTest.class);
- return suite;
- }
-
- public static void main(String[] args)
- {
- TestRunner.run(suite());
- }
-
/**
* Test of getDummyAddress method,
* of class com.fasterxml.uuid.UUIDGenerator.
*/
+ @Test
public void testGetDummyAddress()
{
// this test will attempt to check for reasonable behavior of the
@@ -95,17 +77,17 @@ public void testGetDummyAddress()
{
byte[] ethernet_address = ethernet_address_array[i].asByteArray();
// check that none of the EthernetAddresses are null
- assertFalse("dummy EthernetAddress was null",
- Arrays.equals(null_ethernet_address.asByteArray(),
- ethernet_address));
+ assertFalse(Arrays.equals(null_ethernet_address.asByteArray(),
+ ethernet_address),
+ "dummy EthernetAddress was null");
// check that the "broadcast" bit is set in the created address
/* 08-Feb-2004, TSa: Fixed as per fix to actual code; apparently
* broadcast bit is LSB, not MSB.
*/
- assertEquals("dummy EthernetAddress was not broadcast",
- 0x01,
- (ethernet_address[0] & 0x01));
+ assertEquals(0x01,
+ (ethernet_address[0] & 0x01),
+ "dummy EthernetAddress was not broadcast");
}
}
@@ -113,6 +95,7 @@ public void testGetDummyAddress()
* Test of generateRandomBasedUUID method,
* of class com.fasterxml.uuid.UUIDGenerator.
*/
+ @Test
public void testGenerateRandomBasedUUID()
{
// this test will attempt to check for reasonable behavior of the
@@ -148,6 +131,7 @@ public void testGenerateRandomBasedUUID()
* Test of generateTimeBasedUUID() method,
* of class com.fasterxml.uuid.UUIDGenerator.
*/
+ @Test
public void testGenerateTimeBasedUUID()
{
// this test will attempt to check for reasonable behavior of the
@@ -196,6 +180,7 @@ public void testGenerateTimeBasedUUID()
* Test of generateTimeBasedUUID(EthernetAddress) method,
* of class com.fasterxml.uuid.UUIDGenerator.
*/
+ @Test
public void testGenerateTimeBasedUUIDWithEthernetAddress()
{
// this test will attempt to check for reasonable behavior of the
@@ -245,6 +230,7 @@ public void testGenerateTimeBasedUUIDWithEthernetAddress()
checkUUIDArrayForCorrectEthernetAddress(uuid_array, ethernet_address);
}
+ @Test
public void testV7value()
{
// Test vector from spec
@@ -256,6 +242,7 @@ public void testV7value()
* Test of generateTimeBasedEpochUUID() method,
* of class com.fasterxml.uuid.UUIDGenerator.
*/
+ @Test
public void testGenerateTimeBasedEpochUUID() throws Exception
{
// this test will attempt to check for reasonable behavior of the
@@ -308,6 +295,7 @@ public void testGenerateTimeBasedEpochUUID() throws Exception
* Test of generateTimeBasedEpochUUID() method with UUIDClock instance,
* of class com.fasterxml.uuid.UUIDGenerator.
*/
+ @Test
public void testGenerateTimeBasedEpochUUIDWithUUIDClock() throws Exception
{
// this test will attempt to check for reasonable behavior of the
@@ -360,6 +348,7 @@ public void testGenerateTimeBasedEpochUUIDWithUUIDClock() throws Exception
* Test of generateTimeBasedEpochRandomUUID() method,
* of class com.fasterxml.uuid.UUIDGenerator.
*/
+ @Test
public void testGenerateTimeBasedEpochRandomUUID() throws Exception
{
// this test will attempt to check for reasonable behavior of the
@@ -412,6 +401,7 @@ public void testGenerateTimeBasedEpochRandomUUID() throws Exception
* Test of generateTimeBasedEpochRandomUUID() method with UUIDClock instance,
* of class com.fasterxml.uuid.UUIDGenerator.
*/
+ @Test
public void testGenerateTimeBasedEpochRandomUUIDWithUUIDClock() throws Exception
{
// this test will attempt to check for reasonable behavior of the
@@ -461,6 +451,7 @@ public void testGenerateTimeBasedEpochRandomUUIDWithUUIDClock() throws Exception
}
// [#70]: allow use of custom UUIDClock
+ @Test
public void testGenerateTimeBasedEpochUUIDWithFixedClock() throws Exception
{
final UUIDClock fixedClock = new UUIDClock() {
@@ -496,6 +487,7 @@ public long currentTimeMillis() {
* Test of generateNameBasedUUID(UUID, String)
* method, of class com.fasterxml.uuid.UUIDGenerator.
*/
+ @Test
public void testGenerateNameBasedUUIDNameSpaceAndName()
{
// this test will attempt to check for reasonable behavior of the
@@ -564,16 +556,17 @@ public void testGenerateNameBasedUUIDNameSpaceAndName()
// check that all uuids were unique
checkUUIDArrayForUniqueness(uuid_array);
checkUUIDArrayForUniqueness(uuid_array2);
-
+
// check that both arrays are equal to one another
- assertTrue("expected both arrays to be equal, they were not!",
- Arrays.equals(uuid_array, uuid_array2));
+ assertTrue(Arrays.equals(uuid_array, uuid_array2),
+ "expected both arrays to be equal, they were not!");
}
-
+
/**
* Test of generateNameBasedUUID(UUID, String, MessageDigest)
* method, of class com.fasterxml.uuid.UUIDGenerator.
*/
+ @Test
public void testGenerateNameBasedUUIDNameSpaceNameAndMessageDigest()
{
MessageDigest MESSAGE_DIGEST = null;
@@ -648,16 +641,17 @@ public void testGenerateNameBasedUUIDNameSpaceNameAndMessageDigest()
// check that all uuids were unique
checkUUIDArrayForUniqueness(uuid_array);
checkUUIDArrayForUniqueness(uuid_array2);
-
+
// check that both arrays are equal to one another
- assertTrue("expected both arrays to be equal, they were not!",
- Arrays.equals(uuid_array, uuid_array2));
+ assertTrue(Arrays.equals(uuid_array, uuid_array2),
+ "expected both arrays to be equal, they were not!");
}
-
+
/**
* Test of generateNameBasedUUID()
* method, of class com.fasterxml.uuid.UUIDGenerator.
*/
+ @Test
public void testGenerateNameBasedUUIDWithDefaults()
{
// this test will attempt to check for reasonable behavior of the
@@ -726,14 +720,15 @@ public void testGenerateNameBasedUUIDWithDefaults()
checkUUIDArrayForUniqueness(uuid_array2);
// check that both arrays are equal to one another
- assertTrue("expected both arrays to be equal, they were not!",
- Arrays.equals(uuid_array, uuid_array2));
+ assertTrue(Arrays.equals(uuid_array, uuid_array2),
+ "expected both arrays to be equal, they were not!");
}
/**
* Test of generateTimeBasedReorderedUUID() method,
* of class com.fasterxml.uuid.UUIDGenerator.
*/
+ @Test
public void testGenerateTimeBasedReorderedUUID()
{
// this test will attempt to check for reasonable behavior of the
@@ -782,6 +777,7 @@ public void testGenerateTimeBasedReorderedUUID()
* Test of generateTimeBasedReorderedUUID(EthernetAddress) method,
* of class com.fasterxml.uuid.UUIDGenerator.
*/
+ @Test
public void testGenerateTimeBasedReorderedUUIDWithEthernetAddress()
{
// this test will attempt to check for reasonable behavior of the
@@ -858,9 +854,9 @@ private void checkUUIDArrayForCorrectOrdering(UUID[] uuidArray)
{
// now we'll clone the array and reverse it
UUID uuid_sorted_array[] = (UUID[])uuidArray.clone();
- assertEquals("Cloned array length did not match",
- uuidArray.length,
- uuid_sorted_array.length);
+ assertEquals(uuidArray.length,
+ uuid_sorted_array.length,
+ "Cloned array length did not match");
ReverseOrderUUIDComparator rev_order_uuid_comp =
new ReverseOrderUUIDComparator();
@@ -869,10 +865,9 @@ private void checkUUIDArrayForCorrectOrdering(UUID[] uuidArray)
// let's check that the array is actually reversed
for (int i = 0; i < uuid_sorted_array.length; i++)
{
- assertTrue(
- "Reverse order check on uuid arrays failed on element " + i,
- uuidArray[i].equals(
- uuid_sorted_array[uuid_sorted_array.length - (1 + i)]));
+ assertTrue(uuidArray[i].equals(
+ uuid_sorted_array[uuid_sorted_array.length - (1 + i)]),
+ "Reverse order check on uuid arrays failed on element " + i);
}
// now let's sort the reversed array and check that it
@@ -880,9 +875,8 @@ private void checkUUIDArrayForCorrectOrdering(UUID[] uuidArray)
Arrays.sort(uuid_sorted_array);
for (int i = 0; i < uuid_sorted_array.length; i++)
{
- assertTrue(
- "Same order check on uuid arrays failed on element " + i,
- uuidArray[i].equals(uuid_sorted_array[i]));
+ assertTrue(uuidArray[i].equals(uuid_sorted_array[i]),
+ "Same order check on uuid arrays failed on element " + i);
}
}
@@ -895,10 +889,10 @@ private void checkUUIDArrayForUniqueness(UUID[] uuidArray)
HashSet hash_set = new HashSet();
for (int i = 0; i < uuidArray.length; i++)
{
- assertTrue("Uniqueness test failed on insert into HashSet: index "+i+", value "+uuidArray[i],
- hash_set.add(uuidArray[i]));
- assertFalse("Paranoia Uniqueness test failed (second insert)",
- hash_set.add(uuidArray[i]));
+ assertTrue(hash_set.add(uuidArray[i]),
+ "Uniqueness test failed on insert into HashSet: index "+i+", value "+uuidArray[i]);
+ assertFalse(hash_set.add(uuidArray[i]),
+ "Paranoia Uniqueness test failed (second insert)");
}
}
@@ -918,14 +912,14 @@ private void checkUUIDArrayForCorrectVariantAndVersion(UUID[] uuidArray,
// extract type from the UUID and check for correct type
int type = (temp_uuid[UUIDUtil.BYTE_OFFSET_TYPE] & 0xFF) >> 4;
- assertEquals("Expected type did not match",
- expectedType.raw(),
- type);
+ assertEquals(expectedType.raw(),
+ type,
+ "Expected type did not match");
// extract variant from the UUID and check for correct variant
int variant = (temp_uuid[UUIDUtil.BYTE_OFFSET_VARIATION] & 0xFF) >> 6;
- assertEquals("Expected variant did not match",
- 2,
- variant);
+ assertEquals(2,
+ variant,
+ "Expected variant did not match");
}
}
@@ -942,8 +936,8 @@ private void checkUUIDArrayForCorrectCreationTime(UUID[] uuidArray, long startTi
// 21-Feb-2020, tatu: Not sure why this would be checked, as timestamps come from
// System.currenTimeMillis()...
- assertTrue("Start time: " + startTime +" was after the end time: " + endTime,
- startTime <= endTime);
+ assertTrue(startTime <= endTime,
+ "Start time: " + startTime +" was after the end time: " + endTime);
// let's check that all uuids in the array have a timestamp which lands
// between the start and end time
@@ -971,14 +965,12 @@ private void checkUUIDArrayForCorrectCreationTime(UUID[] uuidArray, long startTi
uuid_time /= MILLI_CONVERSION_FACTOR;
// now check that the times are correct
- assertTrue(
+ assertTrue(startTime <= uuid_time,
"Start time: " + startTime +
- " was not before UUID timestamp: " + uuid_time,
- startTime <= uuid_time);
- assertTrue(
+ " was not before UUID timestamp: " + uuid_time);
+ assertTrue(uuid_time <= endTime,
"UUID timestamp: " + uuid_time +
- " was not before the end time: " + endTime,
- uuid_time <= endTime);
+ " was not before the end time: " + endTime);
}
}
@@ -997,8 +989,8 @@ private void checkUUIDArrayForCorrectCreationTimeReorder(UUID[] uuidArray,
// 21-Feb-2020, tatu: Not sure why this would be checked, as timestamps come from
// System.currenTimeMillis()...
- assertTrue("Start time: " + startTime +" was after the end time: " + endTime,
- startTime <= endTime);
+ assertTrue(startTime <= endTime,
+ "Start time: " + startTime +" was after the end time: " + endTime);
// let's check that all uuids in the array have a timestamp which lands
// between the start and end time
@@ -1025,14 +1017,12 @@ private void checkUUIDArrayForCorrectCreationTimeReorder(UUID[] uuidArray,
uuid_time /= MILLI_CONVERSION_FACTOR;
// now check that the times are correct
- assertTrue(
+ assertTrue(startTime <= uuid_time,
"Start time: " + startTime +
- " was not before UUID timestamp: " + uuid_time,
- startTime <= uuid_time);
- assertTrue(
+ " was not before UUID timestamp: " + uuid_time);
+ assertTrue(uuid_time <= endTime,
"UUID timestamp: " + uuid_time +
- " was not before the end time: " + endTime,
- uuid_time <= endTime);
+ " was not before the end time: " + endTime);
}
}
@@ -1040,19 +1030,20 @@ private void checkUUIDArrayForCorrectCreationTimeReorder(UUID[] uuidArray,
private void checkUUIDArrayForCorrectCreationTimeEpoch(UUID[] uuidArray,
long startTime, long endTime)
{
- assertTrue("Start time: " + startTime + " was after the end time: " + endTime, startTime <= endTime);
+ assertTrue(startTime <= endTime,
+ "Start time: " + startTime + " was after the end time: " + endTime);
// let's check that all uuids in the array have a timestamp which lands
// between the start and end time
for (int i = 0; i < uuidArray.length; i++) {
byte[] temp_uuid = UUIDUtil.asByteArray(uuidArray[i]);
ByteBuffer buff = ByteBuffer.wrap(temp_uuid);
- final long uuid_time = buff.getLong() >>> 16;
+ final long uuid_time = buff.getLong() >>> 16;
// now check that the times are correct
- assertTrue("Start time: " + startTime + " was not before UUID timestamp: " + uuid_time,
- startTime <= uuid_time);
- assertTrue("UUID: " + i + " timestamp: " + uuid_time + " was not before the end time: " + endTime,
- uuid_time <= endTime);
+ assertTrue(startTime <= uuid_time,
+ "Start time: " + startTime + " was not before UUID timestamp: " + uuid_time);
+ assertTrue(uuid_time <= endTime,
+ "UUID: " + i + " timestamp: " + uuid_time + " was not before the end time: " + endTime);
}
}
@@ -1064,10 +1055,9 @@ private void checkUUIDArrayForCorrectEthernetAddress(UUID[] uuidArray,
byte[] uuid_ethernet_address = new byte[6];
System.arraycopy(UUIDUtil.asByteArray(uuidArray[i]), 10, uuid_ethernet_address, 0, 6);
byte[] ethernet_address = ethernetAddress.asByteArray();
-
- assertTrue(
- "UUID ethernet address did not equal passed ethernetAddress",
- Arrays.equals(ethernet_address, uuid_ethernet_address));
+
+ assertTrue(Arrays.equals(ethernet_address, uuid_ethernet_address),
+ "UUID ethernet address did not equal passed ethernetAddress");
}
}
diff --git a/src/test/java/com/fasterxml/uuid/UUIDTest.java b/src/test/java/com/fasterxml/uuid/UUIDTest.java
index d688718..1a5cdea 100644
--- a/src/test/java/com/fasterxml/uuid/UUIDTest.java
+++ b/src/test/java/com/fasterxml/uuid/UUIDTest.java
@@ -17,10 +17,8 @@
package com.fasterxml.uuid;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-import junit.textui.TestRunner;
+import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.*;
import java.util.Arrays;
import java.util.UUID;
@@ -32,26 +30,10 @@
*
* @author Eric Bie
*/
-public class UUIDTest extends TestCase
+public class UUIDTest
{
final static UUID nullUUID = UUIDUtil.nilUUID();
- public UUIDTest(java.lang.String testName)
- {
- super(testName);
- }
-
- public static Test suite()
- {
- TestSuite suite = new TestSuite(UUIDTest.class);
- return suite;
- }
-
- public static void main(String[] args)
- {
- TestRunner.run(suite());
- }
-
/**************************************************************************
* Begin constructor tests
*************************************************************************/
@@ -59,6 +41,8 @@ public static void main(String[] args)
/**
* Test of UUID() constructor, of class com.fasterxml.uuid.UUID.
*/
+ @Test
+
public void testDefaultUUIDConstructor()
{
// this test technically relies on the toString() and toByteArray()
@@ -66,16 +50,15 @@ public void testDefaultUUIDConstructor()
// If it fails, that is fine... the test only needs to indicate
// proper working behavior or that it needs to be fixed.
UUID uuid = nullUUID;
- assertEquals("Default constructor did not create expected null UUID",
- NULL_UUID_STRING,
- uuid.toString());
- assertTrue("Expected array did not equal actual array",
- Arrays.equals(NULL_UUID_BYTE_ARRAY, UUIDUtil.asByteArray(uuid)));
+ assertEquals(NULL_UUID_STRING, uuid.toString(), "Default constructor did not create expected null UUID");
+ assertTrue(Arrays.equals(NULL_UUID_BYTE_ARRAY, UUIDUtil.asByteArray(uuid)), "Expected array did not equal actual array");
}
/**
* Test of UUID(byte[]) constructor, of class com.fasterxml.uuid.UUID.
*/
+ @Test
+
public void testByteArrayUUIDConstructor()
{
// passing array that is too small
@@ -93,28 +76,23 @@ public void testByteArrayUUIDConstructor()
// test that creating a uuid from an zero'd array
// gives us a null UUID (definition of a null UUID)
UUID uuid = UUIDUtil.uuid(new byte[UUID_BYTE_ARRAY_LENGTH]);
- assertEquals("constructor did not create expected null UUID",
- NULL_UUID_STRING,
- uuid.toString());
- assertTrue("Expected array did not equal actual array",
- Arrays.equals(NULL_UUID_BYTE_ARRAY, UUIDUtil.asByteArray(uuid)));
+ assertEquals(NULL_UUID_STRING, uuid.toString(), "constructor did not create expected null UUID");
+ assertTrue(Arrays.equals(NULL_UUID_BYTE_ARRAY, UUIDUtil.asByteArray(uuid)), "Expected array did not equal actual array");
// test creating an array from a good byte array
uuid = UUIDUtil.uuid(VALID_UUID_BYTE_ARRAY);
- assertEquals("constructor did not create expected UUID",
- MIXED_CASE_VALID_UUID_STRING.toLowerCase(),
- uuid.toString().toLowerCase());
+ assertEquals(MIXED_CASE_VALID_UUID_STRING.toLowerCase(), uuid.toString().toLowerCase(), "constructor did not create expected UUID");
// test creating an array from a good byte array with extra data on end
uuid = UUIDUtil.uuid(VALID_UUID_BYTE_ARRAY_WITH_EXTRA_END);
- assertEquals("constructor did not create expected UUID",
- MIXED_CASE_VALID_UUID_STRING.toLowerCase(),
- uuid.toString().toLowerCase());
+ assertEquals(MIXED_CASE_VALID_UUID_STRING.toLowerCase(), uuid.toString().toLowerCase(), "constructor did not create expected UUID");
}
/**
* Test of UUID(String) constructor, of class com.fasterxml.uuid.UUID.
*/
+ @Test
+
public void testStringUUIDConstructor()
{
// test a null string case
@@ -155,6 +133,8 @@ public void testStringUUIDConstructor()
/**
* Test of asByteArray method, of class com.fasterxml.uuid.UUID.
*/
+ @Test
+
public void testAsByteArray()
{
// we'll test making a couple UUIDs and then check that the asByteArray
@@ -162,44 +142,34 @@ public void testAsByteArray()
// first we'll test the null uuid
UUID uuid = nullUUID;
- assertEquals("Expected length of returned array wrong",
- UUID_BYTE_ARRAY_LENGTH,
- UUIDUtil.asByteArray(uuid).length);
- assertTrue("Expected array did not equal actual array",
- Arrays.equals(NULL_UUID_BYTE_ARRAY, UUIDUtil.asByteArray(uuid)));
+ assertEquals(UUID_BYTE_ARRAY_LENGTH, UUIDUtil.asByteArray(uuid).length, "Expected length of returned array wrong");
+ assertTrue(Arrays.equals(NULL_UUID_BYTE_ARRAY, UUIDUtil.asByteArray(uuid)), "Expected array did not equal actual array");
// now test a non-null uuid
uuid = UUIDUtil.uuid(MIXED_CASE_VALID_UUID_STRING);
- assertEquals("Expected length of returned array wrong",
- UUID_BYTE_ARRAY_LENGTH,
- UUIDUtil.asByteArray(uuid).length);
- assertTrue("Expected array did not equal actual array",
- Arrays.equals(VALID_UUID_BYTE_ARRAY, UUIDUtil.asByteArray(uuid)));
+ assertEquals(UUID_BYTE_ARRAY_LENGTH, UUIDUtil.asByteArray(uuid).length, "Expected length of returned array wrong");
+ assertTrue(Arrays.equals(VALID_UUID_BYTE_ARRAY, UUIDUtil.asByteArray(uuid)), "Expected array did not equal actual array");
// let's make sure that changing the returned array doesn't mess with
// the wrapped UUID's internals
uuid = UUIDUtil.uuid(MIXED_CASE_VALID_UUID_STRING);
- assertEquals("Expected length of returned array wrong",
- UUID_BYTE_ARRAY_LENGTH,
- UUIDUtil.asByteArray(uuid).length);
- assertTrue("Expected array did not equal actual array",
- Arrays.equals(VALID_UUID_BYTE_ARRAY, UUIDUtil.asByteArray(uuid)));
+ assertEquals(UUID_BYTE_ARRAY_LENGTH, UUIDUtil.asByteArray(uuid).length, "Expected length of returned array wrong");
+ assertTrue(Arrays.equals(VALID_UUID_BYTE_ARRAY, UUIDUtil.asByteArray(uuid)), "Expected array did not equal actual array");
byte[] test_byte_array = UUIDUtil.asByteArray(uuid);
// now stir it up a bit and then check that the original UUID was
// not changed in the process. The easiest stir is to sort it ;)
Arrays.sort(test_byte_array);
- assertFalse("Expected array was equal other array",
- Arrays.equals(VALID_UUID_BYTE_ARRAY, test_byte_array));
- assertFalse("Expected array was equal other array",
- Arrays.equals(UUIDUtil.asByteArray(uuid), test_byte_array));
- assertTrue("Expected array did not equal actual array",
- Arrays.equals(VALID_UUID_BYTE_ARRAY, UUIDUtil.asByteArray(uuid)));
+ assertFalse(Arrays.equals(VALID_UUID_BYTE_ARRAY, test_byte_array), "Expected array was equal other array");
+ assertFalse(Arrays.equals(UUIDUtil.asByteArray(uuid), test_byte_array), "Expected array was equal other array");
+ assertTrue(Arrays.equals(VALID_UUID_BYTE_ARRAY, UUIDUtil.asByteArray(uuid)), "Expected array did not equal actual array");
}
/**
* Test of compareTo method, of class com.fasterxml.uuid.UUID.
*/
+ @Test
+
public void testCompareTo()
{
// first, let's make sure calling compareTo with null
@@ -331,66 +301,65 @@ public void testCompareTo()
/**
* Test of equals method, of class com.fasterxml.uuid.UUID.
*/
+ @Test
+
public void testEquals()
{
// test passing null to equals returns false
// (as specified in the JDK docs for Object)
UUID x = UUIDUtil.uuid(VALID_UUID_BYTE_ARRAY);
- assertFalse("equals(null) didn't return false", x.equals((Object)null));
+ assertFalse(x.equals((Object)null), "equals(null) didn't return false");
// test that passing an object which is not a UUID returns false
- assertFalse("x.equals(non_UUID_object) didn't return false", x.equals(new Object()));
+ assertFalse(x.equals(new Object()), "x.equals(non_UUID_object) didn't return false");
// test a case where two UUIDs are definitly not equal
UUID w = UUIDUtil.uuid(ANOTHER_VALID_UUID_BYTE_ARRAY);
- assertFalse("x.equals(w) didn't return false", x.equals(w));
+ assertFalse(x.equals(w), "x.equals(w) didn't return false");
// test refelexivity
- assertTrue("x.equals(x) didn't return true", x.equals(x));
+ assertTrue(x.equals(x), "x.equals(x) didn't return true");
// test symmetry
UUID y = UUIDUtil.uuid(VALID_UUID_BYTE_ARRAY);
- assertTrue("y.equals(x) didn't return true", y.equals(x));
- assertTrue("x.equals(y) didn't return true", x.equals(y));
+ assertTrue(y.equals(x), "y.equals(x) didn't return true");
+ assertTrue(x.equals(y), "x.equals(y) didn't return true");
// now we'll test transitivity
UUID z = UUIDUtil.uuid(VALID_UUID_BYTE_ARRAY);
- assertTrue("x.equals(y) didn't return true", x.equals(y));
- assertTrue("y.equals(z) didn't return true", y.equals(z));
- assertTrue("x.equals(z) didn't return true", x.equals(z));
+ assertTrue(x.equals(y), "x.equals(y) didn't return true");
+ assertTrue(y.equals(z), "y.equals(z) didn't return true");
+ assertTrue(x.equals(z), "x.equals(z) didn't return true");
// test consistancy (this test is just calling equals multiple times)
- assertTrue("x.equals(y) didn't return true", x.equals(y));
- assertTrue("x.equals(y) didn't return true", x.equals(y));
- assertTrue("x.equals(y) didn't return true", x.equals(y));
+ assertTrue(x.equals(y), "x.equals(y) didn't return true");
+ assertTrue(x.equals(y), "x.equals(y) didn't return true");
+ assertTrue(x.equals(y), "x.equals(y) didn't return true");
}
/**
* Test of getNullUUID method, of class com.fasterxml.uuid.UUID.
*/
+ @Test
+
public void testGetNullUUID()
{
UUID uuid = nullUUID;
- assertEquals("getNullUUID did not create expected null UUID",
- NULL_UUID_STRING,
- uuid.toString());
- assertTrue("Expected array did not equal actual array",
- Arrays.equals(NULL_UUID_BYTE_ARRAY, UUIDUtil.asByteArray(uuid)));
+ assertEquals(NULL_UUID_STRING, uuid.toString(), "getNullUUID did not create expected null UUID");
+ assertTrue(Arrays.equals(NULL_UUID_BYTE_ARRAY, UUIDUtil.asByteArray(uuid)), "Expected array did not equal actual array");
// also, validate that getNullUUID is getting the same null each time
UUID uuid2 = nullUUID;
- assertEquals("getNullUUID did not create expected null UUID",
- NULL_UUID_STRING,
- uuid2.toString());
- assertTrue("Expected array did not equal actual array",
- Arrays.equals(NULL_UUID_BYTE_ARRAY, UUIDUtil.asByteArray(uuid2)));
- assertTrue("two returned null UUIDs were not the sam object instance",
- uuid == uuid2);
+ assertEquals(NULL_UUID_STRING, uuid2.toString(), "getNullUUID did not create expected null UUID");
+ assertTrue(Arrays.equals(NULL_UUID_BYTE_ARRAY, UUIDUtil.asByteArray(uuid2)), "Expected array did not equal actual array");
+ assertTrue(uuid == uuid2, "two returned null UUIDs were not the sam object instance");
}
/**
* Test of getType method, of class com.fasterxml.uuid.UUID.
*/
+ @Test
+
public void testGetType()
{
// here we will test that UUID's constructed with the right type
@@ -398,49 +367,35 @@ public void testGetType()
// test creating a null UUID
UUID uuid = nullUUID;
- assertTrue("Expected array did not equal actual array",
- Arrays.equals(NULL_UUID_BYTE_ARRAY, UUIDUtil.asByteArray(uuid)));
- assertEquals("Expected type was not returned",
- UUIDUtil.typeOf(nullUUID),
- UUIDUtil.typeOf(uuid));
+ assertTrue(Arrays.equals(NULL_UUID_BYTE_ARRAY, UUIDUtil.asByteArray(uuid)), "Expected array did not equal actual array");
+ assertEquals(UUIDUtil.typeOf(nullUUID), UUIDUtil.typeOf(uuid), "Expected type was not returned");
// test Random UUID in this case
uuid = UUIDUtil.uuid(VALID_UUID_BYTE_ARRAY);
- assertTrue("Expected array did not equal actual array",
- Arrays.equals(VALID_UUID_BYTE_ARRAY, UUIDUtil.asByteArray(uuid)));
- assertEquals("Expected type was not returned",
- UUIDType.RANDOM_BASED,
- UUIDUtil.typeOf(uuid));
+ assertTrue(Arrays.equals(VALID_UUID_BYTE_ARRAY, UUIDUtil.asByteArray(uuid)), "Expected array did not equal actual array");
+ assertEquals(UUIDType.RANDOM_BASED, UUIDUtil.typeOf(uuid), "Expected type was not returned");
// test time based UUID in this case
uuid = UUIDUtil.uuid(UUIDUtil.asByteArray(TIME1_MAC1_UUID));
- assertEquals("constructor did not create expected UUID",
- TIME1_MAC1_UUID.toString().toLowerCase(),
- uuid.toString().toLowerCase());
- assertEquals("Expected type was not returned",
- UUIDType.TIME_BASED,
- UUIDUtil.typeOf(uuid));
+ assertEquals(TIME1_MAC1_UUID.toString().toLowerCase(), uuid.toString().toLowerCase(), "constructor did not create expected UUID");
+ assertEquals(UUIDType.TIME_BASED, UUIDUtil.typeOf(uuid), "Expected type was not returned");
// test name based UUID in this case
uuid = UUIDUtil.uuid(NAME_BASED_UUID_STRING);
- assertTrue("Expected array did not equal actual array",
- Arrays.equals(NAME_BASED_UUID_BYTE_ARRAY, UUIDUtil.asByteArray(uuid)));
- assertEquals("Expected type was not returned",
- UUIDType.NAME_BASED_MD5,
- UUIDUtil.typeOf(uuid));
+ assertTrue(Arrays.equals(NAME_BASED_UUID_BYTE_ARRAY, UUIDUtil.asByteArray(uuid)), "Expected array did not equal actual array");
+ assertEquals(UUIDType.NAME_BASED_MD5, UUIDUtil.typeOf(uuid), "Expected type was not returned");
// test DCE based UUID in this case
uuid = UUIDUtil.uuid(DCE_BASED_UUID_BYTE_ARRAY);
- assertTrue("Expected array did not equal actual array",
- Arrays.equals(DCE_BASED_UUID_BYTE_ARRAY, UUIDUtil.asByteArray(uuid)));
- assertEquals("Expected type was not returned",
- UUIDType.DCE,
- UUIDUtil.typeOf(uuid));
+ assertTrue(Arrays.equals(DCE_BASED_UUID_BYTE_ARRAY, UUIDUtil.asByteArray(uuid)), "Expected array did not equal actual array");
+ assertEquals(UUIDType.DCE, UUIDUtil.typeOf(uuid), "Expected type was not returned");
}
/**
* Test of hashCode method, of class com.fasterxml.uuid.UUID.
*/
+ @Test
+
public void testHashCode()
{
// as lifted from the JDK Object JavaDocs:
@@ -452,27 +407,18 @@ public void testHashCode()
// execution of an application to another execution of the
// same application
UUID x = UUIDUtil.uuid(VALID_UUID_BYTE_ARRAY);
- assertTrue("x.equals(x) didn't return true",
- x.equals(x));
- assertEquals("x.hashCode() didn't equal x.hashCode()",
- x.hashCode(),
- x.hashCode());
- assertEquals("x.hashCode() didn't equal x.hashCode()",
- x.hashCode(),
- x.hashCode());
+ assertTrue(x.equals(x), "x.equals(x) didn't return true");
+ assertEquals(x.hashCode(), x.hashCode(), "x.hashCode() didn't equal x.hashCode()");
+ assertEquals(x.hashCode(), x.hashCode(), "x.hashCode() didn't equal x.hashCode()");
// as lifted from the JDK Object JavaDocs:
// If two objects are equal according to the equals(Object) method,
// then calling the hashCode method on each of the two objects
// must produce the same integer result
UUID y = UUIDUtil.uuid(VALID_UUID_BYTE_ARRAY);
- assertFalse("x == y didn't return false",
- x == y);
- assertTrue("x.equals(y) didn't return true",
- x.equals(y));
- assertEquals("x.hashCode() didn't equal y.hashCode()",
- x.hashCode(),
- y.hashCode());
+ assertFalse(x == y, "x == y didn't return false");
+ assertTrue(x.equals(y), "x.equals(y) didn't return true");
+ assertEquals(x.hashCode(), y.hashCode(), "x.hashCode() didn't equal y.hashCode()");
// it is not REQUIRED that hashCode return different ints for different
// objects where x.equals(z) is not true.
@@ -482,6 +428,8 @@ public void testHashCode()
/**
* Test of isNullUUID method, of class com.fasterxml.uuid.UUID.
*/
+ @Test
+
public void testIsNullUUID()
{
// this test will test isNullUUID using the five main ways you could
@@ -520,6 +468,8 @@ private void assertIsNullUUID(UUID uuid) {
/**
* Test of toByteArray() method, of class com.fasterxml.uuid.UUID.
*/
+ @Test
+
public void testToByteArray()
{
// we'll test making a couple UUIDs and then check that the toByteArray
@@ -527,43 +477,33 @@ public void testToByteArray()
// first we'll test the null uuid
UUID uuid = nullUUID;
- assertEquals("Expected length of returned array wrong",
- UUID_BYTE_ARRAY_LENGTH,
- UUIDUtil.asByteArray(uuid).length);
- assertTrue("Expected array did not equal actual array",
- Arrays.equals(NULL_UUID_BYTE_ARRAY, UUIDUtil.asByteArray(uuid)));
+ assertEquals(UUID_BYTE_ARRAY_LENGTH, UUIDUtil.asByteArray(uuid).length, "Expected length of returned array wrong");
+ assertTrue(Arrays.equals(NULL_UUID_BYTE_ARRAY, UUIDUtil.asByteArray(uuid)), "Expected array did not equal actual array");
// now test a non-null uuid
uuid = UUIDUtil.uuid(MIXED_CASE_VALID_UUID_STRING);
- assertEquals("Expected length of returned array wrong",
- UUID_BYTE_ARRAY_LENGTH,
- UUIDUtil.asByteArray(uuid).length);
- assertTrue("Expected array did not equal actual array",
- Arrays.equals(VALID_UUID_BYTE_ARRAY, UUIDUtil.asByteArray(uuid)));
+ assertEquals(UUID_BYTE_ARRAY_LENGTH, UUIDUtil.asByteArray(uuid).length, "Expected length of returned array wrong");
+ assertTrue(Arrays.equals(VALID_UUID_BYTE_ARRAY, UUIDUtil.asByteArray(uuid)), "Expected array did not equal actual array");
// let's make sure that changing the returned array doesn't mess with
// the wrapped UUID's internals
uuid = UUIDUtil.uuid(MIXED_CASE_VALID_UUID_STRING);
- assertEquals("Expected length of returned array wrong",
- UUID_BYTE_ARRAY_LENGTH,
- UUIDUtil.asByteArray(uuid).length);
- assertTrue("Expected array did not equal actual array",
- Arrays.equals(VALID_UUID_BYTE_ARRAY, UUIDUtil.asByteArray(uuid)));
+ assertEquals(UUID_BYTE_ARRAY_LENGTH, UUIDUtil.asByteArray(uuid).length, "Expected length of returned array wrong");
+ assertTrue(Arrays.equals(VALID_UUID_BYTE_ARRAY, UUIDUtil.asByteArray(uuid)), "Expected array did not equal actual array");
byte[] test_byte_array = UUIDUtil.asByteArray(uuid);
// now stir it up a bit and then check that the original UUID was
// not changed in the process. The easiest stir is to sort it ;)
Arrays.sort(test_byte_array);
- assertFalse("Expected array was equal other array",
- Arrays.equals(VALID_UUID_BYTE_ARRAY, test_byte_array));
- assertFalse("Expected array was equal other array",
- Arrays.equals(UUIDUtil.asByteArray(uuid), test_byte_array));
- assertTrue("Expected array did not equal actual array",
- Arrays.equals(VALID_UUID_BYTE_ARRAY, UUIDUtil.asByteArray(uuid)));
+ assertFalse(Arrays.equals(VALID_UUID_BYTE_ARRAY, test_byte_array), "Expected array was equal other array");
+ assertFalse(Arrays.equals(UUIDUtil.asByteArray(uuid), test_byte_array), "Expected array was equal other array");
+ assertTrue(Arrays.equals(VALID_UUID_BYTE_ARRAY, UUIDUtil.asByteArray(uuid)), "Expected array did not equal actual array");
}
/**
* Test of toByteArray(byte[]) method, of class com.fasterxml.uuid.UUID.
*/
+ @Test
+
public void testToByteArrayDest()
{
// constant for use in this test
@@ -614,14 +554,12 @@ public void testToByteArrayDest()
UUID test_uuid = nullUUID;
byte[] test_array = new byte[UUID_BYTE_ARRAY_LENGTH];
UUIDUtil.toByteArray(test_uuid, test_array);
- assertTrue("Expected array did not equal actual array",
- Arrays.equals(NULL_UUID_BYTE_ARRAY, test_array));
+ assertTrue(Arrays.equals(NULL_UUID_BYTE_ARRAY, test_array), "Expected array did not equal actual array");
// now test a non-null uuid
test_uuid = UUIDUtil.uuid(MIXED_CASE_VALID_UUID_STRING);
UUIDUtil.toByteArray(test_uuid, test_array);
- assertTrue("Expected array did not equal actual array",
- Arrays.equals(VALID_UUID_BYTE_ARRAY, test_array));
+ assertTrue(Arrays.equals(VALID_UUID_BYTE_ARRAY, test_array), "Expected array did not equal actual array");
// now test a null uuid case with extra data in the array
test_uuid = nullUUID;
@@ -630,15 +568,11 @@ public void testToByteArrayDest()
UUIDUtil.toByteArray(test_uuid, test_array);
for (int i = 0; i < UUID_BYTE_ARRAY_LENGTH; ++i)
{
- assertEquals("Expected array values did not match",
- NULL_UUID_BYTE_ARRAY[i],
- test_array[i]);
+ assertEquals(NULL_UUID_BYTE_ARRAY[i], test_array[i], "Expected array values did not match");
}
for (int i = 0; i < EXTRA_DATA_LENGTH; i++)
{
- assertEquals("Expected array fill value changed",
- (byte)'x',
- test_array[i + UUID_BYTE_ARRAY_LENGTH]);
+ assertEquals((byte)'x', test_array[i + UUID_BYTE_ARRAY_LENGTH], "Expected array fill value changed");
}
// now test a good uuid case with extra data in the array
@@ -648,15 +582,11 @@ public void testToByteArrayDest()
UUIDUtil.toByteArray(test_uuid, test_array);
for (int i = 0; i < UUID_BYTE_ARRAY_LENGTH; ++i)
{
- assertEquals("Expected array values did not match",
- VALID_UUID_BYTE_ARRAY[i],
- test_array[i]);
+ assertEquals(VALID_UUID_BYTE_ARRAY[i], test_array[i], "Expected array values did not match");
}
for (int i = 0; i < EXTRA_DATA_LENGTH; i++)
{
- assertEquals("Expected array fill value changed",
- (byte)'x',
- test_array[i + UUID_BYTE_ARRAY_LENGTH]);
+ assertEquals((byte)'x', test_array[i + UUID_BYTE_ARRAY_LENGTH], "Expected array fill value changed");
}
}
@@ -664,6 +594,8 @@ public void testToByteArrayDest()
* Test of toByteArray(byte[], int) method,
* of class com.fasterxml.uuid.UUID.
*/
+ @Test
+
public void testToByteArrayDestOffset()
{
// constant value for use in this test
@@ -734,14 +666,12 @@ public void testToByteArrayDestOffset()
UUID test_uuid = nullUUID;
byte[] test_array = new byte[UUID_BYTE_ARRAY_LENGTH];
UUIDUtil.toByteArray(test_uuid, test_array, 0);
- assertTrue("Expected array did not equal actual array",
- Arrays.equals(NULL_UUID_BYTE_ARRAY, test_array));
+ assertTrue(Arrays.equals(NULL_UUID_BYTE_ARRAY, test_array), "Expected array did not equal actual array");
// now test a non-null uuid
test_uuid = UUIDUtil.uuid(MIXED_CASE_VALID_UUID_STRING);
UUIDUtil.toByteArray(test_uuid, test_array);
- assertTrue("Expected array did not equal actual array",
- Arrays.equals(VALID_UUID_BYTE_ARRAY, test_array));
+ assertTrue(Arrays.equals(VALID_UUID_BYTE_ARRAY, test_array), "Expected array did not equal actual array");
// now test a null uuid case with extra data in the array
test_uuid = nullUUID;
@@ -749,14 +679,10 @@ public void testToByteArrayDestOffset()
Arrays.fill(test_array, (byte)'x');
UUIDUtil.toByteArray(test_uuid, test_array, 0);
for (int i = 0; i < UUID_BYTE_ARRAY_LENGTH; ++i) {
- assertEquals("Expected array values did not match",
- NULL_UUID_BYTE_ARRAY[i],
- test_array[i]);
+ assertEquals(NULL_UUID_BYTE_ARRAY[i], test_array[i], "Expected array values did not match");
}
for (int i = 0; i < EXTRA_DATA_LENGTH; i++) {
- assertEquals("Expected array fill value changed",
- (byte)'x',
- test_array[i + UUID_BYTE_ARRAY_LENGTH]);
+ assertEquals((byte)'x', test_array[i + UUID_BYTE_ARRAY_LENGTH], "Expected array fill value changed");
}
// now test a null uuid case with extra data in the array
@@ -766,18 +692,12 @@ public void testToByteArrayDestOffset()
UUIDUtil.toByteArray(test_uuid, test_array, EXTRA_DATA_LENGTH/2);
// first check the data (in the middle of the array)
for (int i = 0; i < UUID_BYTE_ARRAY_LENGTH; ++i) {
- assertEquals("Expected array values did not match (offset "+i+")",
- NULL_UUID_BYTE_ARRAY[i],
- test_array[i + EXTRA_DATA_LENGTH/2]);
+ assertEquals(NULL_UUID_BYTE_ARRAY[i], test_array[i + EXTRA_DATA_LENGTH/2], "Expected array values did not match (offset "+i+")");
}
// and now check that the surrounding bytes were not changed
for (int i = 0; i < EXTRA_DATA_LENGTH/2; ++i) {
- assertEquals("Expected array fill value changed",
- (byte)'x',
- test_array[i]);
- assertEquals("Expected array fill value changed",
- (byte)'x',
- test_array[i + UUID_BYTE_ARRAY_LENGTH + EXTRA_DATA_LENGTH/2]);
+ assertEquals((byte)'x', test_array[i], "Expected array fill value changed");
+ assertEquals((byte)'x', test_array[i + UUID_BYTE_ARRAY_LENGTH + EXTRA_DATA_LENGTH/2], "Expected array fill value changed");
}
// now test a good uuid case with extra data in the array
@@ -786,14 +706,10 @@ public void testToByteArrayDestOffset()
Arrays.fill(test_array, (byte)'x');
UUIDUtil.toByteArray(test_uuid, test_array, 0);
for (int i = 0; i < UUID_BYTE_ARRAY_LENGTH; ++i) {
- assertEquals("Expected array values did not match",
- VALID_UUID_BYTE_ARRAY[i],
- test_array[i]);
+ assertEquals(VALID_UUID_BYTE_ARRAY[i], test_array[i], "Expected array values did not match");
}
for (int i = 0; i < EXTRA_DATA_LENGTH; i++) {
- assertEquals("Expected array fill value changed",
- (byte)'x',
- test_array[i + UUID_BYTE_ARRAY_LENGTH]);
+ assertEquals((byte)'x', test_array[i + UUID_BYTE_ARRAY_LENGTH], "Expected array fill value changed");
}
// now test a good uuid case with extra data in the array
@@ -804,24 +720,20 @@ public void testToByteArrayDestOffset()
UUIDUtil.toByteArray(test_uuid, test_array, EXTRA_DATA_LENGTH/2);
// first check the data (in the middle of the array)
for (int i = 0; i < UUID_BYTE_ARRAY_LENGTH; ++i) {
- assertEquals("Expected array values did not match",
- VALID_UUID_BYTE_ARRAY[i],
- test_array[i + EXTRA_DATA_LENGTH/2]);
+ assertEquals(VALID_UUID_BYTE_ARRAY[i], test_array[i + EXTRA_DATA_LENGTH/2], "Expected array values did not match");
}
// and now check that the surrounding bytes were not changed
for (int i = 0; i < EXTRA_DATA_LENGTH/2; ++i) {
- assertEquals("Expected array fill value changed",
- (byte)'x',
- test_array[i]);
- assertEquals("Expected array fill value changed",
- (byte)'x',
- test_array[i + UUID_BYTE_ARRAY_LENGTH + EXTRA_DATA_LENGTH/2]);
+ assertEquals((byte)'x', test_array[i], "Expected array fill value changed");
+ assertEquals((byte)'x', test_array[i + UUID_BYTE_ARRAY_LENGTH + EXTRA_DATA_LENGTH/2], "Expected array fill value changed");
}
}
/**
* Test of toString method, of class com.fasterxml.uuid.UUID.
*/
+ @Test
+
public void testToString()
{
// test making a couple UUIDs and then check that the toString
@@ -829,15 +741,11 @@ public void testToString()
// test the null uuid
UUID uuid = nullUUID;
- assertEquals("null uuid string and toString did not match",
- NULL_UUID_STRING.toLowerCase(),
- uuid.toString().toLowerCase());
+ assertEquals(NULL_UUID_STRING.toLowerCase(), uuid.toString().toLowerCase(), "null uuid string and toString did not match");
// test a non-null uuid
uuid = UUIDUtil.uuid(VALID_UUID_BYTE_ARRAY);
- assertEquals("uuid string and toString results did not match",
- MIXED_CASE_VALID_UUID_STRING.toLowerCase(),
- uuid.toString().toLowerCase());
+ assertEquals(MIXED_CASE_VALID_UUID_STRING.toLowerCase(), uuid.toString().toLowerCase(), "uuid string and toString results did not match");
// The current UUID implementation returns strings all lowercase.
// Although relying on this behavior in code is not recommended,
@@ -845,19 +753,18 @@ public void testToString()
// becomes bad. This will act as an early warning to anyone
// who relies on this particular behavior.
uuid = UUIDUtil.uuid(VALID_UUID_BYTE_ARRAY);
- assertFalse("mixed case uuid string and toString " +
- "matched (expected toString to be all lower case)",
- MIXED_CASE_VALID_UUID_STRING.equals(uuid.toString()));
- assertEquals("mixed case string toLowerCase and " +
+ assertFalse(MIXED_CASE_VALID_UUID_STRING.equals(uuid.toString()), "mixed case uuid string and toString " +
+ "matched (expected toString to be all lower case)");
+ assertEquals(MIXED_CASE_VALID_UUID_STRING.toLowerCase(), uuid.toString(), "mixed case string toLowerCase and " +
"toString results did not match (expected toString to " +
- "be all lower case)",
- MIXED_CASE_VALID_UUID_STRING.toLowerCase(),
- uuid.toString());
+ "be all lower case)");
}
/**
* Test of valueOf(String) method, of class com.fasterxml.uuid.UUID.
*/
+ @Test
+
public void testValueOfString()
{
// test some failure cases for the string constructor
@@ -910,9 +817,7 @@ private void goodStringUUIDConstructorHelper(String uuidString)
fail("Caught unexpected exception: " + ex);
}
- assertEquals("uuid strings were not equal",
- uuidString.toLowerCase(),
- temp_uuid.toString().toLowerCase());
+ assertEquals(uuidString.toLowerCase(), temp_uuid.toString().toLowerCase(), "uuid strings were not equal");
}
private void badStringValueOfHelper(String uuidString)
@@ -945,38 +850,34 @@ private void goodStringValueOfHelper(String uuidString)
fail("Caught unexpected exception: " + ex);
}
- assertEquals("UUID strings were not equal",
- uuidString.toLowerCase(),
- temp_uuid.toString().toLowerCase());
+ assertEquals(uuidString.toLowerCase(), temp_uuid.toString().toLowerCase(), "UUID strings were not equal");
}
private void assertUUIDsMatchHelper(UUID expected, UUID actual)
{
// technically, toString will always return lowercase uuid strings,
// but just to be paranoid, we will always do toLowerCase in this test
- assertEquals("UUID strings did not match",
- expected.toString().toLowerCase(),
- actual.toString().toLowerCase());
+ assertEquals(expected.toString().toLowerCase(), actual.toString().toLowerCase(), "UUID strings did not match");
- assertEquals("UUID equals did not match",
- expected,
- actual);
+ assertEquals(expected, actual, "UUID equals did not match");
}
private void assertUUIDEqualOrderHelper(UUID uuid1, UUID uuid2)
{
- assertTrue(uuid1 + " did not test as equal to " + uuid2,
- 0 == UUIDComparator.staticCompare(uuid1, uuid2));
- assertTrue(uuid2 + " did not test as equal to " + uuid1,
- 0 == UUIDComparator.staticCompare(uuid2, uuid1));
+ assertTrue(
+ 0 == UUIDComparator.staticCompare(uuid1, uuid2),
+ uuid1 + " did not test as equal to " + uuid2);
+ assertTrue(
+ 0 == UUIDComparator.staticCompare(uuid2, uuid1),
+ uuid2 + " did not test as equal to " + uuid1);
}
private void assertUUIDGreaterOrderHelper(UUID uuid1, UUID uuid2)
{
int diff = UUIDComparator.staticCompare(uuid1, uuid2);
- assertTrue(uuid1 + " did not test as larger than " + uuid2+", diff: "+diff, diff > 0);
+ assertTrue(diff > 0, uuid1 + " did not test as larger than " + uuid2+", diff: "+diff);
diff = UUIDComparator.staticCompare(uuid2, uuid1);
- assertTrue(uuid2 + " did not test as smaller than " + uuid1+", diff: "+diff, diff < 0);
+ assertTrue(diff < 0, uuid2 + " did not test as smaller than " + uuid1+", diff: "+diff);
}
/**************************************************************************
* End private helper functions for use in tests
diff --git a/src/test/java/com/fasterxml/uuid/UUIDTimerTest.java b/src/test/java/com/fasterxml/uuid/UUIDTimerTest.java
index bb699b0..0d9c30d 100644
--- a/src/test/java/com/fasterxml/uuid/UUIDTimerTest.java
+++ b/src/test/java/com/fasterxml/uuid/UUIDTimerTest.java
@@ -17,6 +17,9 @@
package com.fasterxml.uuid;
+import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.*;
+
import java.io.IOException;
import java.security.SecureRandom;
import java.util.Arrays;
@@ -25,38 +28,17 @@
import java.util.Random;
import java.util.Set;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-import junit.textui.TestRunner;
-
/**
* JUnit Test class for the com.fasterxml.uuid.UUIDTimer class.
*
* @author Eric Bie
*/
-public class UUIDTimerTest extends TestCase
+public class UUIDTimerTest
{
// constants for use in the tests
private static final int UUID_TIMER_ARRAY_LENGTH = 10;
private static final int SIZE_OF_TEST_ARRAY = 10000;
- public UUIDTimerTest(java.lang.String testName)
- {
- super(testName);
- }
-
- public static Test suite()
- {
- TestSuite suite = new TestSuite(UUIDTimerTest.class);
- return suite;
- }
-
- public static void main(String[] args)
- {
- TestRunner.run(suite());
- }
-
/**************************************************************************
* Begin constructor tests
*************************************************************************/
@@ -64,6 +46,8 @@ public static void main(String[] args)
* Test of UUIDTimer(SecureRandom) constructor,
* of class com.fasterxml.uuid.UUIDTimer.
*/
+ @Test
+
public void testSecureRandomUUIDTimerConstructor() throws IOException
{
// try passing a null SecureRandom argument
@@ -94,6 +78,8 @@ public void testSecureRandomUUIDTimerConstructor() throws IOException
/**
* Test of getAndSetTimestamp method, of class com.fasterxml.uuid.UUIDTimer.
*/
+ @Test
+
public void testGetTimestamp() throws IOException
{
// constant for use in this test
@@ -135,9 +121,7 @@ public void testGetTimestamp() throws IOException
uuid_timer.getAndSetTimestamp(test_array);
for (int i = 0; i < EXTRA_DATA_LENGTH; ++i)
{
- assertEquals("test_array element was corrupted",
- (byte)'x',
- test_array[i + UUID_TIMER_ARRAY_LENGTH]);
+ assertEquals((byte)'x', test_array[i + UUID_TIMER_ARRAY_LENGTH], "test_array element was corrupted");
}
// check that the timer portion is not all null
assertArrayNotEqual(test_array,
@@ -184,6 +168,8 @@ public void testGetTimestamp() throws IOException
* Test of reproducibility of getTimestamp method, of class
* com.fasterxml.uuid.UUIDTimer.
*/
+ @Test
+
public void testGetTimestampReproducible() throws IOException
{
final long seed = new Random().nextLong();
@@ -257,9 +243,7 @@ private void checkUUIDTimerLongArrayForCorrectOrdering(
{
// now we'll clone the array and reverse it
Long[] uuid_timer_sorted_arrays = (Long[])uuidTimerLongArray.clone();
- assertEquals("Cloned array length did not match",
- uuidTimerLongArray.length,
- uuid_timer_sorted_arrays.length);
+ assertEquals(uuidTimerLongArray.length, uuid_timer_sorted_arrays.length, "Cloned array length did not match");
ReverseOrderUUIDTimerLongComparator rev_order_uuid_timer_comp =
new ReverseOrderUUIDTimerLongComparator();
@@ -269,14 +253,12 @@ private void checkUUIDTimerLongArrayForCorrectOrdering(
int sorted_arrays_length = uuid_timer_sorted_arrays.length;
for (int i = 0; i < sorted_arrays_length; i++)
{
- assertTrue(
- "Reverse order check on uuid timer arrays failed" +
+ assertTrue(uuidTimerLongArray[i].equals(
+ uuid_timer_sorted_arrays[sorted_arrays_length - (1 + i)]), "Reverse order check on uuid timer arrays failed" +
" on element " + i + ": " +
uuidTimerLongArray[i].longValue() + " does not equal " +
uuid_timer_sorted_arrays[
- sorted_arrays_length - (1 + i)].longValue(),
- uuidTimerLongArray[i].equals(
- uuid_timer_sorted_arrays[sorted_arrays_length - (1 + i)]));
+ sorted_arrays_length - (1 + i)].longValue());
}
// now let's sort the reversed array and check that it sorted to
@@ -284,12 +266,10 @@ private void checkUUIDTimerLongArrayForCorrectOrdering(
Arrays.sort(uuid_timer_sorted_arrays);
for (int i = 0; i < sorted_arrays_length; i++)
{
- assertTrue(
- "Same order check on uuid timer arrays failed on element " +
+ assertTrue(uuidTimerLongArray[i].equals(uuid_timer_sorted_arrays[i]), "Same order check on uuid timer arrays failed on element " +
i + ": " + uuidTimerLongArray[i].longValue() +
" does not equal " +
- uuid_timer_sorted_arrays[i].longValue(),
- uuidTimerLongArray[i].equals(uuid_timer_sorted_arrays[i]));
+ uuid_timer_sorted_arrays[i].longValue());
}
}
@@ -302,11 +282,8 @@ private void checkUUIDTimerLongArrayForUniqueness(Long[] uuidTimerLongArray)
Set set = new HashSet();
for (int i = 0; i < uuidTimerLongArray.length; i++)
{
- assertTrue("Uniqueness test failed on insert into HashSet",
- set.add(uuidTimerLongArray[i]));
- assertFalse(
- "Paranoia Uniqueness test failed (second insert into HashSet)",
- set.add(uuidTimerLongArray[i]));
+ assertTrue(set.add(uuidTimerLongArray[i]), "Uniqueness test failed on insert into HashSet");
+ assertFalse(set.add(uuidTimerLongArray[i]), "Paranoia Uniqueness test failed (second insert into HashSet)");
}
}
@@ -324,8 +301,7 @@ private void checkUUIDTimerLongArrayForCorrectCreationTime(
final long GREGORIAN_CALENDAR_START_TO_UTC_START_OFFSET =
122192928000000000L;
- assertTrue("Start time was not before the end time",
- startTime < endTime);
+ assertTrue(startTime < endTime, "Start time was not before the end time");
// let's check that all the uuid timer longs in the array have a
// timestamp which lands between the start and end time
@@ -340,14 +316,10 @@ private void checkUUIDTimerLongArrayForCorrectCreationTime(
uuid_time /= MILLI_CONVERSION_FACTOR;
// now check that the times are correct
- assertTrue(
- "Start time: " + startTime +
- " was not before UUID timestamp: " + uuid_time,
- startTime <= uuid_time);
- assertTrue(
- "UUID timestamp: " + uuid_time +
- " was not before the end time: " + endTime,
- uuid_time <= endTime);
+ assertTrue(startTime <= uuid_time, "Start time: " + startTime +
+ " was not before UUID timestamp: " + uuid_time);
+ assertTrue(uuid_time <= endTime, "UUID timestamp: " + uuid_time +
+ " was not before the end time: " + endTime);
}
}
@@ -356,17 +328,14 @@ private void checkUUIDTimerLongArrayForNonNullTimes(
{
for (int i = 0; i < uuidTimerLongArray.length; i++)
{
- assertFalse("Timer Long was null",
- 0 == uuidTimerLongArray[i].longValue());
+ assertFalse(0 == uuidTimerLongArray[i].longValue(), "Timer Long was null");
}
}
private void assertArrayNotEqual(byte[] array1, byte[] array2, int length)
{
- assertTrue("array1 was not equal or longer then length",
- array1.length >= length);
- assertTrue("array2 was not equal or longer then length",
- array2.length >= length);
+ assertTrue(array1.length >= length, "array1 was not equal or longer then length");
+ assertTrue(array2.length >= length, "array2 was not equal or longer then length");
for (int i = 0; i < length; ++i)
{
diff --git a/src/test/java/com/fasterxml/uuid/ext/LockedFileTest.java b/src/test/java/com/fasterxml/uuid/ext/LockedFileTest.java
index cb9db2e..20a82c8 100644
--- a/src/test/java/com/fasterxml/uuid/ext/LockedFileTest.java
+++ b/src/test/java/com/fasterxml/uuid/ext/LockedFileTest.java
@@ -1,24 +1,39 @@
package com.fasterxml.uuid.ext;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
+import java.nio.file.Path;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
import static com.fasterxml.uuid.ext.LockedFile.READ_ERROR;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
public class LockedFileTest
{
- @Rule
- public TemporaryFolder temporaryFolder = new TemporaryFolder();
+ @TempDir
+ Path temporaryFolder;
+
+ @BeforeAll
+ static void setUp() {
+ // Suppress logging during test
+ LockedFile.logging(false);
+ }
+
+ @AfterAll
+ static void tearDown() {
+ // Re-enable logging after tests
+ LockedFile.logging(true);
+
+ }
@Test
public void constructor_givenNull_shouldThrowNullPointerException() throws IOException {
@@ -33,7 +48,7 @@ public void constructor_givenNull_shouldThrowNullPointerException() throws IOExc
@Test
public void constructor_givenEmptyFile_shouldLeaveFileAsIs() throws IOException {
// given
- File emptyFile = temporaryFolder.newFile();
+ File emptyFile = Files.createTempFile(temporaryFolder, null, null).toFile();
// when
new LockedFile(emptyFile);
@@ -47,7 +62,7 @@ public void constructor_givenEmptyFile_shouldLeaveFileAsIs() throws IOException
@Test
public void constructor_givenNonExistentFile_shouldCreateANewFile() throws IOException {
// given
- File blankFile = temporaryFolder.newFile();
+ File blankFile = Files.createTempFile(temporaryFolder, null, null).toFile();
File nonExistentFile = new File(blankFile + ".nonexistent");
if (Files.exists(nonExistentFile.toPath())) {
@@ -66,7 +81,7 @@ public void constructor_givenNonExistentFile_shouldCreateANewFile() throws IOExc
@Test
public void constructor_canOnlyTakeAFile_shouldThrowFileNotFoundException() throws IOException {
// given
- File blankFolder = temporaryFolder.newFolder();
+ File blankFolder = Files.createTempDirectory(temporaryFolder, null).toFile();
// when
try {
@@ -84,7 +99,7 @@ public void constructor_canOnlyTakeAFile_shouldThrowFileNotFoundException() thro
@Test
public void readStamp_givenEmptyFile_shouldReturnREADERROR() throws IOException {
// given
- File emptyFile = temporaryFolder.newFile();
+ File emptyFile = Files.createTempFile(temporaryFolder, null, null).toFile();
// when
LockedFile lockedFile = new LockedFile(emptyFile);
@@ -97,7 +112,7 @@ public void readStamp_givenEmptyFile_shouldReturnREADERROR() throws IOException
@Test
public void readStamp_givenGibberishFile_shouldReturnREADERROR() throws IOException {
// given
- File gibberishFile = temporaryFolder.newFile();
+ File gibberishFile = Files.createTempFile(temporaryFolder, null, null).toFile();
try(FileWriter fileWriter = new FileWriter(gibberishFile)) {
fileWriter.write(UUID.randomUUID().toString().substring(0, 22));
fileWriter.flush();
@@ -116,7 +131,7 @@ public void readStamp_givenGibberishFile_shouldReturnREADERROR() throws IOExcept
@Test
public void readStamp_givenTimestampedFile_shouldReturnValueInside() throws IOException {
// given
- File timeStampedFile = temporaryFolder.newFile();
+ File timeStampedFile = Files.createTempFile(temporaryFolder, null, null).toFile();
try(FileWriter fileWriter = new FileWriter(timeStampedFile)) {
// we are faking the timestamp format
fileWriter.write("[0x0000000000000001]");
@@ -136,7 +151,7 @@ public void readStamp_givenTimestampedFile_shouldReturnValueInside() throws IOEx
@Test
public void readStamp_givenOverflowedDigitFile_shouldReturnREADERROR() throws IOException {
// given
- File timeStampedFile = temporaryFolder.newFile();
+ File timeStampedFile = Files.createTempFile(temporaryFolder, null, null).toFile();
try(FileWriter fileWriter = new FileWriter(timeStampedFile)) {
// we are faking an overflowed timestamp
fileWriter.write("[0x10000000000000000]");
@@ -154,7 +169,7 @@ public void readStamp_givenOverflowedDigitFile_shouldReturnREADERROR() throws IO
@Test
public void readStamp_givenMaxLongFile_shouldReturnLargeTimestamp() throws IOException {
// given
- File timeStampedFile = temporaryFolder.newFile();
+ File timeStampedFile = Files.createTempFile(temporaryFolder, null, null).toFile();
try(FileWriter fileWriter = new FileWriter(timeStampedFile)) {
// we are faking an overflowed timestamp
fileWriter.write("[0x7fffffffffffffff]");
@@ -172,7 +187,7 @@ public void readStamp_givenMaxLongFile_shouldReturnLargeTimestamp() throws IOExc
@Test
public void writeStamp_givenNegativeTimestamps_shouldThrowIOException() throws IOException {
// given
- File timeStampedFile = temporaryFolder.newFile();
+ File timeStampedFile = Files.createTempFile(temporaryFolder, null, null).toFile();
// when
LockedFile lockedFile = new LockedFile(timeStampedFile);
@@ -193,7 +208,7 @@ public void writeStamp_givenTimestampedFile_withLowerValue_shouldOverrideValue()
long numericInputValue = 0L;
long newTimestamp = ThreadLocalRandom.current().nextLong(Long.MAX_VALUE);
- File timeStampedFile = temporaryFolder.newFile();
+ File timeStampedFile = Files.createTempFile(temporaryFolder, null, null).toFile();
try(FileWriter fileWriter = new FileWriter(timeStampedFile)) {
fileWriter.write(inputValue);
fileWriter.flush();
@@ -216,7 +231,7 @@ public void writeStamp_givenNewerTimestampedFile_writeNegativeTimestamp_shouldTh
String inputValue = "[0x7fffffffffffffff]";
long newTimestamp = Long.MIN_VALUE;
- File timeStampedFile = temporaryFolder.newFile();
+ File timeStampedFile = Files.createTempFile(temporaryFolder, null, null).toFile();
try(FileWriter fileWriter = new FileWriter(timeStampedFile)) {
fileWriter.write(inputValue);
fileWriter.flush();
@@ -242,7 +257,7 @@ public void writeStamp_givenTimestampedFile_writeSameTimestamp_shouldLeaveFileAl
long numericInputValue = Long.MAX_VALUE;
long newTimestamp = Long.MAX_VALUE;
- File timeStampedFile = temporaryFolder.newFile();
+ File timeStampedFile = Files.createTempFile(temporaryFolder, null, null).toFile();
try(FileWriter fileWriter = new FileWriter(timeStampedFile)) {
fileWriter.write(inputValue);
fileWriter.flush();
diff --git a/src/test/java/com/fasterxml/uuid/impl/TimeBasedEpochGeneratorTest.java b/src/test/java/com/fasterxml/uuid/impl/TimeBasedEpochGeneratorTest.java
index 1b155c1..8da117f 100644
--- a/src/test/java/com/fasterxml/uuid/impl/TimeBasedEpochGeneratorTest.java
+++ b/src/test/java/com/fasterxml/uuid/impl/TimeBasedEpochGeneratorTest.java
@@ -7,13 +7,16 @@
import com.fasterxml.uuid.UUIDClock;
-import junit.framework.TestCase;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
/**
* @since 5.2
*/
-public class TimeBasedEpochGeneratorTest extends TestCase
+public class TimeBasedEpochGeneratorTest
{
+ @Test
public void testFormat() {
BigInteger minEntropy = BigInteger.ZERO;
long minTimestamp = 0;
@@ -34,6 +37,7 @@ public void testFormat() {
assertEquals(BigInteger.ONE.shiftLeft(73).subtract(BigInteger.ONE), getEntropy(uuidFull));
}
+ @Test
public void testIncrement() {
TimeBasedEpochGenerator generator = new TimeBasedEpochGenerator(staticEntropy(BigInteger.ZERO), staticClock(0));
assertEquals(BigInteger.valueOf(0), getEntropy(generator.generate()));
@@ -42,12 +46,14 @@ public void testIncrement() {
assertEquals(BigInteger.valueOf(3), getEntropy(generator.generate()));
}
+ @Test
public void testCarryOnce() {
TimeBasedEpochGenerator generator = new TimeBasedEpochGenerator(staticEntropy(BigInteger.valueOf(0xFF)), staticClock(0));
assertEquals(BigInteger.valueOf(0xFF), getEntropy(generator.generate()));
assertEquals(BigInteger.valueOf(0x100), getEntropy(generator.generate()));
}
+ @Test
public void testCarryAll() {
BigInteger largeEntropy = BigInteger.ONE.shiftLeft(73).subtract(BigInteger.ONE);
TimeBasedEpochGenerator generator = new TimeBasedEpochGenerator(staticEntropy(largeEntropy), staticClock(0));
diff --git a/src/test/java/com/fasterxml/uuid/impl/UUIDUtilTest.java b/src/test/java/com/fasterxml/uuid/impl/UUIDUtilTest.java
index b730c00..f65f9af 100644
--- a/src/test/java/com/fasterxml/uuid/impl/UUIDUtilTest.java
+++ b/src/test/java/com/fasterxml/uuid/impl/UUIDUtilTest.java
@@ -5,7 +5,9 @@
import com.fasterxml.uuid.Generators;
import com.fasterxml.uuid.NoArgGenerator;
-import junit.framework.TestCase;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
/**
* Test class focusing on verifying functionality provided by
@@ -14,10 +16,11 @@
* NOTE: some of {@code UUIDUtil} testing is via main
* {@link com.fasterxml.uuid.UUIDTest}.
*/
-public class UUIDUtilTest extends TestCase
+public class UUIDUtilTest
{
final static int TEST_REPS = 1_000_000;
+ @Test
public void testNilUUID() {
UUID nil = UUIDUtil.nilUUID();
// Should be all zeroes:
@@ -25,6 +28,7 @@ public void testNilUUID() {
assertEquals(0L, nil.getLeastSignificantBits());
}
+ @Test
public void testMaxUUID() {
UUID max = UUIDUtil.maxUUID();
// Should be all ones:
@@ -32,6 +36,7 @@ public void testMaxUUID() {
assertEquals(~0, max.getLeastSignificantBits());
}
+ @Test
public void testExtractTimestampUUIDTimeBased() {
TimeBasedGenerator generator = Generators.timeBasedGenerator();
final Random rnd = new Random(1);
@@ -42,6 +47,7 @@ public void testExtractTimestampUUIDTimeBased() {
}
}
+ @Test
public void testExtractTimestampUUIDTimeBasedCurrentTimemillis() {
TimeBasedGenerator generator = Generators.timeBasedGenerator();
long time = System.currentTimeMillis();
@@ -50,6 +56,7 @@ public void testExtractTimestampUUIDTimeBasedCurrentTimemillis() {
}
+ @Test
public void testExtractTimestampUUIDTimeBasedReordered() {
TimeBasedReorderedGenerator generator = Generators.timeBasedReorderedGenerator();
final Random rnd = new Random(2);
@@ -60,6 +67,7 @@ public void testExtractTimestampUUIDTimeBasedReordered() {
}
}
+ @Test
public void testExtractTimestampUUIDTimeBasedReorderedCurrentTimeMillis() {
NoArgGenerator generator = Generators.timeBasedReorderedGenerator();
long time = System.currentTimeMillis();
@@ -67,6 +75,7 @@ public void testExtractTimestampUUIDTimeBasedReorderedCurrentTimeMillis() {
assertEquals(time, UUIDUtil.extractTimestamp(uuid));
}
+ @Test
public void testExtractTimestampUUIDEpochBased() {
TimeBasedEpochGenerator generator = Generators.timeBasedEpochGenerator();
final Random rnd = new Random(3);
@@ -77,6 +86,7 @@ public void testExtractTimestampUUIDEpochBased() {
}
}
+ @Test
public void testExtractTimestampUUIDEpochBasedCurrentTimeMillis() {
NoArgGenerator generator = Generators.timeBasedEpochGenerator();
long time = System.currentTimeMillis();
@@ -85,6 +95,7 @@ public void testExtractTimestampUUIDEpochBasedCurrentTimeMillis() {
}
+ @Test
public void testExtractTimestampUUIDEpochRandomBased() {
TimeBasedEpochRandomGenerator generator = Generators.timeBasedEpochRandomGenerator();
final Random rnd = new Random(3);
@@ -95,6 +106,7 @@ public void testExtractTimestampUUIDEpochRandomBased() {
}
}
+ @Test
public void testExtractTimestampUUIDOnOtherValues() {
assertEquals(0L, UUIDUtil.extractTimestamp(null));
assertEquals(0L, UUIDUtil.extractTimestamp(UUID.fromString("00000000-0000-0000-0000-000000000000")));
diff --git a/src/test/java/perf/MeasurePerformanceTest.java b/src/test/java/perf/MeasurePerformanceTest.java
deleted file mode 100644
index fdc81c7..0000000
--- a/src/test/java/perf/MeasurePerformanceTest.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package perf;
-
-import org.junit.Test;
-
-// Things we do for Code Coverage... altough "perf/MeasurePerformance.java"
-// is only to be manually run, it is included in build, so
-// we get code coverage whether we want it or not. So let's have
-// a silly little driver to exercise it from unit tests and avoid dinging
-// overall test coverage
-public class MeasurePerformanceTest
-{
- @Test
- public void runMinimalPerfTest() throws Exception
- {
- new MeasurePerformance(10, false).test();
- }
-}