Skip to content

Commit

Permalink
Merge pull request #95 from macisamuele/maci-unify-temporary-director…
Browse files Browse the repository at this point in the history
…y-usage

Use TemporaryFolder JUnit-Test rule to create temporary directories
  • Loading branch information
macisamuele committed Feb 6, 2020
2 parents 7ae0186 + bec0f65 commit af953eb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 23 deletions.
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)
}
}

0 comments on commit af953eb

Please sign in to comment.