18
18
import org .terasology .engine .context .Context ;
19
19
import org .terasology .engine .core .GameEngine ;
20
20
import org .terasology .engine .core .PathManager ;
21
+ import org .terasology .engine .core .PathManagerProvider ;
21
22
import org .terasology .engine .core .TerasologyConstants ;
22
23
import org .terasology .engine .core .TerasologyEngine ;
23
24
import org .terasology .engine .core .TerasologyEngineBuilder ;
55
56
import java .io .IOException ;
56
57
import java .nio .file .Files ;
57
58
import java .nio .file .Path ;
59
+ import java .util .Collections ;
58
60
import java .util .List ;
59
61
import java .util .Set ;
60
62
import java .util .function .Supplier ;
61
63
62
64
import static org .mockito .Mockito .mock ;
65
+ import static org .mockito .Mockito .spy ;
66
+ import static org .mockito .Mockito .when ;
63
67
64
68
/**
65
69
* Base class for tests involving full {@link TerasologyEngine} instances. View the tests included in this module for
@@ -155,6 +159,9 @@ public class ModuleTestingEnvironment {
155
159
private final List <TerasologyEngine > engines = Lists .newArrayList ();
156
160
private long safetyTimeoutMs = DEFAULT_SAFETY_TIMEOUT ;
157
161
162
+ PathManager pathManager ;
163
+ PathManagerProvider .Cleaner pathManagerCleaner ;
164
+
158
165
/**
159
166
* Set up and start the engine as configured via this environment.
160
167
* <p>
@@ -164,6 +171,7 @@ public class ModuleTestingEnvironment {
164
171
*/
165
172
@ BeforeEach
166
173
public void setup () throws Exception {
174
+ mockPathManager ();
167
175
host = createHost ();
168
176
ScreenGrabber grabber = mock (ScreenGrabber .class );
169
177
hostContext .put (ScreenGrabber .class , grabber );
@@ -180,6 +188,13 @@ public void tearDown() {
180
188
engines .forEach (TerasologyEngine ::shutdown );
181
189
engines .forEach (TerasologyEngine ::cleanup );
182
190
engines .clear ();
191
+ try {
192
+ pathManagerCleaner .close ();
193
+ } catch (RuntimeException e ) {
194
+ throw e ;
195
+ } catch (Throwable e ) {
196
+ throw new RuntimeException (e );
197
+ }
183
198
host = null ;
184
199
hostContext = null ;
185
200
}
@@ -398,6 +413,8 @@ private TerasologyEngine createHeadedEngine() throws IOException {
398
413
}
399
414
400
415
private TerasologyEngine createEngine (TerasologyEngineBuilder terasologyEngineBuilder ) throws IOException {
416
+ System .setProperty (ModuleManager .LOAD_CLASSPATH_MODULES_PROPERTY , "true" );
417
+
401
418
// create temporary home paths so the MTE engines don't overwrite config/save files in your real home path
402
419
Path path = Files .createTempDirectory ("terasology-mte-engine" );
403
420
PathManager pathManager = PathManager .getInstance ();
@@ -449,6 +466,14 @@ private void registerCurrentDirectoryIfModule(TerasologyEngine terasologyEngine)
449
466
}
450
467
}
451
468
469
+ protected void mockPathManager () {
470
+ PathManager originalPathManager = PathManager .getInstance ();
471
+ pathManager = spy (originalPathManager );
472
+ when (pathManager .getModulePaths ()).thenReturn (Collections .emptyList ());
473
+ pathManagerCleaner = new PathManagerProvider .Cleaner (originalPathManager , pathManager );
474
+ PathManagerProvider .setPathManager (pathManager );
475
+ };
476
+
452
477
private TerasologyEngine createHost () throws IOException {
453
478
TerasologyEngine terasologyEngine = createHeadlessEngine ();
454
479
terasologyEngine .getFromEngineContext (SystemConfig .class ).writeSaveGamesEnabled .set (false );
0 commit comments