Modularise project
This commit is contained in:
parent
2be3825438
commit
4416d55173
55 changed files with 388 additions and 331 deletions
|
|
@ -0,0 +1,67 @@
|
|||
package net.frankheijden.serverutils.common.utils;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static java.util.Collections.singletonList;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.util.List;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class ListBuilderTest {
|
||||
|
||||
private final String seperator = ", ";
|
||||
private final String lastSeperator = " and ";
|
||||
|
||||
@Test
|
||||
void testToStringOneElement() {
|
||||
String list = ListBuilder.createStrings(singletonList("Nice"))
|
||||
.seperator(seperator)
|
||||
.lastSeperator(lastSeperator)
|
||||
.toString();
|
||||
assertEquals("Nice", list);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToStringTwoElements() {
|
||||
String list = ListBuilder.createStrings(asList("Nice", "List"))
|
||||
.seperator(seperator)
|
||||
.lastSeperator(lastSeperator)
|
||||
.toString();
|
||||
assertEquals("Nice and List", list);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToStringMultipleElements() {
|
||||
String list = ListBuilder.createStrings(asList("Nice", "List", "You", "Having", "There"))
|
||||
.seperator(seperator)
|
||||
.lastSeperator(lastSeperator)
|
||||
.toString();
|
||||
assertEquals("Nice, List, You, Having and There", list);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToStringCustomFormat() {
|
||||
List<TestObject> objects = asList(
|
||||
new TestObject("pre1", 2),
|
||||
new TestObject("pre2", 3),
|
||||
new TestObject("pre3", 4)
|
||||
);
|
||||
|
||||
String list = ListBuilder.create(objects)
|
||||
.format(obj -> obj.prefix + "-" + obj.value)
|
||||
.seperator("; ")
|
||||
.lastSeperator(" and at last ")
|
||||
.toString();
|
||||
assertEquals("pre1-2; pre2-3 and at last pre3-4", list);
|
||||
}
|
||||
|
||||
private static class TestObject {
|
||||
private final String prefix;
|
||||
private final int value;
|
||||
|
||||
public TestObject(String prefix, int value) {
|
||||
this.prefix = prefix;
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
package net.frankheijden.serverutils.common.utils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.params.provider.Arguments.of;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
class VersionUtilsTest {
|
||||
|
||||
@ParameterizedTest(name = "old = {0}, new = {1}, expected = {2}")
|
||||
@MethodSource("versionGenerator")
|
||||
void isNewVersion(String oldVersion, String newVersion, boolean expected) {
|
||||
assertThat(VersionUtils.isNewVersion(oldVersion, newVersion)).isEqualTo(expected);
|
||||
}
|
||||
|
||||
private static Stream<Arguments> versionGenerator() {
|
||||
return Stream.of(
|
||||
of("0", "1", true),
|
||||
of("1", "0", false),
|
||||
of("9", "10", true),
|
||||
of("10", "9", false),
|
||||
of("-1", "5", true),
|
||||
of("5", "-1", false),
|
||||
of("10.1", "10.0", false),
|
||||
of("100.0", "120.0", true),
|
||||
of("1.0.0", "1.0.1", true),
|
||||
of("1.0.0", "1.1.0", true),
|
||||
of("1.0.0", "2.0.0", true),
|
||||
of("0.0.1", "0.0.1", false),
|
||||
of("0.0.1", "0.0.0", false),
|
||||
of("0.1.0", "0.0.1", false),
|
||||
of("1.0.0", "0.0.1", false),
|
||||
of("1.1.0", "0.1.1", false),
|
||||
of("1.0.0.0", "1.0.0.1", true),
|
||||
of("1.0.1-DEV", "1.0.2", true)
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue