Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display JVM differences with the user-defined JVM comparison mode #195

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
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ public boolean isDisconnect() {

@SuppressWarnings("unused") // jelly
public String toHtml(String version) {
if (!version.equals("N/A") && !version.equals(CONTROLLER_VERSION.toString())) {
if (version == null || version.equals("N/A")) {
return "N/A";
}
final JVMVersionComparator jvmVersionComparator =
new JVMVersionComparator(CONTROLLER_VERSION, Runtime.Version.parse(version), comparisonMode);
if (jvmVersionComparator.isNotCompatible()) {
return Util.wrapToErrorSpan(version);
}
return version;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

Expand Down Expand Up @@ -43,4 +44,52 @@ public void checkComparisonMode(JVMVersionComparator.ComparisonMode comparisonMo
JVMVersionMonitor object = new JVMVersionMonitor(comparisonMode, disconnect);
assertEquals(comparisonMode, object.getComparisonMode());
}

@Test
public void checkToHtmlRendering() throws Exception {

JVMVersionMonitor object = new JVMVersionMonitor(JVMVersionComparator.ComparisonMode.EXACT_MATCH, false);

// N/A
assertEquals("N/A", object.toHtml(null));
assertEquals("N/A", object.toHtml("N/A"));

// EXACT_MATCH
assertEquals(
Runtime.version().toString(), object.toHtml(Runtime.version().toString()));
assertEquals(asError("1.1.1.1+1"), object.toHtml("1.1.1.1+1"));

// RUNTIME_GREATER_OR_EQUAL_MASTER_BYTECODE
object = new JVMVersionMonitor(
JVMVersionComparator.ComparisonMode.RUNTIME_GREATER_OR_EQUAL_MASTER_BYTECODE, false);
assertEquals(
Runtime.version().toString(), object.toHtml(Runtime.version().toString()));
assertEquals(majorGreater(), object.toHtml(majorGreater()));
assertEquals(majorVersionMatch(), object.toHtml(majorVersionMatch()));
assertEquals(asError(majorLower()), object.toHtml(majorLower()));

// MAJOR_MINOR_MATCH
object = new JVMVersionMonitor(JVMVersionComparator.ComparisonMode.MAJOR_MINOR_MATCH, false);
assertEquals(
Runtime.version().toString(), object.toHtml(Runtime.version().toString()));
assertEquals(majorGreater(), object.toHtml(majorGreater()));
assertEquals(majorVersionMatch(), object.toHtml(majorVersionMatch()));
assertEquals(asError(majorLower()), object.toHtml(majorLower()));
}

private String majorVersionMatch() {
return Runtime.version().feature() + ".99.99.99+99";
}

private String majorLower() {
return "1.99.99.99+99";
}

private String majorGreater() {
return "999.99.99.99+99";
}

private String asError(String version) {
return "<span class=error style='display:inline-block'>" + version + "</span>";
}
}