Skip to content
Permalink
Browse files

Fix mocked platform conflicts

  • Loading branch information...
kenzierocks committed Jul 16, 2019
1 parent ad5f321 commit 6941473f0bc38dd2f586ac051e801fa8d9c0ac73
@@ -27,29 +27,38 @@
import com.sk89q.worldedit.internal.expression.runtime.EvaluationException;
import com.sk89q.worldedit.internal.expression.runtime.ExpressionEnvironment;
import com.sk89q.worldedit.internal.expression.runtime.ExpressionTimeoutException;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

import static java.lang.Math.atan2;
import static java.lang.Math.sin;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class ExpressionTest {

private Platform mockPlat = mock(Platform.class);

@BeforeEach
public void setup() {
Platform mockPlat = Mockito.mock(Platform.class);
Mockito.when(mockPlat.getConfiguration()).thenReturn(new LocalConfiguration() {
when(mockPlat.getConfiguration()).thenReturn(new LocalConfiguration() {
@Override
public void load() {
}
});
WorldEdit.getInstance().getPlatformManager().register(mockPlat);
}

@AfterEach
public void tearDown() {
WorldEdit.getInstance().getPlatformManager().unregister(mockPlat);
}

@Test
public void testEvaluate() throws ExpressionException {
// check
@@ -21,7 +21,6 @@

import com.google.common.collect.ImmutableMap;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.event.platform.PlatformReadyEvent;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.extension.platform.PlatformManager;
@@ -32,6 +31,7 @@
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.registry.BundledRegistries;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
@@ -66,23 +66,28 @@
@DisplayName("An ordered block map")
class BlockMapTest {

private static Platform mockedPlatform = mock(Platform.class);

@BeforeAll
static void setupFakePlatform() {
Platform mocked = mock(Platform.class);
when(mocked.getRegistries()).thenReturn(new BundledRegistries() {
when(mockedPlatform.getRegistries()).thenReturn(new BundledRegistries() {
});
when(mocked.getCapabilities()).thenReturn(ImmutableMap.of(
when(mockedPlatform.getCapabilities()).thenReturn(ImmutableMap.of(
Capability.WORLD_EDITING, Preference.PREFERRED,
Capability.GAME_HOOKS, Preference.PREFERRED
));
PlatformManager platformManager = WorldEdit.getInstance().getPlatformManager();
platformManager.register(mocked);
platformManager.handlePlatformReady(new PlatformReadyEvent());
platformManager.register(mockedPlatform);

registerBlock("minecraft:air");
registerBlock("minecraft:oak_wood");
}

@AfterAll
static void tearDownFakePlatform() {
WorldEdit.getInstance().getPlatformManager().unregister(mockedPlatform);
}

private static void registerBlock(String id) {
BlockType.REGISTRY.register(id, new BlockType(id));
}
@@ -1,4 +1,5 @@
junit.jupiter.execution.parallel.enabled=true
junit.jupiter.execution.parallel.mode.default=concurrent
junit.jupiter.execution.parallel.mode.classes.default=same_thread
junit.jupiter.execution.parallel.config.strategy=dynamic
junit.jupiter.execution.parallel.config.dynamic.factor=4

0 comments on commit 6941473

Please sign in to comment.
You can’t perform that action at this time.