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

Improve handling of JUnit support with regard to Kotlin #77

Closed
codecholeric opened this issue Jun 2, 2018 · 4 comments
Closed

Improve handling of JUnit support with regard to Kotlin #77

codecholeric opened this issue Jun 2, 2018 · 4 comments

Comments

@codecholeric
Copy link
Collaborator

When Kotlin is used together with the JUnit support, writing rules becomes too bloated, since it's necessary to create a companion object due to the static requirements for fields.
I.e. at the moment ArchUnit JUnit tests in Kotlin have to be written like

@RunWith(ArchUnitRunner::class)
@AnalyzeClasses(packages = ["com.mycompany.myapp"])
class MyArchitectureTest {

    companion object {
        @ArchTest @JvmField val myRule = classes()
            .that().resideInAPackage("..service..")
            .should().onlyBeAccessed().byAnyPackage("..controller..", "..service..")
    }
}

This seems unnecessary bloated, what we would want, is

@RunWith(ArchUnitRunner::class)
@AnalyzeClasses(packages = ["com.mycompany.myapp"])
class MyArchitectureTest {

     @ArchTest val myRule = classes()
            .that().resideInAPackage("..service..")
            .should().onlyBeAccessed().byAnyPackage("..controller..", "..service..")

}
@maheshksd
Copy link

I am working on this

@codecholeric
Copy link
Collaborator Author

Thanks 😃 Let me know if you need any further support!!

@codecholeric
Copy link
Collaborator Author

I've noticed, that another problem is, that non-Java source files create wrong links, e.g. MyClass.kt will be reported as

violation in (MyClass.java:20)

or similar, which is obviously wrong. The info seems commonly recorded in Java/Kotlin class files, so I'll fix this on this issue as well.

@codecholeric
Copy link
Collaborator Author

Also what is your status on this issue @maheshksd? Because this weekend I'll probably merge the JUnit 5 feature branch back into master, which will mean, that this issue needs to be tackled in two places.
(I'm happy to provide some hints though or work together with you if you want)

codecholeric added a commit that referenced this issue Aug 3, 2018
…ion(..) assumed that the file name will always be simpleName of enclosing class + ".java". ASM allows to read the source file name from Java bytecode, provided it was compiled into the class-file. This patch adds Optional<sourceFileName> to Source and a 2-step approach within formatLocation(..) that will first try to derive the location from the real source file name, and only if that is not present will use the old heuristic to determine the source file name.

Issue: #77
Signed-off-by: Peter Gafert <peter.gafert@tngtech.com>
codecholeric added a commit that referenced this issue Aug 12, 2018
… as well, so tests can just be written naturally in Kotlin without any need for a companion object.

Issue: #77
Signed-off-by: Peter Gafert <peter.gafert@tngtech.com>
codecholeric added a commit that referenced this issue Aug 12, 2018
… as well.

Issue: #77
Signed-off-by: Peter Gafert <peter.gafert@tngtech.com>
codecholeric added a commit that referenced this issue Aug 12, 2018
…on object anymore.

Issue: #77
Signed-off-by: Peter Gafert <peter.gafert@tngtech.com>
codecholeric added a commit that referenced this issue Aug 12, 2018
… as well, so tests can just be written naturally in Kotlin without any need for a companion object.

Issue: #77
Signed-off-by: Peter Gafert <peter.gafert@tngtech.com>
codecholeric added a commit that referenced this issue Aug 12, 2018
… as well.

Issue: #77
Signed-off-by: Peter Gafert <peter.gafert@tngtech.com>
codecholeric added a commit that referenced this issue Aug 12, 2018
…on object anymore.

Issue: #77
Signed-off-by: Peter Gafert <peter.gafert@tngtech.com>
@codecholeric codecholeric added this to the 0.9.0 milestone Aug 19, 2018
codecholeric added a commit that referenced this issue Feb 21, 2021
…ion(..) assumed that the file name will always be simpleName of enclosing class + ".java". ASM allows to read the source file name from Java bytecode, provided it was compiled into the class-file. This patch adds Optional<sourceFileName> to Source and a 2-step approach within formatLocation(..) that will first try to derive the location from the real source file name, and only if that is not present will use the old heuristic to determine the source file name.

Issue: #77
Signed-off-by: Peter Gafert <peter.gafert@tngtech.com>
codecholeric added a commit that referenced this issue Feb 21, 2021
… as well, so tests can just be written naturally in Kotlin without any need for a companion object.

Issue: #77
Signed-off-by: Peter Gafert <peter.gafert@tngtech.com>
codecholeric added a commit that referenced this issue Feb 21, 2021
… as well.

Issue: #77
Signed-off-by: Peter Gafert <peter.gafert@tngtech.com>
codecholeric added a commit that referenced this issue Feb 21, 2021
…on object anymore.

Issue: #77
Signed-off-by: Peter Gafert <peter.gafert@tngtech.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants