Skip to content

Commit

Permalink
replace jmockit call with mockito call
Browse files Browse the repository at this point in the history
  • Loading branch information
mtf90 committed Jan 8, 2024
1 parent 510653f commit 5e057de
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 50 deletions.
24 changes: 3 additions & 21 deletions examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ limitations under the License.
<artifactId>cacio-tta</artifactId>
</dependency>
<dependency>
<groupId>org.jmockit</groupId>
<artifactId>jmockit</artifactId>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</dependency>
</dependencies>

Expand All @@ -201,28 +201,10 @@ limitations under the License.
<java.awt.headless>false</java.awt.headless>
</systemPropertyVariables>
<!-- append to existing argLine to nicely work together with jacoco plugin -->
<argLine>
@{argLine}
-javaagent:${org.jmockit:jmockit:jar}
--add-opens=java.base/java.util=xstream
</argLine>
<argLine>@{argLine} --add-opens=java.base/java.util=xstream</argLine>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<!-- set properties, so we can easily resolve the file path to the JMockit jar in the surefire-plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>properties</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
30 changes: 10 additions & 20 deletions examples/src/test/java/de/learnlib/example/ExamplesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,16 @@
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.URI;

import javax.swing.SwingUtilities;

import com.github.caciocavallosilano.cacio.ctc.CTCToolkit;
import de.learnlib.example.aaar.AlternatingBitExampleExplicit;
import de.learnlib.example.aaar.AlternatingBitExampleGeneric;
import mockit.Mock;
import mockit.MockUp;
import net.automatalib.common.util.system.JVMUtil;
import net.automatalib.modelchecker.ltsmin.LTSminUtil;
import net.automatalib.modelchecker.ltsmin.LTSminVersion;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import org.testng.SkipException;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
Expand Down Expand Up @@ -141,23 +139,16 @@ public void testSLIExample2() {
public void testExample1() throws Exception {
requireJVMCompatibility();

// Mock Desktop classes, so we don't actually open a browser during the test
new MockUp<CTCToolkit>() {
@Mock
public boolean isDesktopSupported() {
return true;
}
};
new MockUp<Desktop>() {
@Mock
public void browse(URI uri) throws IOException {
// do nothing
}
};

SwingUtilities.invokeAndWait(() -> {
try {
Example1.main(new String[0]);
final Desktop mock = Mockito.mock(Desktop.class);
Mockito.doNothing().when(mock).browse(Mockito.any());

try (MockedStatic<Desktop> desktop = Mockito.mockStatic(Desktop.class)) {
desktop.when(Desktop::getDesktop).thenReturn(mock);

Example1.main(new String[0]);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand All @@ -182,7 +173,6 @@ public void testExample3() throws InvocationTargetException, InterruptedExceptio
SwingUtilities.invokeAndWait(() -> Example3.main(new String[0]));
}


private static boolean isJVMCompatible() {
return JVMUtil.getCanonicalSpecVersion() == 11;
}
Expand Down
9 changes: 0 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ limitations under the License.
<guava.version>32.1.2-jre</guava.version>
<javapoet.version>1.13.0</javapoet.version>
<jaxb-api.version>2.3.1</jaxb-api.version>
<jmockit.version>1.49</jmockit.version>
<logback.version>1.3.12</logback.version>
<metainf-services.version>1.11</metainf-services.version>
<mockito.version>5.6.0</mockito.version>
Expand Down Expand Up @@ -589,14 +588,6 @@ limitations under the License.
<scope>test</scope>
</dependency>

<!-- JMockit -->
<dependency>
<groupId>org.jmockit</groupId>
<artifactId>jmockit</artifactId>
<version>${jmockit.version}</version>
<scope>test</scope>
</dependency>

<!-- Caciocavallo -->
<dependency>
<groupId>com.github.caciocavallosilano</groupId>
Expand Down

0 comments on commit 5e057de

Please sign in to comment.