Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use TemporaryFolder JUnit-Test rule to create temporary directories #95

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 14 additions & 17 deletions plugin/src/test/java/com/yelp/codegen/MainTest.kt
Original file line number Diff line number Diff line change
@@ -1,34 +1,31 @@
package com.yelp.codegen
import java.io.File
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder

class MainTest {
@get:Rule
val temporaryFolder = TemporaryFolder()

private fun runGenerator(platform: String) {
val temporaryFolder = TemporaryFolder()
val junitTestsSpecsPath = File(
// Repo root
File(".").absoluteFile.parentFile.parentFile.absolutePath,
"samples${File.separator}junit-tests${File.separator}junit_tests_specs.json"
).path

try {
temporaryFolder.create()
main(
listOf(
"-p", platform,
"-i", junitTestsSpecsPath,
"-o", temporaryFolder.newFolder("kotlin").absolutePath,
"-s", "junittests",
"-v", "0.0.1",
"-g", "com.yelp.codegen",
"-a", " generatecodesamples"
).toTypedArray()
)
} finally {
temporaryFolder.delete()
}
main(
listOf(
"-p", platform,
"-i", junitTestsSpecsPath,
"-o", temporaryFolder.newFolder("kotlin").absolutePath,
"-s", "junittests",
"-v", "0.0.1",
"-g", "com.yelp.codegen",
"-a", " generatecodesamples"
).toTypedArray()
)
}

@Test
Expand Down
21 changes: 15 additions & 6 deletions plugin/src/test/java/com/yelp/plugin/PluginTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,32 @@ import java.io.File
import org.gradle.testkit.runner.GradleRunner
import org.gradle.testkit.runner.TaskOutcome
import org.junit.Assert
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder

class PluginTests {
@get:Rule
val temporaryFolder = TemporaryFolder(File("."))

@Test
fun basicPluginTest() {
val tmpDir = File(".", "build/testProject")
tmpDir.deleteRecursively()

println(File(".").absolutePath)
File(".", "src/test/testProject").copyRecursively(tmpDir)
val projectDir = temporaryFolder.newFolder("project")
File("src/test/testProject").copyRecursively(projectDir)

val result = GradleRunner.create().withProjectDir(tmpDir)
val result = GradleRunner.create().withProjectDir(projectDir)
.forwardStdOutput(System.out.writer())
.forwardStdError(System.err.writer())
.withArguments("generateSwagger")
.build()

Assert.assertEquals(TaskOutcome.SUCCESS, result.task(":generateSwagger")?.outcome)

val result2ndRun = GradleRunner.create().withProjectDir(projectDir)
.forwardStdOutput(System.out.writer())
.forwardStdError(System.err.writer())
.withArguments("generateSwagger")
.build()
Assert.assertEquals(TaskOutcome.UP_TO_DATE, result2ndRun.task(":generateSwagger")?.outcome)
}
}