-
-
Notifications
You must be signed in to change notification settings - Fork 18
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
Add default classpath to enable type resolution #154
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,14 @@ | ||
package com.github.ozsie | ||
|
||
import com.github.ozsie.test.CheckMojoTestFactory | ||
import io.github.detekt.tooling.api.MaxIssuesReached | ||
import org.jetbrains.spek.api.Spek | ||
import org.jetbrains.spek.api.dsl.given | ||
import org.jetbrains.spek.api.dsl.on | ||
import java.net.URI | ||
import java.nio.file.Paths | ||
import kotlin.test.assertFailsWith | ||
import kotlin.test.expect | ||
|
||
|
||
class CheckMojoSpec : Spek({ | ||
val invalidPackageNamingDirectoryPath by lazy { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extracted a test factors to separate concerns, reduce duplication and improve readability |
||
val uri = CheckMojoSpec::class.java.classLoader | ||
.getResource("code-samples/invalid-package-naming")!!.toURI() | ||
Paths.get(uri).toString() | ||
} | ||
|
||
given("a CheckMojo and 'skip' is true") { | ||
val checkMojo = CheckMojo() | ||
checkMojo.skip = true | ||
|
@@ -42,11 +34,11 @@ class CheckMojoSpec : Spek({ | |
} | ||
|
||
given("a CheckMojo and 'failBuildOnMaxIssuesReached' is false") { | ||
val checkMojo = CheckMojo().apply { | ||
input = invalidPackageNamingDirectoryPath | ||
val checkMojo = CheckMojoTestFactory.createWithInvalidPackageNamingStructure { | ||
failBuildOnMaxIssuesReached = false | ||
failFast = true // fail on any issue | ||
failFast = true | ||
} | ||
|
||
on("checkMojo.execute()") { | ||
test("Unit is expected") { | ||
expect(Unit) { | ||
|
@@ -57,10 +49,9 @@ class CheckMojoSpec : Spek({ | |
} | ||
|
||
given("a CheckMojo and 'failBuildOnMaxIssuesReached' is true") { | ||
val checkMojo = CheckMojo().apply { | ||
input = invalidPackageNamingDirectoryPath | ||
val checkMojo = CheckMojoTestFactory.createWithInvalidPackageNamingStructure { | ||
failBuildOnMaxIssuesReached = true | ||
failFast = true // fail on any issue | ||
failFast = true | ||
} | ||
on("checkMojo.execute()") { | ||
test("Unit is expected") { | ||
|
@@ -70,4 +61,32 @@ class CheckMojoSpec : Spek({ | |
} | ||
} | ||
} | ||
|
||
given("classpath parameter") { | ||
val checkMojo = CheckMojoTestFactory.createWithNoRuleExecution { | ||
classPath = "/tmp/provided" | ||
} | ||
|
||
on("checkMojo.execute()") { | ||
test("uses provider value") { | ||
expect("/tmp/provided") { | ||
checkMojo.execute() | ||
checkMojo.cliArgs.classpath | ||
} | ||
} | ||
} | ||
} | ||
|
||
given("no classpath parameter") { | ||
val checkMojo = CheckMojoTestFactory.createWithNoRuleExecution() | ||
|
||
on("checkMojo.execute()") { | ||
test("uses default compileClasspathElements") { | ||
expect("/tmp/default${java.io.File.pathSeparatorChar}/tmp/default2") { | ||
checkMojo.execute() | ||
checkMojo.cliArgs.classpath | ||
} | ||
} | ||
} | ||
} | ||
}) |
69 changes: 69 additions & 0 deletions
69
src/test/java/com/github/ozsie/test/CheckMojoTestFactory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.github.ozsie.test | ||
|
||
import com.github.ozsie.CheckMojo | ||
import com.github.ozsie.CheckMojoSpec | ||
import com.nhaarman.mockito_kotlin.any | ||
import com.nhaarman.mockito_kotlin.doReturn | ||
import com.nhaarman.mockito_kotlin.mock | ||
import org.apache.maven.model.Dependency | ||
import org.apache.maven.model.Plugin | ||
import org.apache.maven.project.MavenProject | ||
import java.nio.file.Paths | ||
|
||
object CheckMojoTestFactory { | ||
|
||
private val invalidPackageNamingDirectoryPath by lazy { | ||
val uri = CheckMojoSpec::class.java.classLoader | ||
.getResource("code-samples/invalid-package-naming")!!.toURI() | ||
Paths.get(uri).toString() | ||
} | ||
|
||
private val validPackageNamingDirectoryPath by lazy { | ||
val uri = CheckMojoSpec::class.java.classLoader | ||
.getResource("code-samples/valid")!!.toURI() | ||
Paths.get(uri).toString() | ||
} | ||
|
||
fun create(block: CheckMojo.() -> Unit = {}): CheckMojo { | ||
return CheckMojo().apply { | ||
input = validPackageNamingDirectoryPath | ||
mavenProject = createMockMavenProject() | ||
block(this) | ||
} | ||
} | ||
|
||
fun createWithInvalidPackageNamingStructure(block: CheckMojo.() -> Unit): CheckMojo { | ||
return CheckMojo().apply { | ||
input = invalidPackageNamingDirectoryPath | ||
block(this) | ||
} | ||
} | ||
|
||
fun createWithNoRuleExecution(block: CheckMojo.() -> Unit = {}): CheckMojo { | ||
return create { | ||
disableDefaultRuleSets = true | ||
block(this) | ||
} | ||
} | ||
|
||
private fun createMockMavenProject(): MavenProject { | ||
return mock { | ||
on { | ||
compileClasspathElements | ||
} doReturn listOf("/tmp/default", "/tmp/default2") | ||
on { | ||
getPlugin(any()) | ||
} doReturn ( | ||
Plugin().apply { | ||
dependencies = mutableListOf( | ||
Dependency().apply { | ||
groupId = "a.b" | ||
artifactId = "b" | ||
version = "1" | ||
} | ||
) | ||
} | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package `code-samples`.`valid` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Created a valid input to execute a full testrun. Maybe this is not necessary - not sure. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set to a field for testing purposes. Maybe there is another smart idea of how we can assert the expected outcome.