类org.junit.jupiter.api.TestReporter源码实例Demo

下面列出了怎么用org.junit.jupiter.api.TestReporter的API类实例代码及写法,或者点击链接到github查看源代码。

@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())
    );
}
 
源代码2 项目: java-9-wtf   文件: NullParentClassLoaderIT.java
/**
 * 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;
}
 
源代码3 项目: java-9-wtf   文件: BootstrapLoaderTest.java
@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;
	}
}
 
@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");
}
 
@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");
}
 
@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");
}
 
@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");
}
 
源代码8 项目: mastering-junit5   文件: TestReporterTest.java
@Test
void reportSeveralValues(TestReporter testReporter) {
    HashMap<String, String> values = new HashMap<>();
    values.put("name", "john");
    values.put("surname", "doe");

    testReporter.publishEntry(values);
}
 
源代码9 项目: java-9-wtf   文件: NullParentClassLoaderIT.java
/**
 * 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();
}
 
源代码10 项目: java-9-wtf   文件: TransformTest.java
@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();
}
 
源代码11 项目: java-9-wtf   文件: TransformTest.java
@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");
}
 
源代码12 项目: java-9-wtf   文件: TransformTest.java
@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();
}
 
源代码13 项目: java-9-wtf   文件: TransformTest.java
@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");
}
 
源代码14 项目: java-9-wtf   文件: TransformTest.java
@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>");
}
 
源代码15 项目: java-9-wtf   文件: TransformTest.java
@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>");
}
 
@Test
void reportSeveralValues(TestReporter testReporter) {
    HashMap<String, String> values = new HashMap<>();
    values.put("name", "john");
    values.put("surname", "doe");

    testReporter.publishEntry(values);
}
 
源代码17 项目: demo-junit-5   文件: ArgumentAggregatorTest.java
@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();
}
 
源代码18 项目: spring-test-junit5   文件: SpringExtensionTests.java
@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");
}
 
@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 } };
}
 
@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 } };
}
 
源代码21 项目: mastering-junit5   文件: TestReporterTest.java
@Test
void reportSingleValue(TestReporter testReporter) {
    testReporter.publishEntry("key", "value");
}
 
@Test
void reportSingleValue(TestReporter testReporter) {
    testReporter.publishEntry("key", "value");
}
 
@BeforeEach
void setUp(@TempDir Path tempDir, TestReporter reporter) {
  jarPath = tempDir.resolve("test.jar");
  reporter.publishEntry("Test JAR path", jarPath.toString());
}
 
源代码24 项目: demo-junit-5   文件: OrderTests.java
@Test
@ExtendWith(RandomIntegerResolver.class)
void customParameterFirst(int randomized, TestReporter reporter) {
	reporter.publishEntry("first parameter", "" + randomized);
}
 
源代码25 项目: demo-junit-5   文件: OrderTests.java
@Test
@ExtendWith(RandomIntegerResolver.class)
void jupiterParameterFirst(TestReporter reporter, int randomized) {
	reporter.publishEntry("first parameter", "" + randomized);
}
 
源代码26 项目: demo-junit-5   文件: OrderTests.java
@RepeatedTest(3)
@ExtendWith(RandomIntegerResolver.class)
void repetitionInfoFirst(RepetitionInfo info, TestReporter reporter, int randomized) {
	reporter.publishEntry("first parameter", "" + randomized);
}
 
源代码27 项目: demo-junit-5   文件: OrderTests.java
@RepeatedTest(3)
@ExtendWith(RandomIntegerResolver.class)
void repetitionInfoLast(TestReporter reporter, int randomized, RepetitionInfo info) {
	reporter.publishEntry("first parameter", "" + randomized);
}
 
源代码28 项目: demo-junit-5   文件: ArgumentSourcesTest.java
@ParameterizedTest
@ValueSource(strings = { "Hello", "Parameterized" })
void withOtherParams(String word, TestInfo info, TestReporter reporter) {
	reporter.publishEntry(info.getDisplayName(), "Word: " + word);
	assertNotNull(word);
}
 
源代码29 项目: demo-junit-5   文件: PioneerTest.java
@Test
@ExtendWith(TempDirectory.class)
void testTempDirInjection(@TempDir Path tempDir, TestReporter reporter) {
	assertNotNull(tempDir);
	reporter.publishEntry("Temporary directory", tempDir.toString());
}
 
 类所在包
 类方法
 同包方法