Skip to content

Commit

Permalink
Add support for Mockito/ByteBuddy requiring javaagent on Java 21
Browse files Browse the repository at this point in the history
- See mockito/mockito#3037
- See https://javadoc.io/doc/org.mockito/mockito-core/latest/org/mockito/Mockito.html#0.3
- Requires Mockito 5.14.0 or later which allows you to specify Mockito itself as an agent rather than ByteBuddy

- Note - all test plug-ins need to declare a dependency on Mockito so that the mockito jar property ${org.mockito:mockito-core:jar} is always resolved for each test run

- To run JUnit in Eclipse you need to add the following VM arguments (adjust path version as required):

-Xshare:off
-javaagent:${workspace_loc}/.metadata/.plugins/org.eclipse.pde.core/.bundle_pool/plugins/org.mockito.mockito-core_5.14.2.jar

- Or, for now, it's simpler to add the following VM arguments:

-Xshare:off
-XX:+EnableDynamicAgentLoading
  • Loading branch information
Phillipus committed Nov 19, 2024
1 parent 35d3b37 commit d87b664
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Set up Java
uses: actions/setup-java@v4
with:
java-version: '17'
java-version: '21'
distribution: 'temurin'
cache: 'maven'

Expand Down
4 changes: 2 additions & 2 deletions com.archimatetool.editor.product/archi.target
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
<unit id="org.eclipse.jgit.ssh.apache.feature.group" version="6.10.0.202406032230-r"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
<repository location="https://download.eclipse.org/tools/orbit/simrel/orbit-aggregation/release/4.32.0"/>
<unit id="org.mockito.mockito-core" version="5.12.0"/>
<repository location="https://download.eclipse.org/tools/orbit/simrel/orbit-aggregation/release/4.34.0"/>
<unit id="org.mockito.mockito-core" version="5.14.2"/>
</location>
</locations>
</target>
30 changes: 26 additions & 4 deletions tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,30 @@

<artifactId>com.archimatetool.testing</artifactId>
<packaging>pom</packaging>


<properties>
<!-- Mockito/ByteBuddy needs this on Java 21+ -->
<mockito.args>-Xshare:off -javaagent:${org.mockito:mockito-core:jar}</mockito.args>

<!-- <tycho.testArgLine> is passed as <argLine> to tycho-surefire-plugin -->
<tycho.testArgLine>${mockito.args}</tycho.testArgLine>
</properties>

<!-- Orbit p2 repo provides Mockito and latest JUnit for tests -->
<repositories>
<repository>
<id>Orbit</id>
<layout>p2</layout>
<url>https://download.eclipse.org/tools/orbit/simrel/orbit-aggregation/release/4.32.0</url>
<url>https://download.eclipse.org/tools/orbit/simrel/orbit-aggregation/release/4.34.0</url>
</repository>
</repositories>

<modules>
<module>com.archimatetool.testsupport</module>

<module>com.archimatetool.canvas.tests</module>
<module>com.archimatetool.csv.tests</module>
<module>com.archimatetool.commandline.tests</module>
<module>com.archimatetool.csv.tests</module>
<module>com.archimatetool.editor.tests</module>
<module>com.archimatetool.export.svg.tests</module>
<module>com.archimatetool.hammer.tests</module>
Expand All @@ -43,6 +51,20 @@

<build>
<plugins>
<!-- With this we can resolve ${org.mockito:mockito-core:jar} -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.8.1</version>
<executions>
<execution>
<goals>
<goal>properties</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-surefire-plugin</artifactId>
Expand All @@ -67,7 +89,7 @@
</os>
</activation>
<properties>
<tycho.testArgLine>-XstartOnFirstThread</tycho.testArgLine>
<tycho.testArgLine>-XstartOnFirstThread ${mockito.args}</tycho.testArgLine>
</properties>
</profile>
</profiles>
Expand Down

0 comments on commit d87b664

Please sign in to comment.