Upgrading to use jdk 17
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
package net.locusworks.test;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import net.locusworks.common.crypto.AES;
|
||||
import net.locusworks.common.utils.Utils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class AESEncryptionTest {
|
||||
|
||||
@@ -12,10 +12,10 @@ public class AESEncryptionTest {
|
||||
public void testEncryption() {
|
||||
try {
|
||||
String encrypted = AES.createInstance().encrypt("hello world");
|
||||
Assert.assertTrue(String.format("Encrypted String is not blank? :%s", encrypted), !Utils.isEmptyString(encrypted));
|
||||
assertFalse(Utils.isEmptyString(encrypted), String.format("Encrypted String is not blank? :%s", encrypted));
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace(System.err);
|
||||
Assert.fail();
|
||||
fail();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,16 +25,16 @@ public class AESEncryptionTest {
|
||||
try {
|
||||
AES aes = AES.createInstance();
|
||||
String encrypted = aes.encrypt(testString);
|
||||
Assert.assertTrue(String.format("Encrypted String is not blank? :%s", encrypted), !Utils.isEmptyString(encrypted));
|
||||
assertFalse(Utils.isEmptyString(encrypted), String.format("Encrypted String is not blank? :%s", encrypted));
|
||||
|
||||
String decrypted = aes.decrypt(encrypted);
|
||||
Assert.assertTrue(String.format("Decrypted String is not blank? :%s", decrypted), !Utils.isEmptyString(encrypted));
|
||||
|
||||
Assert.assertTrue("Test String and Original String the same? :%s", testString.equals(decrypted));
|
||||
assertFalse(Utils.isEmptyString(encrypted), String.format("Decrypted String is not blank? :%s", decrypted));
|
||||
|
||||
assertEquals(testString, decrypted, "Test String and Original String the same? :%s");
|
||||
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace(System.err);
|
||||
Assert.fail();
|
||||
fail();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,11 +1,7 @@
|
||||
package net.locusworks.test;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Suite;
|
||||
import org.junit.runners.Suite.SuiteClasses;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
@RunWith(Suite.class)
|
||||
@SuiteClasses({ AESEncryptionTest.class, FileReaderTest.class, HashSaltTest.class, RandomStringTest.class })
|
||||
public class AllTests {
|
||||
|
||||
}
|
||||
|
@@ -1,6 +1,12 @@
|
||||
package net.locusworks.test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import net.locusworks.common.interfaces.AutoCloseableIterator;
|
||||
import net.locusworks.common.utils.FileReader;
|
||||
import net.locusworks.common.utils.FileReader.LineInfo;
|
||||
import net.locusworks.common.utils.RandomString;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
@@ -10,26 +16,19 @@ import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import net.locusworks.common.interfaces.AutoCloseableIterator;
|
||||
import net.locusworks.common.utils.FileReader;
|
||||
import net.locusworks.common.utils.FileReader.LineInfo;
|
||||
import net.locusworks.common.utils.RandomString;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class FileReaderTest {
|
||||
|
||||
private static final String TEST_FILE = "test_file.txt";
|
||||
private static Map<Integer, Integer> numLines = new LinkedHashMap<>();
|
||||
private static final Map<Integer, Integer> numLines = new LinkedHashMap<>();
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
File testFile = new File(TEST_FILE);
|
||||
FileOutputStream fos = new FileOutputStream(testFile);
|
||||
|
||||
Integer count = ThreadLocalRandom.current().nextInt(100);
|
||||
int count = ThreadLocalRandom.current().nextInt(100);
|
||||
|
||||
for (int i = 1; i <= count; i++) {
|
||||
String randomString = RandomString.getString(ThreadLocalRandom.current().nextInt(5, 100)) + "\n";
|
||||
@@ -40,7 +39,7 @@ public class FileReaderTest {
|
||||
fos.close();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void tearDownAfterClass() throws Exception {
|
||||
File file = new File(TEST_FILE);
|
||||
file.delete();
|
||||
@@ -48,48 +47,50 @@ public class FileReaderTest {
|
||||
|
||||
@Test
|
||||
public void testForLoop() {
|
||||
Integer lineCount = 0;
|
||||
int lineCount = 0;
|
||||
try (FileReader fr = new FileReader(Paths.get(TEST_FILE))) {
|
||||
for (LineInfo s : fr) {
|
||||
lineCount++;
|
||||
Integer lineNumber = s.getLineNumber();
|
||||
Integer lineLength = s.getLine().length();
|
||||
int lineLength = s.getLine().length();
|
||||
Integer mapLineLength = numLines.get(lineNumber);
|
||||
assertTrue(lineLength == (mapLineLength-1));
|
||||
assertEquals(lineLength, (mapLineLength - 1));
|
||||
}
|
||||
}
|
||||
assertTrue(lineCount == numLines.size());
|
||||
assertEquals(lineCount, numLines.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIterator() {
|
||||
Integer lineCount = 0;
|
||||
int lineCount = 0;
|
||||
|
||||
try(AutoCloseableIterator<LineInfo> iter = new FileReader(Paths.get(TEST_FILE))) {
|
||||
while(iter.hasNext()) {
|
||||
lineCount++;
|
||||
LineInfo s = iter.next();
|
||||
Integer lineNumber = s.getLineNumber();
|
||||
Integer lineLength = s.getLine().length();
|
||||
int lineLength = s.getLine().length();
|
||||
Integer mapLineLength = numLines.get(lineNumber);
|
||||
assertTrue(lineLength == (mapLineLength-1));
|
||||
assertEquals(lineLength, (mapLineLength - 1));
|
||||
}
|
||||
}
|
||||
assertTrue(lineCount == numLines.size());
|
||||
assertEquals(lineCount, numLines.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testForIterator() {
|
||||
Integer lineCount = 0;
|
||||
for(Iterator<LineInfo> iter = new FileReader(Paths.get(TEST_FILE)); iter.hasNext();) {
|
||||
lineCount++;
|
||||
LineInfo s = iter.next();
|
||||
Integer lineNumber = s.getLineNumber();
|
||||
Integer lineLength = s.getLine().length();
|
||||
Integer mapLineLength = numLines.get(lineNumber);
|
||||
assertTrue(lineLength == (mapLineLength-1));
|
||||
int lineCount = 0;
|
||||
try (FileReader fr = new FileReader(Paths.get(TEST_FILE))) {
|
||||
while (((Iterator<LineInfo>) fr).hasNext()) {
|
||||
lineCount++;
|
||||
LineInfo s = ((Iterator<LineInfo>) fr).next();
|
||||
Integer lineNumber = s.getLineNumber();
|
||||
int lineLength = s.getLine().length();
|
||||
Integer mapLineLength = numLines.get(lineNumber);
|
||||
assertEquals(lineLength, (mapLineLength - 1));
|
||||
}
|
||||
assertEquals(lineCount, numLines.size());
|
||||
}
|
||||
assertTrue(lineCount == numLines.size());
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,22 +1,22 @@
|
||||
package net.locusworks.test;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import net.locusworks.common.crypto.HashSalt;
|
||||
import net.locusworks.common.utils.Utils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class HashSaltTest {
|
||||
|
||||
private static String samplePassword="Hello World";
|
||||
private static final String samplePassword="Hello World";
|
||||
|
||||
@Test
|
||||
public void testEncryption() {
|
||||
try {
|
||||
String hashSalt = HashSalt.createHash(samplePassword);
|
||||
Assert.assertTrue(String.format("Encrypted String is not blank? :%s", hashSalt), !Utils.isEmptyString(hashSalt));
|
||||
assertFalse(Utils.isEmptyString(hashSalt), String.format("Encrypted String is not blank? :%s", hashSalt));
|
||||
} catch(Exception ex) {
|
||||
Assert.fail();
|
||||
fail();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,9 +25,9 @@ public class HashSaltTest {
|
||||
try {
|
||||
String hashSalt = HashSalt.createHash(samplePassword);
|
||||
boolean decrypted = HashSalt.validatePassword(samplePassword, hashSalt);
|
||||
Assert.assertTrue("Test String and Original String the same? :%s", decrypted);
|
||||
assertTrue(decrypted, "Test String and Original String the same? :%s");
|
||||
} catch(Exception ex) {
|
||||
Assert.fail();
|
||||
fail();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,11 +1,10 @@
|
||||
package net.locusworks.test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
import net.locusworks.common.utils.HashUtils;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class HashUtilsTest {
|
||||
|
||||
@@ -15,24 +14,24 @@ public class HashUtilsTest {
|
||||
public void testMD5() throws Exception {
|
||||
String digestUtilsMD5 = DigestUtils.md5Hex(TEST_STRING.getBytes());
|
||||
String hashUtilsMD5 = HashUtils.hash("MD5", TEST_STRING);
|
||||
|
||||
assertTrue(digestUtilsMD5.equals(hashUtilsMD5));
|
||||
|
||||
assertEquals(digestUtilsMD5, hashUtilsMD5);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSHA1() throws Exception {
|
||||
String digestUtilsMD5 = DigestUtils.sha1Hex(TEST_STRING.getBytes());
|
||||
String hashUtilsMD5 = HashUtils.hash("SHA-1", TEST_STRING);
|
||||
|
||||
assertTrue(digestUtilsMD5.equals(hashUtilsMD5));
|
||||
|
||||
assertEquals(digestUtilsMD5, hashUtilsMD5);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSHA512() throws Exception {
|
||||
String digestUtilsMD5 = DigestUtils.sha512Hex(TEST_STRING.getBytes());
|
||||
String hashUtilsMD5 = HashUtils.hash("SHA-512", TEST_STRING);
|
||||
|
||||
assertTrue(digestUtilsMD5.equals(hashUtilsMD5));
|
||||
|
||||
assertEquals(digestUtilsMD5, hashUtilsMD5);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,12 +1,12 @@
|
||||
package net.locusworks.test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import net.locusworks.common.immutables.Pair;
|
||||
import net.locusworks.common.immutables.Triplet;
|
||||
import net.locusworks.common.immutables.Unit;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
|
||||
public class ImmutablesTest {
|
||||
@@ -14,32 +14,32 @@ public class ImmutablesTest {
|
||||
@Test
|
||||
public void testUnit() {
|
||||
Unit<String> unit = new Unit<>("Hello World");
|
||||
assertTrue(unit.getValue1().equals("Hello World"));
|
||||
assertEquals("Hello World", unit.getValue1());
|
||||
Unit<Integer> unit2 = new Unit<>(2);
|
||||
assertTrue(unit2.getValue1().equals(2));
|
||||
assertEquals(2, (int) unit2.getValue1());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPair() {
|
||||
Pair<String, String> pair1 = new Pair<>("Hello", "World");
|
||||
assertTrue(pair1.getValue1().equals("Hello"));
|
||||
assertTrue(pair1.getValue2().equals("World"));
|
||||
assertEquals("Hello", pair1.getValue1());
|
||||
assertEquals("World", pair1.getValue2());
|
||||
|
||||
Pair<String, Integer> pair2 = new Pair<>("Foo", 25);
|
||||
assertTrue(pair2.getValue1().equals("Foo"));
|
||||
assertTrue(pair2.getValue2().equals(25));
|
||||
assertEquals("Foo", pair2.getValue1());
|
||||
assertEquals(25, (int) pair2.getValue2());
|
||||
|
||||
Pair<Integer, Integer> pair3 = new Pair<>(1, 23);
|
||||
assertTrue(pair3.getValue1().equals(1));
|
||||
assertTrue(pair3.getValue2().equals(23));
|
||||
assertEquals(1, (int) pair3.getValue1());
|
||||
assertEquals(23, (int) pair3.getValue2());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTriplet() {
|
||||
Triplet<String, Integer, String> triplet1 = new Triplet<>("Hello", 24, "World");
|
||||
assertTrue(triplet1.getValue1().equals("Hello"));
|
||||
assertTrue(triplet1.getValue2().equals(24));
|
||||
assertTrue(triplet1.getValue3().equals("World"));
|
||||
assertEquals("Hello", triplet1.getValue1());
|
||||
assertEquals(24, (int) triplet1.getValue2());
|
||||
assertEquals("World", triplet1.getValue3());
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -3,20 +3,18 @@
|
||||
*/
|
||||
package net.locusworks.test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import net.locusworks.common.immutables.Triplet;
|
||||
import net.locusworks.common.objectmapper.ObjectMapperHelper;
|
||||
import net.locusworks.common.utils.Utils;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static net.locusworks.common.utils.Constants.JUNIT_TEST_CHECK;
|
||||
import static net.locusworks.common.utils.Constants.LOG4J_CONFIG_PROPERTY;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* Test cases to test ObjectMapperHelper.class
|
||||
@@ -31,14 +29,14 @@ public class ObjectMapperHelperTest {
|
||||
/**
|
||||
* @throws java.lang.Exception exception
|
||||
*/
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
System.setProperty(LOG4J_CONFIG_PROPERTY, "log4j2-test.xml");
|
||||
System.setProperty(JUNIT_TEST_CHECK, "true");
|
||||
test = new Triplet<String, Integer, String>("Hello", 24, "World");
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void tearDownAfterClass() throws Exception {
|
||||
System.clearProperty(LOG4J_CONFIG_PROPERTY);
|
||||
System.clearProperty(JUNIT_TEST_CHECK);
|
||||
@@ -56,8 +54,8 @@ public class ObjectMapperHelperTest {
|
||||
assertTrue(value != null && !value.trim().isEmpty());
|
||||
|
||||
Triplet<?, ?, ?> tmp = ObjectMapperHelper.readValue(value, Triplet.class).getResults();
|
||||
assertTrue(tmp != null);
|
||||
assertTrue(tmp.equals(test));
|
||||
assertNotNull(tmp);
|
||||
assertEquals(tmp, test);
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@@ -67,7 +65,7 @@ public class ObjectMapperHelperTest {
|
||||
String value = ObjectMapperHelper.writeValue(htrList).getResults();
|
||||
assertTrue(value != null && !value.trim().isEmpty());
|
||||
List<Triplet> tmpList = ObjectMapperHelper.readListValue(value, Triplet.class).getResults();
|
||||
assertTrue(tmpList != null && tmpList.size() > 0);
|
||||
assertTrue(tmpList != null && !tmpList.isEmpty());
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,17 +1,16 @@
|
||||
package net.locusworks.test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import net.locusworks.common.configuration.PropertiesManager;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* Test cases for the properties manager class
|
||||
@@ -31,7 +30,7 @@ public class PropertiesManagerTest {
|
||||
USER_EXPIRATION_DAYS("userExpirationDays"),
|
||||
LOG_LEVEL("logLevel");
|
||||
|
||||
private String value;
|
||||
private final String value;
|
||||
|
||||
private Configuration(String value) {
|
||||
this.value = value;
|
||||
@@ -51,7 +50,7 @@ public class PropertiesManagerTest {
|
||||
}
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void removeSavedProps() {
|
||||
File tmp = new File(TMP_PROPS);
|
||||
if (tmp.exists()) {
|
||||
@@ -63,7 +62,7 @@ public class PropertiesManagerTest {
|
||||
public void testPropertiesLoad() {
|
||||
try {
|
||||
Properties props = PropertiesManager.loadConfiguration(this.getClass(), PROPERTIES_FILE);
|
||||
assertTrue(props != null);
|
||||
assertNotNull(props);
|
||||
assertTrue(props.containsKey(Configuration.USER_EXPIRATION_DAYS.toString()));
|
||||
assertTrue(props.containsKey(Configuration.DB_HOST.toString()));
|
||||
assertTrue(props.containsKey(Configuration.DB_PORT.toString()));
|
||||
@@ -78,9 +77,9 @@ public class PropertiesManagerTest {
|
||||
try {
|
||||
Properties props = PropertiesManager.loadConfiguration(this.getClass(), PROPERTIES_FILE);
|
||||
Properties tmp = new Properties();
|
||||
assertTrue(tmp.keySet().size() == 0);
|
||||
assertEquals(0, tmp.keySet().size());
|
||||
PropertiesManager.addConfiguration(tmp, props);
|
||||
assertTrue(tmp.keySet().size() == ENTRY_SIZE);
|
||||
assertEquals(ENTRY_SIZE, tmp.keySet().size());
|
||||
assertTrue(tmp.containsKey(Configuration.USER_EXPIRATION_DAYS.toString()));
|
||||
assertTrue(tmp.containsKey(Configuration.DB_HOST.toString()));
|
||||
assertTrue(tmp.containsKey(Configuration.DB_PORT.toString()));
|
||||
@@ -95,11 +94,12 @@ public class PropertiesManagerTest {
|
||||
try {
|
||||
Properties props = PropertiesManager.loadConfiguration(this.getClass(), PROPERTIES_FILE);
|
||||
Properties tmp = new Properties();
|
||||
assertTrue(props.keySet().size() == ENTRY_SIZE);
|
||||
assertTrue(tmp.keySet().size() == 0);
|
||||
assert props != null;
|
||||
assertEquals(ENTRY_SIZE, props.keySet().size());
|
||||
assertEquals(0, tmp.keySet().size());
|
||||
PropertiesManager.removeConfiguration(props, tmp);
|
||||
assertTrue(props.keySet().size() == 0);
|
||||
assertTrue(tmp.keySet().size() == 0);
|
||||
assertEquals(0, props.keySet().size());
|
||||
assertEquals(0, tmp.keySet().size());
|
||||
} catch (IOException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
@@ -112,7 +112,7 @@ public class PropertiesManagerTest {
|
||||
Path tmpFile = Paths.get(TMP_PROPS);
|
||||
PropertiesManager.saveConfiguration(props, tmpFile, "test propertis");
|
||||
Properties tmp = PropertiesManager.loadConfiguration(tmpFile);
|
||||
assertTrue(tmp.keySet().size() == ENTRY_SIZE);
|
||||
assertEquals(ENTRY_SIZE, tmp.keySet().size());
|
||||
assertTrue(tmp.containsKey(Configuration.USER_EXPIRATION_DAYS.toString()));
|
||||
assertTrue(tmp.containsKey(Configuration.DB_HOST.toString()));
|
||||
assertTrue(tmp.containsKey(Configuration.DB_PORT.toString()));
|
||||
|
@@ -1,17 +1,16 @@
|
||||
package net.locusworks.test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import net.locusworks.common.utils.RandomString;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class RandomStringTest {
|
||||
|
||||
@Test
|
||||
public void testStaticBytes() {
|
||||
for (Integer length = 3; length < 50; length++) {
|
||||
assertTrue(RandomString.getBytes(length).length == length);
|
||||
assertEquals(RandomString.getBytes(length).length, (int) length);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +18,7 @@ public class RandomStringTest {
|
||||
public void testStaticString() {
|
||||
for (Integer length = 3; length < 50; length++) {
|
||||
String random = RandomString.getString(length);
|
||||
assertTrue(random.length() == length);
|
||||
assertEquals(random.length(), (int) length);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,10 +1,18 @@
|
||||
package net.locusworks.test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import net.locusworks.common.utils.Utils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* Test cases for the Utils class
|
||||
@@ -20,6 +28,30 @@ public class UtilsTest {
|
||||
assertTrue(Utils.safeString(null).isEmpty());
|
||||
assertFalse(Utils.safeString("hello world").isEmpty());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testAreEqual() {
|
||||
String val1 = "H";
|
||||
String val2 = "H";
|
||||
assertTrue(Utils.areEqual(val1, val2));
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () -> Utils.areEqual("1"));
|
||||
}
|
||||
@ParameterizedTest
|
||||
@MethodSource("areEqualParams")
|
||||
public void testAreEqualWithParams(List<Object> objectList, boolean or, boolean equal) {
|
||||
assertEquals(equal, Utils.areEqual(or, objectList.toArray()));
|
||||
}
|
||||
|
||||
static Stream<Arguments> areEqualParams() {
|
||||
return Stream.of(
|
||||
Arguments.of(List.of("Hello", "Hello"), false, true),
|
||||
Arguments.of(List.of("Hello", "World"), false, false),
|
||||
Arguments.of(List.of("Hello", "World", "Hello"), true, true),
|
||||
Arguments.of(List.of("Hello", "World", "Fair"), true, false)
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyString() {
|
||||
@@ -32,8 +64,55 @@ public class UtilsTest {
|
||||
|
||||
@Test
|
||||
public void testToInteger() {
|
||||
assertTrue(Utils.toInteger("Hello word", 2) == 2);
|
||||
assertTrue(Utils.toInteger("23", 5023) == 23);
|
||||
assertEquals(2, (int) Utils.toInteger("Hello word", 2));
|
||||
assertEquals(23, (int) Utils.toInteger("23", 5023));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("validateValueParams")
|
||||
public <V> void testValidateValue(V value, boolean valid) {
|
||||
assertEquals(valid, Utils.validateValue(value));
|
||||
}
|
||||
|
||||
static Stream<Arguments> validateValueParams() {
|
||||
return Stream.of(
|
||||
Arguments.of(null, false),
|
||||
Arguments.of(Collections.emptyList(), false),
|
||||
Arguments.of(Map.of(), false),
|
||||
Arguments.of(false, false),
|
||||
Arguments.of("", false),
|
||||
Arguments.of("Hello", true),
|
||||
Arguments.of(List.of("Hello"), true),
|
||||
Arguments.of(Map.of("Hello", "World"), true),
|
||||
Arguments.of(true, true)
|
||||
);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("areValidParams")
|
||||
public void testValidateValues(List<Object> objects, boolean or, boolean valid) {
|
||||
assertEquals(valid, Utils.areValid(objects.toArray()));
|
||||
assertEquals(!valid, Utils.areNotValid(objects.toArray()));
|
||||
}
|
||||
|
||||
static Stream<Arguments> areValidParams() {
|
||||
return Stream.of(
|
||||
Arguments.of(List.of("Hello", List.of("Hello"), Map.of("Hello", "World"), true), false, true),
|
||||
Arguments.of(List.of(Collections.emptyList(), Map.of(), false), false, false)
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildMap() {
|
||||
Map<String, String> mymap = Utils.buildMap(TreeMap.class, String.class, String.class, "Hello", "World");
|
||||
assertNotNull(mymap);
|
||||
assertEquals(1, mymap.size());
|
||||
assertEquals("World", mymap.get("Hello"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsJunitRunning() {
|
||||
assertTrue(Utils.isJUnitRunning());
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user