diff --git a/src/test/java/com/github/f4b6a3/ulid/TestSuite.java b/src/test/java/com/github/f4b6a3/ulid/TestSuite.java index b6de9b8..b76e08a 100644 --- a/src/test/java/com/github/f4b6a3/ulid/TestSuite.java +++ b/src/test/java/com/github/f4b6a3/ulid/TestSuite.java @@ -3,13 +3,10 @@ package com.github.f4b6a3.ulid; import org.junit.runner.RunWith; import org.junit.runners.Suite; -import com.github.f4b6a3.ulid.factory.DefaultFactoryTest; -import com.github.f4b6a3.ulid.factory.MonotonicFactoryTest; - @RunWith(Suite.class) @Suite.SuiteClasses({ - MonotonicFactoryTest.class, - DefaultFactoryTest.class, + UlidFactoryMonotonicTest.class, + UlidFactoryDefaultfTest.class, UlidTest.class, }) diff --git a/src/test/java/com/github/f4b6a3/ulid/factory/DefaultFactoryTest.java b/src/test/java/com/github/f4b6a3/ulid/UlidFactoryDefaultfTest.java similarity index 60% rename from src/test/java/com/github/f4b6a3/ulid/factory/DefaultFactoryTest.java rename to src/test/java/com/github/f4b6a3/ulid/UlidFactoryDefaultfTest.java index 05b42af..eca2121 100644 --- a/src/test/java/com/github/f4b6a3/ulid/factory/DefaultFactoryTest.java +++ b/src/test/java/com/github/f4b6a3/ulid/UlidFactoryDefaultfTest.java @@ -1,4 +1,4 @@ -package com.github.f4b6a3.ulid.factory; +package com.github.f4b6a3.ulid; import org.junit.Test; @@ -8,10 +8,9 @@ import com.github.f4b6a3.ulid.UlidFactory; import static org.junit.Assert.*; -import java.util.HashSet; import java.util.Random; -public class DefaultFactoryTest extends UlidFactoryTest { +public class UlidFactoryDefaultfTest extends UlidFactoryTest { @Test public void testGetUlid() { @@ -30,35 +29,6 @@ public class DefaultFactoryTest extends UlidFactoryTest { checkCreationTime(list, startTime, endTime); } - private void checkNullOrInvalid(Ulid[] list) { - for (Ulid ulid : list) { - assertNotNull("ULID is null", ulid); - } - } - - private void checkUniqueness(Ulid[] list) { - - HashSet set = new HashSet<>(); - - for (Ulid ulid : list) { - assertTrue(String.format("ULID is duplicated %s", ulid), set.add(ulid)); - } - - assertEquals("There are duplicated ULIDs", set.size(), list.length); - } - - private void checkCreationTime(Ulid[] list, long startTime, long endTime) { - - assertTrue("Start time was after end time", startTime <= endTime); - - for (Ulid ulid : list) { - long creationTime = ulid.getTime(); - assertTrue("Creation time was before start time " + creationTime + " " + startTime, - creationTime >= startTime); - assertTrue("Creation time was after end time", creationTime <= endTime); - } - } - @Test public void testGetUlidInParallel() throws InterruptedException { diff --git a/src/test/java/com/github/f4b6a3/ulid/factory/MonotonicFactoryTest.java b/src/test/java/com/github/f4b6a3/ulid/UlidFactoryMonotonicTest.java similarity index 65% rename from src/test/java/com/github/f4b6a3/ulid/factory/MonotonicFactoryTest.java rename to src/test/java/com/github/f4b6a3/ulid/UlidFactoryMonotonicTest.java index 6634282..662787d 100644 --- a/src/test/java/com/github/f4b6a3/ulid/factory/MonotonicFactoryTest.java +++ b/src/test/java/com/github/f4b6a3/ulid/UlidFactoryMonotonicTest.java @@ -1,4 +1,4 @@ -package com.github.f4b6a3.ulid.factory; +package com.github.f4b6a3.ulid; import org.junit.Test; @@ -9,10 +9,9 @@ import com.github.f4b6a3.ulid.UlidFactory; import static org.junit.Assert.*; import java.util.Arrays; -import java.util.HashSet; import java.util.Random; -public class MonotonicFactoryTest extends UlidFactoryTest { +public class UlidFactoryMonotonicTest extends UlidFactoryTest { @Test public void testGetUlid() { @@ -32,35 +31,6 @@ public class MonotonicFactoryTest extends UlidFactoryTest { checkCreationTime(list, startTime, endTime); } - private void checkNullOrInvalid(Ulid[] list) { - for (Ulid ulid : list) { - assertNotNull("ULID is null", ulid); - } - } - - private void checkUniqueness(Ulid[] list) { - - HashSet set = new HashSet<>(); - - for (Ulid ulid : list) { - assertTrue(String.format("ULID is duplicated %s", ulid), set.add(ulid)); - } - - assertEquals("There are duplicated ULIDs", set.size(), list.length); - } - - private void checkCreationTime(Ulid[] list, long startTime, long endTime) { - - assertTrue("Start time was after end time", startTime <= endTime); - - for (Ulid ulid : list) { - long creationTime = ulid.getTime(); - assertTrue("Creation time was before start time " + creationTime + " " + startTime, - creationTime >= startTime); - assertTrue("Creation time was after end time", creationTime <= endTime); - } - } - private void checkOrdering(Ulid[] list) { Ulid[] other = Arrays.copyOf(list, list.length); Arrays.sort(other); diff --git a/src/test/java/com/github/f4b6a3/ulid/factory/UlidFactoryTest.java b/src/test/java/com/github/f4b6a3/ulid/UlidFactoryTest.java similarity index 56% rename from src/test/java/com/github/f4b6a3/ulid/factory/UlidFactoryTest.java rename to src/test/java/com/github/f4b6a3/ulid/UlidFactoryTest.java index 7af1fc7..e36863b 100644 --- a/src/test/java/com/github/f4b6a3/ulid/factory/UlidFactoryTest.java +++ b/src/test/java/com/github/f4b6a3/ulid/UlidFactoryTest.java @@ -1,4 +1,8 @@ -package com.github.f4b6a3.ulid.factory; +package com.github.f4b6a3.ulid; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import java.util.HashSet; import java.util.Random; @@ -27,6 +31,35 @@ public abstract class UlidFactoryTest { return processors; } + protected void checkNullOrInvalid(Ulid[] list) { + for (Ulid ulid : list) { + assertNotNull("ULID is null", ulid); + } + } + + protected void checkUniqueness(Ulid[] list) { + + HashSet set = new HashSet<>(); + + for (Ulid ulid : list) { + assertTrue(String.format("ULID is duplicated %s", ulid), set.add(ulid)); + } + + assertEquals("There are duplicated ULIDs", set.size(), list.length); + } + + protected void checkCreationTime(Ulid[] list, long startTime, long endTime) { + + assertTrue("Start time was after end time", startTime <= endTime); + + for (Ulid ulid : list) { + long creationTime = ulid.getTime(); + assertTrue("Creation time was before start time " + creationTime + " " + startTime, + creationTime >= startTime); + assertTrue("Creation time was after end time", creationTime <= endTime); + } + } + protected static class TestThread extends Thread { public static Set hashSet = new HashSet<>(); diff --git a/src/test/java/com/github/f4b6a3/ulid/demo/DemoTest.java b/src/test/java/com/github/f4b6a3/ulid/demo/DemoTest.java index 79d6104..9e22bf9 100644 --- a/src/test/java/com/github/f4b6a3/ulid/demo/DemoTest.java +++ b/src/test/java/com/github/f4b6a3/ulid/demo/DemoTest.java @@ -16,7 +16,7 @@ public class DemoTest { for (int i = 0; i < max; i++) { System.out.println(UlidCreator.getUlid()); } - + System.out.println(HORIZONTAL_LINE); System.out.println("### Monotonic ULID"); System.out.println(HORIZONTAL_LINE);