下面列出了org.junit.jupiter.api.condition.EnabledOnOs#org.junit.jupiter.api.condition.JRE 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Test
@EnabledOnJre(JRE.JAVA_8)
void shouldThrowExceptionWhenXmlRuleDoesNotSatisfySchemaOnJdk8() {
// given
String invalidXmlRule = "" +
"<yare:Rule xmlns:yare=\"http://www.sabre.com/schema/oss/yare/rules/v1\">\n" +
" <yare:unexpectedElement/>\n" +
"</yare:Rule>";
// when / then
assertThatThrownBy(() -> converter.unmarshal(invalidXmlRule))
.isInstanceOf(SchemaValidationException.class)
.hasMessage("Given XML rule does not satisfy schema. Errors:\n" +
"Line: 2. Column: 30. " +
"Error: cvc-complex-type.2.4.a: Invalid content was found starting with element 'yare:unexpectedElement'. " +
"One of '{\"http://www.sabre.com/schema/oss/yare/rules/v1\":Attribute, " +
"\"http://www.sabre.com/schema/oss/yare/rules/v1\":Fact, " +
"\"http://www.sabre.com/schema/oss/yare/rules/v1\":Predicate}' " +
"is expected.");
}
@Test
@DisabledOnJre(JRE.JAVA_8)
void shouldThrowExceptionWhenXmlRuleDoesNotSatisfySchemaOnJdkDifferentThan8() {
// given
String invalidXmlRule = "" +
"<yare:Rule xmlns:yare=\"http://www.sabre.com/schema/oss/yare/rules/v1\">\n" +
" <yare:unexpectedElement/>\n" +
"</yare:Rule>";
// when / then
assertThatThrownBy(() -> converter.unmarshal(invalidXmlRule))
.isInstanceOf(SchemaValidationException.class)
.hasMessage("Given XML rule does not satisfy schema. Errors:\n" +
"Line: 2. Column: 30. " +
"Error: cvc-complex-type.2.4.a: Invalid content was found starting with element '{\"http://www.sabre.com/schema/oss/yare/rules/v1\":unexpectedElement}'. " +
"One of '{\"http://www.sabre.com/schema/oss/yare/rules/v1\":Attribute, " +
"\"http://www.sabre.com/schema/oss/yare/rules/v1\":Fact, " +
"\"http://www.sabre.com/schema/oss/yare/rules/v1\":Predicate}' " +
"is expected.");
}
@Test
@EnabledOnOs(OS.WINDOWS)
@DisabledOnJre(JRE.JAVA_8)
void constructProcessIdWindowsJava9() throws IOException {
Process process = new ProcessBuilder("echo", "Hello world").start();
assertThat(Pid.get(process)).isGreaterThan(0);
}
@Test
@EnabledOnJre(JRE.JAVA_8)
@EnabledOnOs(OS.WINDOWS)
void constructProcessIdWindowsJava8() throws IOException {
Process process = new ProcessBuilder("echo", "Hello world").start();
assertThat(Pid.get(process)).isEqualTo(-1);
}
@DisabledOnJre(JRE.JAVA_8)
@Test
void formattingCzech() throws TemplateValueFormatException, TemplateModelException {
final BigDecimal n = new BigDecimal("0.0001");
final TemplateNumberFormat f = InterestNumberFormatFactory.INSTANCE.get("", Defaults.LOCALE,
Environment.getCurrentEnvironment());
final TemplateNumberModel m = () -> n;
final String result = f.formatToPlainText(m);
assertThat(result.trim()).isEqualTo("0,01" + (char) 160 + "%");
}
@DisabledOnJre(JRE.JAVA_8)
@Test
void formattingCzech2() throws TemplateValueFormatException, TemplateModelException {
final BigDecimal n = new BigDecimal("0.0000");
final TemplateNumberFormat f = InterestNumberFormatFactory.INSTANCE.get("", Defaults.LOCALE,
Environment.getCurrentEnvironment());
final TemplateNumberModel m = () -> n;
final String result = f.formatToPlainText(m);
assertThat(result.trim()).isEqualTo("0,00" + (char) 160 + "%");
}
@DisabledOnJre(JRE.JAVA_8)
@Test
void formattingCzech3() throws TemplateValueFormatException, TemplateModelException {
final BigDecimal n = new BigDecimal("0.001");
final TemplateNumberFormat f = InterestNumberFormatFactory.INSTANCE.get("", Defaults.LOCALE,
Environment.getCurrentEnvironment());
final TemplateNumberModel m = () -> n;
final String result = f.formatToPlainText(m);
assertThat(result.trim()).isEqualTo("0,10" + (char) 160 + "%");
}
@Test
@EnabledForJreRange(min = JRE.JAVA_11)
public void testThatAppCDSAreUsable() throws Exception {
File testDir = initProject("projects/classic", "projects/project-classic-console-output-appcds");
RunningInvoker running = new RunningInvoker(testDir, false);
MavenProcessInvocationResult result = running
.execute(Arrays.asList("package", "-DskipTests", "-Dquarkus.package.create-appcds=true"),
Collections.emptyMap());
await().atMost(1, TimeUnit.MINUTES).until(() -> result.getProcess() != null && !result.getProcess().isAlive());
assertThat(running.log()).containsIgnoringCase("BUILD SUCCESS");
running.stop();
Path jar = testDir.toPath().toAbsolutePath()
.resolve(Paths.get("target/acme-1.0-SNAPSHOT-runner.jar"));
File output = new File(testDir, "target/output.log");
output.createNewFile();
// by using '-Xshare:on' we ensure that the JVM will fail if for any reason is cannot use the AppCDS
// '-Xlog:class+path=info' will print diagnostic information that is useful for debugging if something goes wrong
Process process = doLaunch(jar.getFileName(), output,
Arrays.asList("-XX:SharedArchiveFile=app-cds.jsa", "-Xshare:on", "-Xlog:class+path=info"))
.directory(jar.getParent().toFile()).start();
try {
// Wait until server up
dumpFileContentOnFailure(() -> {
await()
.pollDelay(1, TimeUnit.SECONDS)
.atMost(1, TimeUnit.MINUTES).until(() -> DevModeTestUtils.getHttpResponse("/app/hello/package", 200));
return null;
}, output, ConditionTimeoutException.class);
String logs = FileUtils.readFileToString(output, "UTF-8");
assertThatOutputWorksCorrectly(logs);
} finally {
process.destroy();
}
}
@Test
@DisabledOnJre(value = JRE.JAVA_10)
void test4() {
assertFalse(3 < 0);
}
@Test
@EnabledOnJre(value = JRE.JAVA_10)
void test5() {
assertTrue(System.getProperty("java.version").startsWith("10"));
}
@Test
@EnabledOnOs(OS.LINUX)
@DisabledOnJre(JRE.JAVA_10)
void conflictingConditions_executed() {
assertTrue(true);
}