Skip to content

Commit

Permalink
#13 improved tests and minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
raydac committed Jun 24, 2024
1 parent 7be62e3 commit a71899a
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 28 deletions.
6 changes: 3 additions & 3 deletions mvn-jlink-wrapper/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.9.1</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
import static org.apache.commons.lang3.SystemUtils.IS_OS_AIX;
import static org.apache.commons.lang3.SystemUtils.IS_OS_FREE_BSD;
import static org.apache.commons.lang3.SystemUtils.IS_OS_HP_UX;
import static org.apache.commons.lang3.SystemUtils.IS_OS_IRIX;
import static org.apache.commons.lang3.SystemUtils.IS_OS_LINUX;
import static org.apache.commons.lang3.SystemUtils.IS_OS_MAC;
import static org.apache.commons.lang3.SystemUtils.IS_OS_MAC_OSX;
import static org.apache.commons.lang3.SystemUtils.IS_OS_SOLARIS;
import static org.apache.commons.lang3.SystemUtils.IS_OS_WINDOWS;
import static org.apache.commons.lang3.SystemUtils.IS_OS_ZOS;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.function.Supplier;
Expand Down Expand Up @@ -69,14 +72,14 @@ public Boolean get() {
@Override
@Nonnull
public Boolean get() {
return SystemUtils.IS_OS_IRIX;
return IS_OS_IRIX;
}
}),
ZOS("zos", "", new Supplier<Boolean>() {
@Override
@Nonnull
public Boolean get() {
return SystemUtils.IS_OS_ZOS;
return IS_OS_ZOS;
}
}),
HP_UX("hpux", "", new Supplier<Boolean>() {
Expand Down Expand Up @@ -108,7 +111,8 @@ public Boolean get() {
}
});

private static final List<HostOs> VALUES = Arrays.asList(HostOs.values());
private static final List<HostOs> VALUES = Arrays.stream(HostOs.values())
.sorted(Comparator.comparingInt(Enum::ordinal)).collect(Collectors.toList());
private final String id;
private final Supplier<Boolean> hostChecker;
private final String defaultExtension;
Expand All @@ -122,7 +126,9 @@ public Boolean get() {

@Nonnull
public static HostOs findHostOs() {
return VALUES.stream().filter(x -> x != UNKNOWN).filter(HostOs::isHostOs).findFirst()
return VALUES.stream().filter(x -> x != UNKNOWN)
.filter(HostOs::isHostOs)
.reduce((a, b) -> b)
.orElse(UNKNOWN);
}

Expand All @@ -134,7 +140,8 @@ public String getId() {
@Nonnull
public static HostOs findForId(@Nonnull final String id) {
final String normalized = id.toLowerCase(Locale.ENGLISH).trim();
return VALUES.stream().filter(x -> x != UNKNOWN).filter(x -> x.getId().equals(normalized))
return VALUES.stream().filter(x -> x != UNKNOWN)
.filter(x -> x.getId().equals(normalized))
.reduce((a, b) -> b).orElse(UNKNOWN);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@

package com.igormaznitsa.mvnjlink.jdkproviders.providers;

import static com.igormaznitsa.meta.common.utils.Assertions.assertEquals;
import static com.igormaznitsa.mvnjlink.jdkproviders.providers.LibericaOpenJdkProvider.ReleaseList.Release.BELLSOFT_FILENAME_PATTERN;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

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

import java.util.regex.Matcher;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class LibericaOpenJdkProviderTest {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.igormaznitsa.mvnjlink.utils;

import static com.igormaznitsa.meta.common.utils.Assertions.assertEquals;
import static org.junit.jupiter.api.condition.OS.FREEBSD;
import static org.junit.jupiter.api.condition.OS.LINUX;
import static org.junit.jupiter.api.condition.OS.MAC;
import static org.junit.jupiter.api.condition.OS.SOLARIS;
import static org.junit.jupiter.api.condition.OS.WINDOWS;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledOnOs;

class HostOsTest {

@Test
@EnabledOnOs(LINUX)
void testLinux() {
assertEquals(HostOs.LINUX, HostOs.findHostOs());
}

@Test
@EnabledOnOs(WINDOWS)
void testWindows() {
assertEquals(HostOs.WINDOWS, HostOs.findHostOs());
}

@Test
@EnabledOnOs(MAC)
void testMac() {
assertEquals(true, HostOs.findHostOs().isMac());
}

@Test
@EnabledOnOs(SOLARIS)
void testSolaris() {
assertEquals(HostOs.SOLARIS, HostOs.findHostOs());
}

@Test
@EnabledOnOs(FREEBSD)
void testFreeBsd() {
assertEquals(HostOs.FREE_BSD, HostOs.findHostOs());
}

}
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
package com.igormaznitsa.mvnjlink.utils;

import org.junit.Test;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;

public class HttpUtilsTest {
import org.junit.jupiter.api.Test;

class HttpUtilsTest {

@Test
public void testContentTypeParsed() {
assertTrue(new ContentTypeParsed("text/some+json").equals(new ContentTypeParsed("text/json")));
assertTrue(new ContentTypeParsed("text/json").equals(new ContentTypeParsed("text/ddd+fff+json")));
assertFalse(new ContentTypeParsed("image/json").equals(new ContentTypeParsed("text/ddd+fff+json")));
assertFalse(new ContentTypeParsed("image/json").equals(new ContentTypeParsed("text/ddd+fff+json")));
assertFalse(new ContentTypeParsed("text/json").equals(new ContentTypeParsed("text/ddd+fff")));
void testContentTypeParsed() {
assertEquals(new ContentTypeParsed("text/some+json"), new ContentTypeParsed("text/json"));
assertEquals(new ContentTypeParsed("text/json"), new ContentTypeParsed("text/ddd+fff+json"));
assertNotEquals(new ContentTypeParsed("image/json"),
new ContentTypeParsed("text/ddd+fff+json"));
assertNotEquals(new ContentTypeParsed("image/json"),
new ContentTypeParsed("text/ddd+fff+json"));
assertNotEquals(new ContentTypeParsed("text/json"), new ContentTypeParsed("text/ddd+fff"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,24 @@

package com.igormaznitsa.mvnjlink.utils;

import org.apache.commons.io.IOUtils;
import org.junit.Test;
import static com.igormaznitsa.meta.common.utils.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.List;
import org.apache.commons.io.IOUtils;
import org.junit.jupiter.api.Test;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;

public class StringUtilsTest {
class StringUtilsTest {

@Test
public void testExtractFileHash() throws IOException {
assertEquals("ab8674dd80538dd47279d90c37fd51bdac713d2e67ec09c3b4d1cb5d16a3cfa8", StringUtils.extractFileHash("ab8674dd80538dd47279d90c37fd51bdac713d2e67ec09c3b4d1cb5d16a3cfa8 OpenJDK8-OPENJ9_ppc64_AIX_jdk8u162-b12_openj9-0.8.0.tar.gz"));
}

@Test
public void testExtractModuleNames() throws Exception {
void testExtractModuleNames() throws Exception {
final String text = IOUtils.resourceToString("jmods.out", StandardCharsets.UTF_8, StringUtilsTest.class.getClassLoader());
final List<String> modules = StringUtils.extractJdepsModuleNames(text);
assertArrayEquals(
Expand Down

0 comments on commit a71899a

Please sign in to comment.