cryptomator / cryptofs

Java Filesystem Provider with integrated encryption
GNU Affero General Public License v3.0
94 stars 35 forks source link

Reflective access for module dependencies in test runs #107

Closed infeo closed 3 years ago

infeo commented 3 years ago

Description

There are tests which run inside the IDE, but will fail when the test is executed with maven. This is related to the Java Module System.

Explanation

With commit 7b24e84 the project was migrated to the Java Module System.

Intellij IDEA uses the classpath for executing test classes, while maven uses the module path.

Unfortunately, certain testing functionalities cannot be used in the module system without workarounds, e.g. spying with Mockito an object with package private constructor. To do so, our module needs to be opened towards the mockito module. But Instead of opening our project globally or dependecy-specifically in general, this should only be done during testing.

Workaround

The current workaround is to open every package containing a failing test towards the necessary dependency in the surefire plugin configuration (to be found in pom.xml).

For example:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>3.0.0-M5</version>
    <configuration>
                <!-- This property needs to be edited -->
        <argLine>--add-opens=org.cryptomator.cryptofs/org.cryptomator.cryptofs.health.dirid=ALL-UNNAMED,</argLine>
    </configuration>
</plugin>

The ALL-UNAMED variable contains all modules which are not yet migrated to the module system and are therefore unnamed.


Related issues in other projects: Surefireplugin: https://issues.apache.org/jira/browse/SUREFIRE-1811?focusedCommentId=17147265&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-17147265 Intellij IDEA: https://youtrack.jetbrains.com/issue/IDEA-222831