When running it on my IDE, the tests passes without failing. But when I've committed it to a repository, the pipeline raises this error for all of the tests.
I'm testing my client scenes with TestFX, Mockito and JUnit 5.
JoinPageCtrlTest > testClearFields() FAILED
java.lang.RuntimeException at WaitForAsyncUtils.java:301
Caused by: java.lang.RuntimeException at QuantumToolkit.java:300
Caused by: java.lang.UnsatisfiedLinkError at ClassLoader.java:2458
My test class
package client.scenes;
import client.utils.ServerUtils;
import jakarta.ws.rs.WebApplicationException;
import javafx.application.Platform;
import javafx.scene.control.TextField;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import commons.Event;
import org.testfx.framework.junit5.ApplicationTest;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.*;
public class JoinPageCtrlTest extends ApplicationTest {
@Mock
private ServerUtils server;
@Mock
private MainCtrl mainCtrl;
@InjectMocks
private JoinPageCtrl joinPageCtrl;
@BeforeEach
public void setUp() {
MockitoAnnotations.initMocks(this);
joinPageCtrl = new JoinPageCtrl(server, mainCtrl);
TextField testEvent =
new TextField();
testEvent.setText("Test Event");
TextField testJoinCode =
new TextField();
testJoinCode.setText("123456");
joinPageCtrl.setEventName(testEvent);
joinPageCtrl.setJoinCode(testJoinCode);
}
@Test
public void testClearFields() {
joinPageCtrl.clear();
assertEquals("", joinPageCtrl.getEventName());
assertEquals("", joinPageCtrl.getJoinCode());
}
@Test
public void testCreateSuccess() {
Event event = new Event("Test Event");
joinPageCtrl.create();
verify(server, times(1)).addEvent(event);
verify(mainCtrl, times(1)).showEvent(event);
}
@Test
public void testCreateFail(){
String invalidCode = "Invalid code";
TextField invalid = new TextField();
invalid.setText("Invalid code");
joinPageCtrl.setJoinCode(invalid);
when(server.getEvent(invalidCode))
.thenThrow(WebApplicationException.class);
Platform.runLater(() -> {
joinPageCtrl.join();
verify(server, times(1))
.getEvent(invalidCode);
verify(mainCtrl, never()).showEvent(any(Event.class));
});
}
@Test
public void testNullCreate(){
TextField invalid = new TextField();
invalid.setText(null);
joinPageCtrl.setJoinCode(null);
doThrow(NullPointerException.class)
.when(server).addEvent(null);
assertThrows(NullPointerException.class, () -> joinPageCtrl.create());
}
@Test
public void testJoinSuccess() {
String joinCode = "123456";
Event event = new Event("Test Event");
when(server.getEvent(joinCode)).thenReturn(event);
joinPageCtrl.join();
verify(server, times(1)).getEvent(joinCode);
verify(mainCtrl, times(1)).showEvent(event);
}
@Test
public void testJoinFail(){
String invalidCode = "Invalid code";
TextField invalid = new TextField();
invalid.setText(invalidCode);
joinPageCtrl.setJoinCode(invalid);
Mockito.when(server.getEvent(invalidCode))
.thenThrow(WebApplicationException.class);
Platform.runLater(() -> {
joinPageCtrl.join();
verify(server, times(1))
.getEvent(invalidCode);
verify(mainCtrl, never()).showEvent(any(Event.class));
});
}
@Test
public void testNullJoinCode(){
TextField invalid = new TextField();
invalid.setText(null);
joinPageCtrl.setJoinCode(null);
doThrow(NullPointerException.class)
.when(server).getEvent(null);
assertThrows(NullPointerException.class, () -> joinPageCtrl.join());
}
}
I've tried changing a few of the tests, but I still kept getting this error. I find it weird, since it works in my IDE but not on the pipeline of my repository.