diff --git a/README.md b/README.md index f51ad58d..74b8cb23 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,6 @@ How to compile * Gradle: `gradle clean build` (preferred) * Maven: `mvn clean package` -* sbt: `sbt clean package` (experimental) Configuration ------------- diff --git a/build.gradle b/build.gradle index 50b50b4f..1a419c3d 100644 --- a/build.gradle +++ b/build.gradle @@ -6,6 +6,7 @@ plugins { id 'org.gradle.crypto.checksum' version '1.4.0' id 'checkstyle' id 'jacoco' + id 'jvm-test-suite' } compileJava.options.encoding = 'UTF-8' @@ -17,10 +18,17 @@ repositories { } dependencies { - implementation group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-xml', version: '2.15.3' - implementation group: 'com.formdev', name: 'flatlaf', version: '3.2.2' + implementation group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-xml', version: '2.16.1' + implementation group: 'com.formdev', name: 'flatlaf', version: '3.4' implementation group: 'com.formdev', name: 'svgSalamander', version: '1.1.4' - testImplementation 'junit:junit:4.13.2' +} + +testing { + suites { + test { + useJUnitJupiter() + } + } } java { @@ -85,7 +93,7 @@ task bumpVersion { if (!project.hasProperty('toVersion')) { throw new GradleException("Please provide 'toVersion' property e.g. gradle bumpVersion -PtoVersion=$project.version") } - def extensions = ['java', 'gradle', 'sbt', 'xml', 'md', 'bat', 'sh', 'txt', 'command'].collect { "**/*.$it" }.join(",") + def extensions = ['java', 'gradle', 'xml', 'md', 'bat', 'sh', 'txt', 'command'].collect { "**/*.$it" }.join(",") def files = new groovy.util.FileNameFinder().getFileNames("$projectDir", extensions) files.each { versionedFile -> def file = new File(versionedFile) diff --git a/build.sbt b/build.sbt deleted file mode 100644 index b58af500..00000000 --- a/build.sbt +++ /dev/null @@ -1,15 +0,0 @@ -organization:= "jpass.id" - -name := "JPass" - -version := "1.0.6-SNAPSHOT" - -libraryDependencies += "com.fasterxml.jackson.dataformat" % "jackson-dataformat-xml" % "2.15.3" - -libraryDependencies += "com.formdev" % "flatlaf" % "3.2.2" - -libraryDependencies += "com.formdev" % "svgSalamander" % "1.1.4" - -libraryDependencies += "junit" % "junit" % "4.13.2" % "test" - -libraryDependencies += "com.novocode" % "junit-interface" % "0.10" % "test" diff --git a/pom.xml b/pom.xml index b9fe2373..72debf49 100644 --- a/pom.xml +++ b/pom.xml @@ -13,12 +13,12 @@ com.fasterxml.jackson.dataformat jackson-dataformat-xml - 2.15.3 + 2.16.1 com.formdev flatlaf - 3.2.2 + 3.4 com.formdev @@ -26,9 +26,9 @@ 1.1.4 - junit - junit - 4.13.2 + org.junit.jupiter + junit-jupiter + 5.10.2 test diff --git a/src/test/java/jpass/crypt/Aes256Test.java b/src/test/java/jpass/crypt/Aes256Test.java index c71ba74f..82cce5c4 100644 --- a/src/test/java/jpass/crypt/Aes256Test.java +++ b/src/test/java/jpass/crypt/Aes256Test.java @@ -2,9 +2,8 @@ import java.util.Arrays; import java.util.Random; - -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * Test values for the "Advanced Encryption Standard" (AES). These @@ -47,11 +46,11 @@ public void shouldEntryptAndDecryptATestMessage() { (byte) 0x45, (byte) 0xbf, (byte) 0xea, (byte) 0xfc, (byte) 0x49, (byte) 0x90, (byte) 0x4b, (byte) 0x49, (byte) 0x60, (byte) 0x89}; - Assert.assertTrue(Arrays.equals(expectedEncrypted, encrypted)); + Assertions.assertTrue(Arrays.equals(expectedEncrypted, encrypted)); byte[] decrypted = new byte[16]; cipher.decrypt(expectedEncrypted, 0, decrypted, 0); - Assert.assertTrue(Arrays.equals(block, decrypted)); + Assertions.assertTrue(Arrays.equals(block, decrypted)); } /** @@ -73,7 +72,7 @@ public void shouldEncryptAndDecryptRandomData() { Aes256 cipher = new Aes256(key); cipher.encrypt(data, 0, encrypted, 0); cipher.decrypt(encrypted, 0, decrypted, 0); - Assert.assertTrue(Arrays.equals(data, decrypted)); + Assertions.assertTrue(Arrays.equals(data, decrypted)); } } } diff --git a/src/test/java/jpass/crypt/CbcTest.java b/src/test/java/jpass/crypt/CbcTest.java index 180cc764..3a8f3ace 100644 --- a/src/test/java/jpass/crypt/CbcTest.java +++ b/src/test/java/jpass/crypt/CbcTest.java @@ -4,10 +4,9 @@ import java.io.IOException; import java.util.Arrays; import java.util.Random; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Unit test for the CBC encryption. The test data will be encrypted and @@ -51,7 +50,7 @@ public class CbcTest { /** * Sets the encryption and decryption instances up. */ - @Before + @BeforeEach public void setup() { byte[] iv = {(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, @@ -81,7 +80,7 @@ public void shouldEncryptAndDecryptASmallMessage() throws DecryptException, IOEx _decrypt.decrypt(_encrypted.toByteArray()); _decrypt.finishDecryption(); - Assert.assertTrue(Arrays.equals(source, _decrypted.toByteArray())); + Assertions.assertTrue(Arrays.equals(source, _decrypted.toByteArray())); } /** @@ -100,9 +99,9 @@ public void shouldEncryptAndDecryptABigMessage() throws DecryptException, IOExce _decrypt.finishDecryption(); byte[] d = _decrypted.toByteArray(); - Assert.assertEquals(3000, d.length); + Assertions.assertEquals(3000, d.length); for (int i = 0; i < d.length; ++i) { - Assert.assertEquals(0x81, d[i] & 0xff); + Assertions.assertEquals(0x81, d[i] & 0xff); } } @@ -146,13 +145,13 @@ public void shouldWorkWithReferenceData() throws DecryptException, IOException { encrypt.encrypt(plain); encrypt.finishEncryption(); - Assert.assertEquals(expected.length, _encrypted.toByteArray().length); - Assert.assertTrue(Arrays.equals(expected, _encrypted.toByteArray())); + Assertions.assertEquals(expected.length, _encrypted.toByteArray().length); + Assertions.assertTrue(Arrays.equals(expected, _encrypted.toByteArray())); decrypt.decrypt(_encrypted.toByteArray()); decrypt.finishDecryption(); - Assert.assertTrue(Arrays.equals(plain, _decrypted.toByteArray())); + Assertions.assertTrue(Arrays.equals(plain, _decrypted.toByteArray())); } /** @@ -178,6 +177,6 @@ private void testRandom(Random rnd, int size) throws DecryptException, IOExcepti _decrypt.decrypt(_encrypted.toByteArray()); _decrypt.finishDecryption(); - Assert.assertTrue(Arrays.equals(data, _decrypted.toByteArray())); + Assertions.assertTrue(Arrays.equals(data, _decrypted.toByteArray())); } } diff --git a/src/test/java/jpass/crypt/io/CryptIOStreamTest.java b/src/test/java/jpass/crypt/io/CryptIOStreamTest.java index 876b33b9..c54e1f8a 100644 --- a/src/test/java/jpass/crypt/io/CryptIOStreamTest.java +++ b/src/test/java/jpass/crypt/io/CryptIOStreamTest.java @@ -5,9 +5,8 @@ import java.io.IOException; import java.util.Arrays; import java.util.Random; - -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * Tests {@link jpass.crypt.io.CryptInputStream} and @@ -54,7 +53,7 @@ public void shouldDecryptAnEncryptedRandomMessage() throws IOException { decrypted.close(); decrypter.close(); - Assert.assertEquals(plain.length, decrypted.toByteArray().length); - Assert.assertTrue(Arrays.equals(plain, decrypted.toByteArray())); + Assertions.assertEquals(plain.length, decrypted.toByteArray().length); + Assertions.assertTrue(Arrays.equals(plain, decrypted.toByteArray())); } } diff --git a/src/test/java/jpass/data/DataModelTest.java b/src/test/java/jpass/data/DataModelTest.java index 675852a4..5f8b6e94 100644 --- a/src/test/java/jpass/data/DataModelTest.java +++ b/src/test/java/jpass/data/DataModelTest.java @@ -30,22 +30,22 @@ import jpass.xml.bind.Entries; import jpass.xml.bind.Entry; -import org.junit.Before; -import org.junit.Test; import java.util.List; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class DataModelTest { +class DataModelTest { public DataModel dataModel; - @Before + @BeforeEach public void setup() { dataModel = DataModel.getInstance(); dataModel.clear(); diff --git a/src/test/java/jpass/data/EntriesRepositoryTest.java b/src/test/java/jpass/data/EntriesRepositoryTest.java index 9c4ed83e..68641692 100644 --- a/src/test/java/jpass/data/EntriesRepositoryTest.java +++ b/src/test/java/jpass/data/EntriesRepositoryTest.java @@ -34,16 +34,16 @@ import java.io.IOException; import jpass.xml.bind.Entries; import jpass.xml.bind.Entry; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Unit test for {@link EntriesRepository}. * * @author Gabor Bata */ -public class EntriesRepositoryTest { +class EntriesRepositoryTest { private static final String TITLE = "Duff Beer Webshop"; private static final String URL = "http://duffbeer.com"; @@ -55,7 +55,7 @@ public class EntriesRepositoryTest { private char[] correctKey; private char[] incorrectKey; - @Before + @BeforeEach public void setup() throws Exception { File tempFile = File.createTempFile("jpass", "temp"); tempFile.deleteOnExit(); @@ -78,35 +78,38 @@ public void shouldWriteAndReadEncryptedFileWithCorrectPassword() throws Document assertEquals(expectedEntries, readEntries); } - @Test(expected = IOException.class) + @Test public void shouldThrowExceptionWhenReadingDocumentWithIncorrectKey() throws DocumentProcessException, IOException { // given EntriesRepository.newInstance(filePath, correctKey).writeDocument(createEntries()); // when - EntriesRepository.newInstance(filePath, incorrectKey).readDocument(); + Assertions.assertThrows(IOException.class, + () -> EntriesRepository.newInstance(filePath, incorrectKey).readDocument()); } - @Test(expected = IOException.class) + @Test public void shouldThrowExceptionWhenReadingDocumentWithInvalidFormat() throws DocumentProcessException, IOException { // given try ( FileWriter writer = new FileWriter(filePath)) { writer.append("invalid content"); } catch (Exception e) { - Assert.fail("could not prepare test data"); + Assertions.fail("could not prepare test data"); } // when - EntriesRepository.newInstance(filePath, correctKey).readDocument(); + Assertions.assertThrows(IOException.class, + () -> EntriesRepository.newInstance(filePath, correctKey).readDocument()); } - @Test(expected = FileNotFoundException.class) + @Test public void shouldThrowExceptionWhenReadingDocumentWithNonExistingFile() throws DocumentProcessException, IOException { // given EntriesRepository entriesRepository = EntriesRepository.newInstance("not_existing_path", correctKey); // when - entriesRepository.readDocument(); + Assertions.assertThrows(FileNotFoundException.class, + () -> entriesRepository.readDocument()); } @Test @@ -122,35 +125,38 @@ public void shouldBeAbleToWriteAndReadUnencryptedFile() throws DocumentProcessEx assertEquals(expectedEntries, readEntries); } - @Test(expected = IOException.class) + @Test public void shouldNotBeAbleToReadEncryptedFileWithoutKey() throws DocumentProcessException, IOException { // given EntriesRepository.newInstance(filePath, correctKey).writeDocument(createEntries()); // when - EntriesRepository.newInstance(filePath).readDocument(); + Assertions.assertThrows(IOException.class, + () -> EntriesRepository.newInstance(filePath).readDocument()); } - @Test(expected = IOException.class) + @Test public void shouldThrowExceptionWhenReadingUnencryptedDocumentWithInvalidFormat() throws DocumentProcessException, IOException { // given try ( FileWriter writer = new FileWriter(filePath)) { writer.append("invalid content"); } catch (Exception e) { - Assert.fail("could not prepare test data"); + Assertions.fail("could not prepare test data"); } // when - EntriesRepository.newInstance(filePath).readDocument(); + Assertions.assertThrows(IOException.class, + () -> EntriesRepository.newInstance(filePath).readDocument()); } - @Test(expected = FileNotFoundException.class) + @Test public void shouldThrowExceptionWhenReadingUnecrypredDocumentWithNonExistingFile() throws DocumentProcessException, IOException { // given EntriesRepository entriesRepository = EntriesRepository.newInstance("not_existing_path"); // when - entriesRepository.readDocument(); + Assertions.assertThrows(FileNotFoundException.class, + () -> entriesRepository.readDocument()); } @Test @@ -206,15 +212,15 @@ private Entry createEntry() { } private void assertEquals(Entries expectedEntries, Entries actualEntries) { - Assert.assertEquals(expectedEntries.getEntry().size(), actualEntries.getEntry().size(), 1); + Assertions.assertEquals(expectedEntries.getEntry().size(), actualEntries.getEntry().size(), 1); assertEquals(expectedEntries.getEntry().iterator().next(), actualEntries.getEntry().iterator().next()); } private void assertEquals(Entry expectedEntry, Entry actualEntry) { - Assert.assertEquals(expectedEntry.getTitle(), actualEntry.getTitle()); - Assert.assertEquals(expectedEntry.getUrl(), actualEntry.getUrl()); - Assert.assertEquals(expectedEntry.getUser(), actualEntry.getUser()); - Assert.assertEquals(expectedEntry.getPassword(), actualEntry.getPassword()); - Assert.assertEquals(expectedEntry.getNotes(), actualEntry.getNotes()); + Assertions.assertEquals(expectedEntry.getTitle(), actualEntry.getTitle()); + Assertions.assertEquals(expectedEntry.getUrl(), actualEntry.getUrl()); + Assertions.assertEquals(expectedEntry.getUser(), actualEntry.getUser()); + Assertions.assertEquals(expectedEntry.getPassword(), actualEntry.getPassword()); + Assertions.assertEquals(expectedEntry.getNotes(), actualEntry.getNotes()); } } diff --git a/src/test/java/jpass/util/ConfigurationTest.java b/src/test/java/jpass/util/ConfigurationTest.java index defbf2d5..cd03fe10 100644 --- a/src/test/java/jpass/util/ConfigurationTest.java +++ b/src/test/java/jpass/util/ConfigurationTest.java @@ -28,18 +28,17 @@ */ package jpass.util; -import org.junit.Before; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; - -public class ConfigurationTest { +class ConfigurationTest { private Configuration configuration; - @Before + @BeforeEach public void setup() { configuration = Configuration.getInstance(); } diff --git a/src/test/java/jpass/util/CryptUtilsTest.java b/src/test/java/jpass/util/CryptUtilsTest.java index 9648db6b..f3f83518 100644 --- a/src/test/java/jpass/util/CryptUtilsTest.java +++ b/src/test/java/jpass/util/CryptUtilsTest.java @@ -29,8 +29,8 @@ package jpass.util; import java.nio.charset.StandardCharsets; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * Unit test for {@link CryptUtils}. @@ -57,7 +57,7 @@ public void shouldCalculateSha256Hash() throws Exception { byte[] hash = CryptUtils.getSha256Hash("sesame".toCharArray()); // then - Assert.assertArrayEquals(expectedHash, hash); + Assertions.assertArrayEquals(expectedHash, hash); } @Test @@ -78,7 +78,7 @@ public void shouldCalculateSha256HashWithIterations() throws Exception { byte[] hash = CryptUtils.getSha256HashWithDefaultIterations("sesame".toCharArray()); // then - Assert.assertArrayEquals(expectedHash, hash); + Assertions.assertArrayEquals(expectedHash, hash); } @Test @@ -100,6 +100,6 @@ public void shouldCalculatePBKDF2KeyWithDefaultIterations() throws Exception { byte[] key = CryptUtils.getPBKDF2KeyWithDefaultIterations("sesame".toCharArray(), salt); // then - Assert.assertArrayEquals(expectedKey, key); + Assertions.assertArrayEquals(expectedKey, key); } } diff --git a/src/test/java/jpass/util/DateUtilsTest.java b/src/test/java/jpass/util/DateUtilsTest.java index ba36af4c..c64296bc 100644 --- a/src/test/java/jpass/util/DateUtilsTest.java +++ b/src/test/java/jpass/util/DateUtilsTest.java @@ -28,11 +28,10 @@ */ package jpass.util; -import org.junit.Test; - import java.time.format.DateTimeFormatter; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.Test; public class DateUtilsTest { diff --git a/src/test/java/jpass/util/StringUtilsTest.java b/src/test/java/jpass/util/StringUtilsTest.java index 788cd4ba..799a8906 100644 --- a/src/test/java/jpass/util/StringUtilsTest.java +++ b/src/test/java/jpass/util/StringUtilsTest.java @@ -28,11 +28,12 @@ */ package jpass.util; -import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; +import org.junit.jupiter.api.Assertions; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import org.junit.jupiter.api.Test; -public class StringUtilsTest { +class StringUtilsTest { @Test public void stripStringLength0String10Test() { @@ -90,16 +91,13 @@ public void stripStringLength10StringBigger10Test() { assertEquals(expectedResult, resultFunction); } - @Test(expected = StringIndexOutOfBoundsException.class) + @Test public void StripStringLength_2String10Test() { - int length_2 = -2; String stringEqual10Char = "Teste da f"; - String expectedResult = "Teste da f..."; - String resultFunction = StringUtils.stripString(stringEqual10Char, length_2); - - assertEquals(expectedResult, resultFunction); + Assertions.assertThrows(StringIndexOutOfBoundsException.class, + () -> StringUtils.stripString(stringEqual10Char, length_2)); } @Test