Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 71 additions & 55 deletions src/test/java/eu/europa/ted/eforms/sdk/SdkVersionTest.java
Original file line number Diff line number Diff line change
@@ -1,63 +1,79 @@
package eu.europa.ted.eforms.sdk;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Test;

public class SdkVersionTest {
@Test
void testGetMajor() {
assertEquals("1", new SdkVersion("1.2.3").getMajor());
}

@Test
void testGetMinor() {
assertEquals("2", new SdkVersion("1.2.3").getMinor());
}

@Test
void testGetPatch() {
assertEquals("3", new SdkVersion("1.2.3").getPatch());
}

@Test
void testGetNextMajor() {
assertEquals("2.2.3", new SdkVersion("1.2.3").getNextMajor());
}

@Test
void testGetNextMinor() {
assertEquals("1.3.3", new SdkVersion("1.2.3").getNextMinor());
}

@Test
void testIsPatch() {
assertEquals(false, new SdkVersion("1.2").isPatch());

assertEquals(true, new SdkVersion("1.2.3").isPatch());
assertEquals(true, new SdkVersion("1.2.3-rc.4").isPatch());
}

@Test
void testToNormalisedStringWithPatch() {
assertEquals("1.2.3", new SdkVersion("1.2.3").toNormalisedString(true));
assertEquals("1.2.3", new SdkVersion("1.2.3-SNAPSHOT").toNormalisedString(true));
assertEquals("1.2.3", new SdkVersion("1.2.3-rc.4").toNormalisedString(true));
}

@Test
void testToStringWithoutPatch() {
assertEquals("1.2", new SdkVersion("1.2.3").toStringWithoutPatch());
assertEquals("1.2", new SdkVersion("1.2.3-SNAPSHOT").toStringWithoutPatch());
assertEquals("1.2", new SdkVersion("1.2.3-rc.4").toStringWithoutPatch());
}

@Test
void testCompare() {
assert(new SdkVersion("1.2.3").compareTo(new SdkVersion("1.2.2")) > 0);
assert(new SdkVersion("1.2.3").compareTo(new SdkVersion("1.2")) > 0);
assert(new SdkVersion("1.2.3").compareTo(new SdkVersion("1.2.3-SNAPSHOT")) > 0);
assert(new SdkVersion("1.2.3").compareTo(new SdkVersion("1.2.3-rc.3")) > 0);
assert(new SdkVersion("2.0.0").compareTo(new SdkVersion("2.0.0-alpha.1")) > 0);
}
@Test
void testGetMajor() {
assertEquals("1", new SdkVersion("1.2.3").getMajor());
}

@Test
void testGetMinor() {
assertEquals("2", new SdkVersion("1.2.3").getMinor());
}

@Test
void testGetPatch() {
assertEquals("3", new SdkVersion("1.2.3").getPatch());
}

@Test
void testGetNextMajor() {
assertEquals("2.2.3", new SdkVersion("1.2.3").getNextMajor());
}

@Test
void testGetNextMinor() {
assertEquals("1.3.3", new SdkVersion("1.2.3").getNextMinor());
}

@Test
void testIsMajor() {
// SdkVersion always has a minor version number, so isMajor can never be true
assertFalse(new SdkVersion("1.0").isMajor());
assertFalse(new SdkVersion("1.2").isMajor());
}

@Test
void testIsMinor() {
assertTrue(new SdkVersion("2.0").isMinor());

assertFalse(new SdkVersion("1.2.3").isMinor());
}

@Test
void testIsPatch() {
assertEquals(false, new SdkVersion("1.2").isPatch());

assertEquals(true, new SdkVersion("1.2.3").isPatch());
assertEquals(true, new SdkVersion("1.2.3-rc.4").isPatch());
}

@Test
void testToNormalisedStringWithPatch() {
assertEquals("1.2.3", new SdkVersion("1.2.3").toNormalisedString(true));
assertEquals("1.2.3", new SdkVersion("1.2.3-SNAPSHOT").toNormalisedString(true));
assertEquals("1.2.3", new SdkVersion("1.2.3-rc.4").toNormalisedString(true));
}

@Test
void testToStringWithoutPatch() {
assertEquals("1.2", new SdkVersion("1.2.3").toStringWithoutPatch());
assertEquals("1.2", new SdkVersion("1.2.3-SNAPSHOT").toStringWithoutPatch());
assertEquals("1.2", new SdkVersion("1.2.3-rc.4").toStringWithoutPatch());
}

@Test
void testCompare() {
assert(new SdkVersion("1.2.3").compareTo(new SdkVersion("1.2.2")) > 0);
assert(new SdkVersion("1.2.3").compareTo(new SdkVersion("1.2")) > 0);
assert(new SdkVersion("1.2.3").compareTo(new SdkVersion("1.2.3-SNAPSHOT")) > 0);
assert(new SdkVersion("1.2.3").compareTo(new SdkVersion("1.2.3-rc.3")) > 0);
assert(new SdkVersion("2.0.0").compareTo(new SdkVersion("2.0.0-alpha.1")) > 0);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package eu.europa.ted.eforms.sdk.resource;

import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import eu.europa.ted.MavenTestSetup;
import eu.europa.ted.eforms.sdk.SdkConstants;

public class SdkResourceLoaderTest extends MavenTestSetup {
private static final Path SDK_ROOT_DIR = Path.of("target/eforms-sdk");

@BeforeAll
static void downloadSdk() throws IOException {
SdkDownloader.downloadSdk("1.1", SDK_ROOT_DIR);
}

@Test
void testGetResourceAsPath() {
Path path = SdkResourceLoader.getResourceAsPath("1.1",
SdkConstants.SdkResource.FIELDS_JSON, SDK_ROOT_DIR);

assertTrue(path.endsWith("fields/fields.json"));
}

@Test
void testGetResourceAsStream() throws IOException {
InputStream is = SdkResourceLoader.getResourceAsStream("1.1",
SdkConstants.SdkResource.FIELDS, "fields.json", SDK_ROOT_DIR);

assertTrue(is.read() >= 0);
is.close();
}
}