下面列出了怎么用org.junitpioneer.jupiter.TempDirectory.TempDir的API类实例代码及写法,或者点击链接到github查看源代码。
@ParameterizedTest
@ValueSource(strings = {"5.1.1", "5.4.1", "5.6.2"})
public void build(String gradleVersion, @TempDir Path projectDir) throws IOException {
Files.write(projectDir.resolve("settings.gradle"), Collections.singleton("rootProject.name = 'dummy'"));
Files.write(projectDir.resolve("build.gradle"), Arrays.asList(
"plugins {",
" id 'java'",
" id 'groovy'",
" id 'scala'",
" id 'org.joinfaces'",
"}",
"repositories { mavenCentral() }",
"dependencies {",
" compile 'org.apache.myfaces.core:myfaces-impl:2.3.2'",
"}"
));
BuildResult buildResult = GradleRunner.create()
.withProjectDir(projectDir.toFile())
.withPluginClasspath()
.withArguments("jar", "-s", "--info")
.withDebug(true)
.withGradleVersion(gradleVersion)
.build();
BuildTask scanClasspath = buildResult.task(":scanJoinfacesClasspath");
assertThat(scanClasspath).isNotNull();
assertThat(scanClasspath.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
File jarFile = projectDir.resolve("build/libs/dummy.jar").toFile();
assertThat(jarFile).isFile();
try (ZipFile zipFile = new ZipFile(jarFile)) {
assertThat(zipFile.getEntry("META-INF/joinfaces/org.apache.myfaces.ee.MyFacesContainerInitializer.classes")).isNotNull();
assertThat(zipFile.getEntry("META-INF/joinfaces/org.apache.myfaces.spi.AnnotationProvider.classes")).isNotNull();
}
}
@BeforeEach
public void setup(@TempDir Path folder) throws Exception {
fixtureDir = new File(this.getClass().getResource("/fixture").getFile());
this.folder = folder;
config = (DefaultJBakeConfiguration) new ConfigUtil().loadConfig(fixtureDir);
config.setDestinationFolder(folder.toFile());
Assertions.assertEquals(".html", config.getOutputExtension());
}
@Test
@ExtendWith(TempDirectory.class)
void testTempDirInjection(@TempDir Path tempDir, TestReporter reporter) {
assertNotNull(tempDir);
reporter.publishEntry("Temporary directory", tempDir.toString());
}
@BeforeEach
public void setup(@TempDir Path folder) {
this.folder = folder;
}
@BeforeEach
public void setup(@TempDir Path folder) {
this.sourceFolder = folder;
this.util = new ConfigUtil();
}