mirror of
https://github.com/filoghost/HolographicDisplays.git
synced 2024-12-21 00:07:48 +01:00
Improve tests
This commit is contained in:
parent
1440a88387
commit
ce2dfd993b
@ -10,30 +10,28 @@ import me.filoghost.holographicdisplays.api.hologram.TouchHandler;
|
|||||||
import me.filoghost.holographicdisplays.plugin.hologram.api.APIHologram;
|
import me.filoghost.holographicdisplays.plugin.hologram.api.APIHologram;
|
||||||
import me.filoghost.holographicdisplays.plugin.hologram.api.APIHologramManager;
|
import me.filoghost.holographicdisplays.plugin.hologram.api.APIHologramManager;
|
||||||
import me.filoghost.holographicdisplays.plugin.hologram.api.APITextLine;
|
import me.filoghost.holographicdisplays.plugin.hologram.api.APITextLine;
|
||||||
import me.filoghost.holographicdisplays.plugin.test.TestAPIHologramsManager;
|
import me.filoghost.holographicdisplays.plugin.test.Mocks;
|
||||||
|
import me.filoghost.holographicdisplays.plugin.test.TestAPIHologramManager;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.*;
|
import static org.assertj.core.api.Assertions.*;
|
||||||
import static org.mockito.Mockito.*;
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
class V2TouchableLineAdapterTest {
|
class V2TouchableLineAdapterTest {
|
||||||
|
|
||||||
APIHologramManager apiHologramManager = new TestAPIHologramsManager();
|
APIHologramManager apiHologramManager = new TestAPIHologramManager();
|
||||||
|
|
||||||
APIHologram hologram = apiHologramManager.createHologram(
|
APIHologram hologram = apiHologramManager.createHologram(
|
||||||
new Location(mock(World.class), 0, 0, 0),
|
new Location(Mocks.WORLD, 0, 0, 0),
|
||||||
mock(Plugin.class)
|
Mocks.PLUGIN
|
||||||
);
|
);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setNullV2TouchHandler() {
|
void setNullV2TouchHandler() {
|
||||||
APITextLine newLine = new APITextLine(hologram, "");
|
APITextLine newLine = hologram.appendTextLine("");
|
||||||
TextLine v2Line = newLine.getV2Adapter();
|
TextLine v2Line = newLine.getV2Adapter();
|
||||||
ExampleNewTouchHandler newTouchHandler = new ExampleNewTouchHandler();
|
ExampleNewTouchHandler newTouchHandler = new ExampleNewTouchHandler();
|
||||||
|
|
||||||
@ -46,7 +44,7 @@ class V2TouchableLineAdapterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setNullNewTouchHandler() {
|
void setNullNewTouchHandler() {
|
||||||
APITextLine newLine = new APITextLine(hologram, "");
|
APITextLine newLine = hologram.appendTextLine("");
|
||||||
TextLine v2Line = newLine.getV2Adapter();
|
TextLine v2Line = newLine.getV2Adapter();
|
||||||
ExampleV2TouchHandler v2TouchHandler = new ExampleV2TouchHandler();
|
ExampleV2TouchHandler v2TouchHandler = new ExampleV2TouchHandler();
|
||||||
|
|
||||||
@ -69,7 +67,7 @@ class V2TouchableLineAdapterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setNewGetV2TouchHandler() {
|
void setNewGetV2TouchHandler() {
|
||||||
APITextLine newLine = new APITextLine(hologram, "");
|
APITextLine newLine = hologram.appendTextLine("");
|
||||||
TextLine v2Line = newLine.getV2Adapter();
|
TextLine v2Line = newLine.getV2Adapter();
|
||||||
ExampleNewTouchHandler newTouchHandler = new ExampleNewTouchHandler();
|
ExampleNewTouchHandler newTouchHandler = new ExampleNewTouchHandler();
|
||||||
|
|
||||||
@ -80,7 +78,7 @@ class V2TouchableLineAdapterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setV2GetNewTouchHandler() {
|
void setV2GetNewTouchHandler() {
|
||||||
APITextLine newLine = new APITextLine(hologram, "");
|
APITextLine newLine = hologram.appendTextLine("");
|
||||||
TextLine v2Line = newLine.getV2Adapter();
|
TextLine v2Line = newLine.getV2Adapter();
|
||||||
ExampleV2TouchHandler v2TouchHandler = new ExampleV2TouchHandler();
|
ExampleV2TouchHandler v2TouchHandler = new ExampleV2TouchHandler();
|
||||||
|
|
||||||
@ -91,7 +89,7 @@ class V2TouchableLineAdapterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void repeatedGetV2TouchHandlerShouldReturnSameInstance() {
|
void repeatedGetV2TouchHandlerShouldReturnSameInstance() {
|
||||||
APITextLine newLine = new APITextLine(hologram, "");
|
APITextLine newLine = hologram.appendTextLine("");
|
||||||
TextLine v2Line = newLine.getV2Adapter();
|
TextLine v2Line = newLine.getV2Adapter();
|
||||||
|
|
||||||
newLine.setTouchHandler(new ExampleNewTouchHandler());
|
newLine.setTouchHandler(new ExampleNewTouchHandler());
|
||||||
@ -103,7 +101,7 @@ class V2TouchableLineAdapterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void repeatedSetV2TouchHandlerShouldNotChangeNewTouchHandlerInstance() {
|
void repeatedSetV2TouchHandlerShouldNotChangeNewTouchHandlerInstance() {
|
||||||
APITextLine newLine = new APITextLine(hologram, "");
|
APITextLine newLine = hologram.appendTextLine("");
|
||||||
TextLine v2Line = newLine.getV2Adapter();
|
TextLine v2Line = newLine.getV2Adapter();
|
||||||
ExampleV2TouchHandler v2TouchHandler = new ExampleV2TouchHandler();
|
ExampleV2TouchHandler v2TouchHandler = new ExampleV2TouchHandler();
|
||||||
|
|
||||||
@ -117,7 +115,7 @@ class V2TouchableLineAdapterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void repeatedSetNewTouchHandlerShouldNotChangeV2TouchHandlerInstance() {
|
void repeatedSetNewTouchHandlerShouldNotChangeV2TouchHandlerInstance() {
|
||||||
APITextLine newLine = new APITextLine(hologram, "");
|
APITextLine newLine = hologram.appendTextLine("");
|
||||||
TextLine v2Line = newLine.getV2Adapter();
|
TextLine v2Line = newLine.getV2Adapter();
|
||||||
ExampleNewTouchHandler v2TouchHandler = new ExampleNewTouchHandler();
|
ExampleNewTouchHandler v2TouchHandler = new ExampleNewTouchHandler();
|
||||||
|
|
||||||
@ -131,7 +129,7 @@ class V2TouchableLineAdapterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void v2TouchHandlerChangesWhenNewTouchHandlerChanges() {
|
void v2TouchHandlerChangesWhenNewTouchHandlerChanges() {
|
||||||
APITextLine newLine = new APITextLine(hologram, "");
|
APITextLine newLine = hologram.appendTextLine("");
|
||||||
TextLine v2Line = newLine.getV2Adapter();
|
TextLine v2Line = newLine.getV2Adapter();
|
||||||
|
|
||||||
newLine.setTouchHandler(new ExampleNewTouchHandler());
|
newLine.setTouchHandler(new ExampleNewTouchHandler());
|
||||||
@ -144,7 +142,7 @@ class V2TouchableLineAdapterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void newTouchHandlerChangesWhenV2TouchHandlerChanges() {
|
void newTouchHandlerChangesWhenV2TouchHandlerChanges() {
|
||||||
APITextLine newLine = new APITextLine(hologram, "");
|
APITextLine newLine = hologram.appendTextLine("");
|
||||||
TextLine v2Line = newLine.getV2Adapter();
|
TextLine v2Line = newLine.getV2Adapter();
|
||||||
|
|
||||||
v2Line.setTouchHandler(new ExampleV2TouchHandler());
|
v2Line.setTouchHandler(new ExampleV2TouchHandler());
|
||||||
@ -157,7 +155,7 @@ class V2TouchableLineAdapterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void preserveTouchHandlerInstancesWhenUsingNewAPI() {
|
void preserveTouchHandlerInstancesWhenUsingNewAPI() {
|
||||||
APITextLine newLine = new APITextLine(hologram, "");
|
APITextLine newLine = hologram.appendTextLine("");
|
||||||
TextLine v2Line = newLine.getV2Adapter();
|
TextLine v2Line = newLine.getV2Adapter();
|
||||||
ExampleV2TouchHandler v2TouchHandler = new ExampleV2TouchHandler();
|
ExampleV2TouchHandler v2TouchHandler = new ExampleV2TouchHandler();
|
||||||
|
|
||||||
@ -174,7 +172,7 @@ class V2TouchableLineAdapterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void preserveTouchHandlerInstancesWhenUsingV2API() {
|
void preserveTouchHandlerInstancesWhenUsingV2API() {
|
||||||
APITextLine newLine = new APITextLine(hologram, "");
|
APITextLine newLine = hologram.appendTextLine("");
|
||||||
TextLine v2Line = newLine.getV2Adapter();
|
TextLine v2Line = newLine.getV2Adapter();
|
||||||
ExampleNewTouchHandler newTouchHandler = new ExampleNewTouchHandler();
|
ExampleNewTouchHandler newTouchHandler = new ExampleNewTouchHandler();
|
||||||
|
|
||||||
|
@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) filoghost and contributors
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
package me.filoghost.holographicdisplays.plugin.test;
|
||||||
|
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
|
public class Mocks {
|
||||||
|
|
||||||
|
public static final Plugin PLUGIN;
|
||||||
|
public static final World WORLD;
|
||||||
|
|
||||||
|
static {
|
||||||
|
PLUGIN = mock(Plugin.class);
|
||||||
|
when(PLUGIN.getName()).thenReturn("HolographicDisplays");
|
||||||
|
WORLD = mock(World.class);
|
||||||
|
when(WORLD.getName()).thenReturn("world");
|
||||||
|
}
|
||||||
|
}
|
@ -11,9 +11,9 @@ import me.filoghost.holographicdisplays.plugin.placeholder.tracking.PlaceholderT
|
|||||||
|
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
public class TestAPIHologramsManager extends APIHologramManager {
|
public class TestAPIHologramManager extends APIHologramManager {
|
||||||
|
|
||||||
public TestAPIHologramsManager() {
|
public TestAPIHologramManager() {
|
||||||
super(new LineTrackerManager(new TestNMSManager(), mock(PlaceholderTracker.class)));
|
super(new LineTrackerManager(new TestNMSManager(), mock(PlaceholderTracker.class)));
|
||||||
}
|
}
|
||||||
|
|
@ -6,26 +6,27 @@
|
|||||||
package me.filoghost.holographicdisplays.plugin.test;
|
package me.filoghost.holographicdisplays.plugin.test;
|
||||||
|
|
||||||
import me.filoghost.holographicdisplays.common.nms.EntityID;
|
import me.filoghost.holographicdisplays.common.nms.EntityID;
|
||||||
|
import me.filoghost.holographicdisplays.common.nms.FallbackEntityIDGenerator;
|
||||||
import me.filoghost.holographicdisplays.common.nms.NMSManager;
|
import me.filoghost.holographicdisplays.common.nms.NMSManager;
|
||||||
import me.filoghost.holographicdisplays.common.nms.NMSPacketList;
|
import me.filoghost.holographicdisplays.common.nms.NMSPacketList;
|
||||||
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
public class TestNMSManager implements NMSManager {
|
public class TestNMSManager implements NMSManager {
|
||||||
|
|
||||||
private final AtomicInteger entityIDGenerator;
|
private final Supplier<Integer> entityIDGenerator;
|
||||||
private final NMSPacketList packetList;
|
private final NMSPacketList packetList;
|
||||||
|
|
||||||
public TestNMSManager() {
|
public TestNMSManager() {
|
||||||
this.entityIDGenerator = new AtomicInteger();
|
this.entityIDGenerator = new FallbackEntityIDGenerator();
|
||||||
this.packetList = mock(NMSPacketList.class);
|
this.packetList = mock(NMSPacketList.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EntityID newEntityID() {
|
public EntityID newEntityID() {
|
||||||
return new EntityID(entityIDGenerator::incrementAndGet);
|
return new EntityID(entityIDGenerator);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user