Skip to content

Commit 01ca90b

Browse files
committed
Make Goblint server failure tests work regardless if Goblint is in env
1 parent d830c8d commit 01ca90b

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

src/test/java/GoblintServerTest.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,20 @@
22
import gobpie.GobPieConfReader;
33
import gobpie.GobPieConfiguration;
44
import gobpie.GobPieException;
5+
import guru.nidi.graphviz.service.CommandRunner;
56
import magpiebridge.core.MagpieServer;
67
import org.junit.jupiter.api.Test;
78
import org.junit.jupiter.api.extension.ExtendWith;
9+
import org.mockito.MockedConstruction;
10+
import org.zeroturnaround.exec.ProcessExecutor;
11+
import org.zeroturnaround.exec.ProcessOutput;
12+
import org.zeroturnaround.exec.ProcessResult;
813
import uk.org.webcompere.systemstubs.jupiter.SystemStub;
914
import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension;
1015
import uk.org.webcompere.systemstubs.stream.SystemOut;
1116

17+
import java.io.IOException;
18+
import java.nio.charset.StandardCharsets;
1219
import java.util.List;
1320

1421
import static org.junit.jupiter.api.Assertions.*;
@@ -64,7 +71,7 @@ public void testStartGoblintServerFailed() {
6471
GoblintServer goblintServer = spy(new GoblintServer(magpieServer, gobPieConfiguration));
6572

6673
// Mock behavior to return the executable command and abstract debugging
67-
when(gobPieConfiguration.goblintExecutable()).thenReturn("goblint");
74+
when(gobPieConfiguration.goblintExecutable()).thenReturn("/definitely/not/a/real/binary");
6875
when(gobPieConfiguration.abstractDebugging()).thenReturn(true);
6976

7077
// Assert that starting Goblint server throws GobPieException
@@ -104,16 +111,12 @@ public void testCheckGoblintVersion() {
104111
@Test
105112
public void testCheckGoblintVersionFailed() {
106113
MagpieServer magpieServer = mock(MagpieServer.class);
107-
108-
// Prepare test data
109-
String fileName = "gobpieTest7.json";
110-
String gobPieConfFileName = GobPieConfTest.class.getResource(fileName).getFile();
111-
112-
// Mock everything needed for creating goblintServer
113-
GobPieConfReader gobPieConfReader = new GobPieConfReader(magpieServer, gobPieConfFileName);
114-
GobPieConfiguration gobPieConfiguration = gobPieConfReader.readGobPieConfiguration();
114+
GobPieConfiguration gobPieConfiguration = mock(GobPieConfiguration.class);
115115
GoblintServer goblintServer = new GoblintServer(magpieServer, gobPieConfiguration);
116116

117+
// Mock behavior to return the executable command
118+
when(gobPieConfiguration.goblintExecutable()).thenReturn("/definitely/not/a/real/binary");
119+
117120
// Assert that checking the Goblint version throws GobPieException
118121
GobPieException thrown = assertThrows(GobPieException.class, goblintServer::checkGoblintVersion);
119122
assertEquals("Checking version failed.", thrown.getMessage());

0 commit comments

Comments
 (0)