Tests for help display
This commit is contained in:
parent
b9fe85996b
commit
a3ff15484b
|
@ -37,15 +37,19 @@ public class Display {
|
|||
final static String CURLY_START = "\\{\\{";
|
||||
final static String CURLY_END = "\\}\\}";
|
||||
|
||||
final static String getMoustacheString(final String string) {
|
||||
return CURLY_START + string + CURLY_END;
|
||||
}
|
||||
|
||||
final static String[][] PLACEHOLDERS = {
|
||||
{ CURLY_START + "XML_AND_JSON_FHIR_VERSIONS" + CURLY_END, "1.0, 1.4, 3.0, 4.0," + Constants.VERSION_MM },
|
||||
{ CURLY_START + "TURTLE_FHIR_VERSIONS" + CURLY_END, "3.0, 4.0, " + Constants.VERSION_MM },
|
||||
{ CURLY_START + "FHIR_MAJOR_VERSIONS" + CURLY_END, "1.0|1.4|3.0|" + VersionUtilities.CURRENT_VERSION},
|
||||
{ CURLY_START + "FHIR_MINOR_VERSIONS" + CURLY_END, "1.0.2|1.4.0|3.0.2|4.0.1|" + VersionUtilities.CURRENT_FULL_VERSION },
|
||||
{ CURLY_START + "FHIR_CURRENT_VERSION" + CURLY_END, VersionUtilities.CURRENT_VERSION},
|
||||
{ getMoustacheString("XML_AND_JSON_FHIR_VERSIONS"), "1.0, 1.4, 3.0, 4.0," + Constants.VERSION_MM },
|
||||
{ getMoustacheString("TURTLE_FHIR_VERSIONS"), "3.0, 4.0, " + Constants.VERSION_MM },
|
||||
{ getMoustacheString("FHIR_MAJOR_VERSIONS"), "1.0|1.4|3.0|" + VersionUtilities.CURRENT_VERSION},
|
||||
{ getMoustacheString("FHIR_MINOR_VERSIONS"), "1.0.2|1.4.0|3.0.2|4.0.1|" + VersionUtilities.CURRENT_FULL_VERSION },
|
||||
{ getMoustacheString("FHIR_CURRENT_VERSION"), VersionUtilities.CURRENT_VERSION},
|
||||
};
|
||||
|
||||
final static String replacePlaceholders(String input, String[][] placeholders) {
|
||||
final static String replacePlaceholders(final String input, final String[][] placeholders) {
|
||||
String output = input;
|
||||
for (String[] placeholder : placeholders) {
|
||||
output = output.replaceAll(placeholder[0], placeholder[1]);
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
package org.hl7.fhir.validation.cli.utils;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.PrintStream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class DisplayTests {
|
||||
|
||||
@Test
|
||||
public void displayHelpDetails() {
|
||||
final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
|
||||
final ByteArrayOutputStream errContent = new ByteArrayOutputStream();
|
||||
|
||||
final PrintStream originalOut = System.out;
|
||||
final PrintStream originalErr = System.err;
|
||||
|
||||
System.setOut(new PrintStream(outContent));
|
||||
System.setErr(new PrintStream(errContent));
|
||||
|
||||
try {
|
||||
Display.displayHelpDetails();
|
||||
|
||||
String output = outContent.toString();
|
||||
|
||||
for (String[] placeHolder: Display.PLACEHOLDERS) {
|
||||
assertTrue(output.contains(placeHolder[1]), placeHolder[1] + " is not contained in output:\n" + output);
|
||||
assertFalse(output.contains(placeHolder[0]), placeHolder[0] + " found in output:\n" + output);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
System.setOut(originalOut);
|
||||
System.setErr(originalErr);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReplacePlaceholdersBaseCase() {
|
||||
|
||||
final String myTestString = "The {{DUMMY_A}} jumps over the {{DUMMY_B}}.";
|
||||
final String[][] placeHolders = {
|
||||
{ "\\{\\{DUMMY_A\\}\\}", "quick brown fox"},
|
||||
{ "\\{\\{DUMMY_B\\}\\}", "lazy dog"},
|
||||
};
|
||||
|
||||
final String expectedOutput = "The quick brown fox jumps over the lazy dog.";
|
||||
final String output = Display.replacePlaceholders(myTestString, placeHolders);
|
||||
|
||||
assertEquals(expectedOutput, output);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue