org.junit.jupiter.api.TestReporter Java Examples

The following examples show how to use org.junit.jupiter.api.TestReporter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GenerateJWTTest.java    From Hands-On-Enterprise-Java-Microservices-with-Eclipse-MicroProfile with MIT License 6 votes vote down vote up
@Test
public void generateJWT(TestReporter reporter) throws Exception {
    KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
    Assumptions.assumeTrue(kpg.getAlgorithm().equals("RSA"));
    kpg.initialize(2048);
    reporter.publishEntry("Created RSA key pair generator of size 2048");
    KeyPair keyPair = kpg.generateKeyPair();
    reporter.publishEntry("Created RSA key pair");
    Assumptions.assumeTrue(keyPair != null, "KeyPair is not null");
    PublicKey publicKey = keyPair.getPublic();
    reporter.publishEntry("RSA.publicKey", publicKey.toString());
    PrivateKey privateKey = keyPair.getPrivate();
    reporter.publishEntry("RSA.privateKey", privateKey.toString());

    assertAll("GenerateJWTTest",
        () -> assertEquals("X.509", publicKey.getFormat()),
        () -> assertEquals("PKCS#8", privateKey.getFormat()),
        () -> assertEquals("RSA", publicKey.getAlgorithm()),
        () -> assertEquals("RSA", privateKey.getAlgorithm())
    );
}
 
Example #2
Source File: NullParentClassLoaderIT.java    From java-9-wtf with Apache License 2.0 6 votes vote down vote up
/**
 * Build a URLClassLoader that only includes the null-parent-classloader artifact in its classpath,
 * along with the bootstrap class loader as its parent.
 *
 * @throws MalformedURLException
 * 		on failure to build the classpath URL
 */
private URLClassLoader buildLoader(TestReporter reporter) throws MalformedURLException {
	String testRootFolder = NullParentClassLoaderIT.class.getResource("/").getPath();
	reporter.publishEntry("Test classes folder", testRootFolder);
	Path projectJar = Paths
			.get(testRootFolder)
			.getParent()
			.resolve("class-loading-1.0-SNAPSHOT.jar");

	assumeTrue(
			projectJar.toFile().exists(),
			"Project JAR must exist as " + projectJar.toString() + " for test to be executed.");
	reporter.publishEntry("Project JAR", projectJar.toString());

	URL path[] = { projectJar.toUri().toURL() };
	// this is the parent that is required when running under Java 9:
	// ClassLoader parent = ClassLoader.getPlatformClassLoader();
	ClassLoader parent = null;
	URLClassLoader loader = new URLClassLoader(path, parent);
	reporter.publishEntry("Class loader", loader.toString());

	return loader;
}
 
Example #3
Source File: BootstrapLoaderTest.java    From java-9-wtf with Apache License 2.0 6 votes vote down vote up
@ParameterizedTest(name = "loading {0}")
@MethodSource(value = "classNames")
public void loadJdkClass(String className, TestReporter reporter) throws ClassNotFoundException {
	TestClassLoader classLoader = new TestClassLoader();

	try {
		Class c = classLoader.loadClass(className);
		reporter.publishEntry(className, "visible");
		// the assertion is pretty useless, but if `c` would not be used,
		// dead code elimination might remove it
		assertThat(c.getName()).isEqualTo(className);
	} catch (ClassNotFoundException ex) {
		reporter.publishEntry(className, "not visible");
		throw ex;
	}
}
 
Example #4
Source File: TransformTest.java    From java-9-wtf with Apache License 2.0 5 votes vote down vote up
@Test // expected to pass on Java 9 because new nodes are always correctly indented
void newNodesAreIndented(TestReporter reporter) throws Exception {
	Document document = parse(INITIAL_XML);
	setChildNode(document, "node", "inner", "inner node content");
	Lines transformation = transform(document);

	reporter.publishEntry("Transformed XML", "\n" + transformation);

	assertThat(transformation.lineWith("<inner>")).isEqualTo("        <inner>inner node content</inner>");
}
 
Example #5
Source File: DataproviderMethodParameterAcceptanceTest.java    From junit-dataprovider with Apache License 2.0 5 votes vote down vote up
@DataProvider
static Object[][] loadFromExternalFile(TestInfo testInfo, TestReporter testReporter) {
    checkNotNull(testInfo, "'testInfo' is not set");
    checkNotNull(testReporter, "'testReporter' is not set");

    String testDataFile = testInfo.getTestMethod().get().getAnnotation(ExternalFile.class).value();
    // Load the data from the external file here ...
    return new Object[][] { { testDataFile } };
}
 
Example #6
Source File: DataProviderMethodParameterAcceptanceTest.java    From junit-dataprovider with Apache License 2.0 5 votes vote down vote up
@DataProvider
static Object[][] loadFromExternalFile(TestInfo testInfo, TestReporter testReporter) {
    checkNotNull(testInfo, "'testInfo' is not set");
    checkNotNull(testReporter, "'testReporter' is not set");

    String testDataFile = testInfo.getTestMethod().get().getAnnotation(ExternalFile.class).value();
    // Load the data from the external file here ...
    return new Object[][] { { testDataFile } };
}
 
Example #7
Source File: SpringExtensionTests.java    From spring-test-junit5 with Apache License 2.0 5 votes vote down vote up
@Test
void junitAndSpringMethodInjectionCombined(@Autowired Cat kittyCat, TestInfo testInfo, ApplicationContext context,
		TestReporter testReporter) {

	assertNotNull(testInfo, "TestInfo should have been injected by JUnit");
	assertNotNull(testReporter, "TestReporter should have been injected by JUnit");

	assertNotNull(context, "ApplicationContext should have been injected by Spring");
	assertNotNull(kittyCat, "Cat should have been @Autowired by Spring");
}
 
Example #8
Source File: ArgumentAggregatorTest.java    From demo-junit-5 with Creative Commons Zero v1.0 Universal 5 votes vote down vote up
@ParameterizedTest
@CsvSource({ "0, 0, 0", "1, 0, 1", "1, 1, 0", "1.414, 1, 1", "2.236, 2, 1" })
// without ArgumentsAccessor in there, this leads to a ParameterResolutionException
void testEatingArguments(double norm, ArgumentsAccessor arguments, TestReporter reporter) {
	reporter.publishEntry("norm", norm + "");
	assertThat(norm).isNotNegative();
}
 
Example #9
Source File: TestReporterTest.java    From Mastering-Software-Testing-with-JUnit-5 with MIT License 5 votes vote down vote up
@Test
void reportSeveralValues(TestReporter testReporter) {
    HashMap<String, String> values = new HashMap<>();
    values.put("name", "john");
    values.put("surname", "doe");

    testReporter.publishEntry(values);
}
 
Example #10
Source File: TransformTest.java    From java-9-wtf with Apache License 2.0 5 votes vote down vote up
@Test // expected to fail on Java 9 because it puts CDATA on its own line
void cDataIsInline(TestReporter reporter) throws Exception {
	Document document = parse(INITIAL_XML);
	setCDataContent(document, "node", "cdata content");
	Lines transformation = transform(document);

	reporter.publishEntry("Transformed XML", "\n" + transformation);

	assertThat(transformation.lineWith("CDATA")).endsWith("<node><![CDATA[cdata content]]></node>");
}
 
Example #11
Source File: SpringExtensionTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
void junitAndSpringMethodInjectionCombined(@Autowired Cat kittyCat, TestInfo testInfo, ApplicationContext context,
		TestReporter testReporter) {

	assertNotNull(testInfo, "TestInfo should have been injected by JUnit");
	assertNotNull(testReporter, "TestReporter should have been injected by JUnit");

	assertNotNull(context, "ApplicationContext should have been injected by Spring");
	assertNotNull(kittyCat, "Cat should have been @Autowired by Spring");
}
 
Example #12
Source File: TransformTest.java    From java-9-wtf with Apache License 2.0 5 votes vote down vote up
@Test // expected to fail on Java 9 because it reformats existing lines
void keepsIndentationOfUnchangedNodes(TestReporter reporter) throws Exception {
	Lines transformation = transform(parse(INITIAL_XML));

	reporter.publishEntry("Transformed XML", "\n" + transformation);

	assertThat(transformation.lineWith("<node")).startsWith("  <node");
}
 
Example #13
Source File: TransformTest.java    From java-9-wtf with Apache License 2.0 5 votes vote down vote up
@Test // expected to pass on Java 9
void pushesRootNodeToUnindentedNewLine(TestReporter reporter) throws Exception {
	Lines transformation = transform(parse(INITIAL_XML));

	reporter.publishEntry("Transformed XML", "\n" + transformation);

	assertThat(transformation.lineAt(0)).doesNotContain("<root");
	assertThat(transformation.lineAt(1)).startsWith("<root");
}
 
Example #14
Source File: RegisterExtensionSpringExtensionTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
void junitAndSpringMethodInjectionCombined(@Autowired Cat kittyCat, TestInfo testInfo,
		ApplicationContext context, TestReporter testReporter) {

	assertNotNull(testInfo, "TestInfo should have been injected by JUnit");
	assertNotNull(testReporter, "TestReporter should have been injected by JUnit");

	assertNotNull(context, "ApplicationContext should have been injected by Spring");
	assertNotNull(kittyCat, "Cat should have been @Autowired by Spring");
}
 
Example #15
Source File: SpringExtensionTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
void junitAndSpringMethodInjectionCombined(@Autowired Cat kittyCat, TestInfo testInfo, ApplicationContext context,
		TestReporter testReporter) {

	assertNotNull(testInfo, "TestInfo should have been injected by JUnit");
	assertNotNull(testReporter, "TestReporter should have been injected by JUnit");

	assertNotNull(context, "ApplicationContext should have been injected by Spring");
	assertNotNull(kittyCat, "Cat should have been @Autowired by Spring");
}
 
Example #16
Source File: RegisterExtensionSpringExtensionTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
void junitAndSpringMethodInjectionCombined(@Autowired Cat kittyCat, TestInfo testInfo,
		ApplicationContext context, TestReporter testReporter) {

	assertNotNull(testInfo, "TestInfo should have been injected by JUnit");
	assertNotNull(testReporter, "TestReporter should have been injected by JUnit");

	assertNotNull(context, "ApplicationContext should have been injected by Spring");
	assertNotNull(kittyCat, "Cat should have been @Autowired by Spring");
}
 
Example #17
Source File: TestReporterTest.java    From mastering-junit5 with Apache License 2.0 5 votes vote down vote up
@Test
void reportSeveralValues(TestReporter testReporter) {
    HashMap<String, String> values = new HashMap<>();
    values.put("name", "john");
    values.put("surname", "doe");

    testReporter.publishEntry(values);
}
 
Example #18
Source File: NullParentClassLoaderIT.java    From java-9-wtf with Apache License 2.0 5 votes vote down vote up
/**
 * Attempt to load a class from the URLClassLoader that references a java.sql.* class. The
 * java.sql.* package is one of those not visible to the Java 9 bootstrap class loader that
 * was visible to the Java 8 bootstrap class loader.
 */
@Test
public void loadSqlDateUsingNullParent(TestReporter reporter) throws Exception {
	URLClassLoader loader = buildLoader(reporter);

	Class<?> jsqlUserClass = loader.loadClass("wtf.java9.class_loading.JavaSqlUser");
	reporter.publishEntry("Loaded class", jsqlUserClass.toString());

	Object jsqlUser = jsqlUserClass.getConstructor().newInstance();
	reporter.publishEntry("Created instance", jsqlUser.toString());

	loader.close();
}
 
Example #19
Source File: TransformTest.java    From java-9-wtf with Apache License 2.0 5 votes vote down vote up
@Test
void doesNotAddEmptyLines(TestReporter reporter) throws Exception {
	Lines transformation = transform(parse(INITIAL_XML));

	reporter.publishEntry("Transformed XML", "\n" + transformation);

	assertThat(transformation.lineAt(2).trim()).isNotEmpty();
}
 
Example #20
Source File: TransformTest.java    From java-9-wtf with Apache License 2.0 5 votes vote down vote up
@Test // expected to fail on Java 9 because it puts in new lines
void doesNotAddEmptyLines(TestReporter reporter) throws Exception {
	Lines transformation = transform(parse(INITIAL_XML));

	reporter.publishEntry("Transformed XML", "\n" + transformation);

	assertThat(transformation.lineAt(2).trim()).isNotEmpty();
}
 
Example #21
Source File: TestReporterTest.java    From Mastering-Software-Testing-with-JUnit-5 with MIT License 4 votes vote down vote up
@Test
void reportSingleValue(TestReporter testReporter) {
    testReporter.publishEntry("key", "value");
}
 
Example #22
Source File: ServiceArtifactBuilderTest.java    From exonum-java-binding with Apache License 2.0 4 votes vote down vote up
@BeforeEach
void setUp(@TempDir Path tempDir, TestReporter reporter) {
  jarPath = tempDir.resolve("test.jar");
  reporter.publishEntry("Test JAR path", jarPath.toString());
}
 
Example #23
Source File: OrderTests.java    From demo-junit-5 with Creative Commons Zero v1.0 Universal 4 votes vote down vote up
@Test
@ExtendWith(RandomIntegerResolver.class)
void customParameterFirst(int randomized, TestReporter reporter) {
	reporter.publishEntry("first parameter", "" + randomized);
}
 
Example #24
Source File: OrderTests.java    From demo-junit-5 with Creative Commons Zero v1.0 Universal 4 votes vote down vote up
@Test
@ExtendWith(RandomIntegerResolver.class)
void jupiterParameterFirst(TestReporter reporter, int randomized) {
	reporter.publishEntry("first parameter", "" + randomized);
}
 
Example #25
Source File: OrderTests.java    From demo-junit-5 with Creative Commons Zero v1.0 Universal 4 votes vote down vote up
@RepeatedTest(3)
@ExtendWith(RandomIntegerResolver.class)
void repetitionInfoFirst(RepetitionInfo info, TestReporter reporter, int randomized) {
	reporter.publishEntry("first parameter", "" + randomized);
}
 
Example #26
Source File: OrderTests.java    From demo-junit-5 with Creative Commons Zero v1.0 Universal 4 votes vote down vote up
@RepeatedTest(3)
@ExtendWith(RandomIntegerResolver.class)
void repetitionInfoLast(TestReporter reporter, int randomized, RepetitionInfo info) {
	reporter.publishEntry("first parameter", "" + randomized);
}
 
Example #27
Source File: ArgumentSourcesTest.java    From demo-junit-5 with Creative Commons Zero v1.0 Universal 4 votes vote down vote up
@ParameterizedTest
@ValueSource(strings = { "Hello", "Parameterized" })
void withOtherParams(String word, TestInfo info, TestReporter reporter) {
	reporter.publishEntry(info.getDisplayName(), "Word: " + word);
	assertNotNull(word);
}
 
Example #28
Source File: TestReporterTest.java    From mastering-junit5 with Apache License 2.0 4 votes vote down vote up
@Test
void reportSingleValue(TestReporter testReporter) {
    testReporter.publishEntry("key", "value");
}
 
Example #29
Source File: PioneerTest.java    From demo-junit-5 with Creative Commons Zero v1.0 Universal 4 votes vote down vote up
@Test
@ExtendWith(TempDirectory.class)
void testTempDirInjection(@TempDir Path tempDir, TestReporter reporter) {
	assertNotNull(tempDir);
	reporter.publishEntry("Temporary directory", tempDir.toString());
}