forked from unimatrix/web
DuneRealms V2 clean baseline
Owner-authorised history reset; current source tree preserved exactly.
This commit is contained in:
commit
6deb4a2e7d
7 changed files with 65043 additions and 0 deletions
|
|
@ -0,0 +1,37 @@
|
|||
package com.example.duneess;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import java.nio.file.*;
|
||||
import java.util.*;
|
||||
import java.util.logging.Logger;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class CommunityLedgerTest {
|
||||
@TempDir Path directory;
|
||||
DuneEss plugin(){DuneEss plugin=mock(DuneEss.class);when(plugin.getDataFolder()).thenReturn(directory.resolve("DuneEss").toFile());when(plugin.getConfig()).thenReturn(new YamlConfiguration());when(plugin.getLogger()).thenReturn(Logger.getAnonymousLogger());return plugin;}
|
||||
@Test void creditsOnceAcrossRestartAndRetainsReceiptUntilAcknowledged() throws Exception {
|
||||
DuneEss plugin=plugin();UUID uuid=UUID.randomUUID();OfflinePlayer player=mock(OfflinePlayer.class);when(player.getUniqueId()).thenReturn(uuid);String receipt="a".repeat(64);
|
||||
DuneEconomy first=new DuneEconomy(plugin);assertTrue(first.grantCommunity(uuid,"2026-10",50,receipt));assertEquals(50,first.getBalance(player));
|
||||
first.add(uuid,10);assertEquals(60,first.getBalance(player));
|
||||
DuneEconomy restarted=new DuneEconomy(plugin);assertFalse(restarted.grantCommunity(uuid,"2026-10",50,receipt));assertEquals(60,restarted.getBalance(player));assertEquals(List.of(receipt),restarted.pendingCommunityReceipts().get(uuid));
|
||||
assertThrows(Exception.class,()->restarted.grantCommunity(uuid,"2026-10",50,"b".repeat(64)));
|
||||
restarted.acknowledgeCommunity(uuid,receipt);assertTrue(new DuneEconomy(plugin).pendingCommunityReceipts().isEmpty());
|
||||
assertTrue(restarted.grantCommunity(uuid,"2026-11",50,"c".repeat(64)));assertEquals(110,restarted.getBalance(player));
|
||||
}
|
||||
@Test void failedDurableWriteDoesNotCreditOrConsumeTheReward() throws Exception {
|
||||
DuneEss plugin=plugin();DuneEconomy ledger=new DuneEconomy(plugin);UUID uuid=UUID.randomUUID();OfflinePlayer player=mock(OfflinePlayer.class);when(player.getUniqueId()).thenReturn(uuid);
|
||||
Path blocker=directory.resolve("DuneEss/balances.yml.community-tmp");Files.createDirectory(blocker);
|
||||
assertThrows(Exception.class,()->ledger.grantCommunity(uuid,"2026-10",50,"a".repeat(64)));assertEquals(0,ledger.getBalance(player));assertTrue(ledger.pendingCommunityReceipts().isEmpty());
|
||||
Files.delete(blocker);assertTrue(ledger.grantCommunity(uuid,"2026-10",50,"a".repeat(64)));assertEquals(50,ledger.getBalance(player));
|
||||
}
|
||||
@Test void incompleteSharedConfigurationCannotCreateASecondLocalWallet() throws Exception {
|
||||
Files.createDirectories(directory.resolve("DuneCore"));YamlConfiguration core=new YamlConfiguration();core.set("database.enabled",true);core.set("database.jdbc-url","");core.save(directory.resolve("DuneCore/config.yml").toFile());
|
||||
DuneEconomy ledger=new DuneEconomy(plugin());UUID uuid=UUID.randomUUID();OfflinePlayer player=mock(OfflinePlayer.class);when(player.getUniqueId()).thenReturn(uuid);
|
||||
assertFalse(ledger.depositPlayer(player,50).transactionSuccess());assertEquals(0,ledger.getBalance(player));
|
||||
assertThrows(Exception.class,()->ledger.grantCommunity(uuid,"2026-10",50,"a".repeat(64)));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
package com.example.duneess;
|
||||
import com.example.dunegui.DunemarkItems;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
class DunemarkDenominationsTest {
|
||||
@Test void walletArtSelectsOnlySupportedDenominationsWithoutRoundingUp(){
|
||||
assertEquals(1,DunemarkItems.denomination(0)); assertEquals(1,DunemarkItems.denomination(4.99));
|
||||
assertEquals(5,DunemarkItems.denomination(5)); assertEquals(5,DunemarkItems.denomination(99.99));
|
||||
assertEquals(100,DunemarkItems.denomination(100));assertEquals(1000,DunemarkItems.denomination(4999.99));
|
||||
assertEquals(5000,DunemarkItems.denomination(5000));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
package com.example.duneess;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
class EssentialsBasicsTest {
|
||||
@Test void normalizesNamesAndHasAStableDefault() {
|
||||
assertEquals("home",EssentialsBasics.homeName(new String[]{}));
|
||||
assertEquals("sietch_2",EssentialsBasics.homeName(new String[]{"Sietch_2"}));
|
||||
}
|
||||
@Test void rejectsYamlPathsAndInvalidArguments() {
|
||||
for(String name:new String[]{"../other","player.home","","a b","x".repeat(25)})
|
||||
assertThrows(IllegalArgumentException.class,()->EssentialsBasics.homeName(new String[]{name}));
|
||||
assertThrows(IllegalArgumentException.class,()->EssentialsBasics.homeName(new String[]{"one","two"}));
|
||||
}
|
||||
|
||||
@org.junit.jupiter.api.io.TempDir java.nio.file.Path directory;
|
||||
@Test void teleportRequestsRequireConsentAndCannotBeAcceptedTwice() {
|
||||
DuneEss plugin=org.mockito.Mockito.mock(DuneEss.class);
|
||||
org.mockito.Mockito.when(plugin.getDataFolder()).thenReturn(directory.toFile());
|
||||
EssentialsBasics basics=new EssentialsBasics(plugin);
|
||||
var source=org.mockito.Mockito.mock(org.bukkit.entity.Player.class);
|
||||
var target=org.mockito.Mockito.mock(org.bukkit.entity.Player.class);
|
||||
var world=org.mockito.Mockito.mock(org.bukkit.World.class);
|
||||
var border=org.mockito.Mockito.mock(org.bukkit.WorldBorder.class);
|
||||
var request=org.mockito.Mockito.mock(org.bukkit.command.Command.class);
|
||||
var accept=org.mockito.Mockito.mock(org.bukkit.command.Command.class);
|
||||
java.util.UUID senderId=java.util.UUID.randomUUID(), targetId=java.util.UUID.randomUUID();
|
||||
org.mockito.Mockito.when(source.getUniqueId()).thenReturn(senderId);
|
||||
org.mockito.Mockito.when(target.getUniqueId()).thenReturn(targetId);
|
||||
org.mockito.Mockito.when(source.getName()).thenReturn("Sender");
|
||||
org.mockito.Mockito.when(source.hasPermission("duneess.basics")).thenReturn(true);
|
||||
org.mockito.Mockito.when(target.hasPermission("duneess.basics")).thenReturn(true);
|
||||
org.mockito.Mockito.when(source.canSee(target)).thenReturn(true);
|
||||
org.mockito.Mockito.when(source.getWorld()).thenReturn(world);
|
||||
org.mockito.Mockito.when(target.getWorld()).thenReturn(world);
|
||||
org.mockito.Mockito.when(source.isOnline()).thenReturn(true);
|
||||
org.mockito.Mockito.when(world.getWorldBorder()).thenReturn(border);
|
||||
org.mockito.Mockito.when(border.isInside(org.mockito.ArgumentMatchers.any())).thenReturn(true);
|
||||
org.mockito.Mockito.when(world.getMinHeight()).thenReturn(-64);
|
||||
org.mockito.Mockito.when(world.getMaxHeight()).thenReturn(320);
|
||||
var destination=new org.bukkit.Location(world,10,80,10);
|
||||
org.mockito.Mockito.when(target.getLocation()).thenReturn(destination);
|
||||
org.mockito.Mockito.when(source.teleportAsync(destination)).thenReturn(java.util.concurrent.CompletableFuture.completedFuture(true));
|
||||
org.mockito.Mockito.when(request.getName()).thenReturn("tpa");
|
||||
org.mockito.Mockito.when(accept.getName()).thenReturn("tpaccept");
|
||||
try(var bukkit=org.mockito.Mockito.mockStatic(org.bukkit.Bukkit.class)) {
|
||||
bukkit.when(()->org.bukkit.Bukkit.getPlayerExact("Target")).thenReturn(target);
|
||||
bukkit.when(()->org.bukkit.Bukkit.getPlayer(senderId)).thenReturn(source);
|
||||
basics.onCommand(source,request,"tpa",new String[]{"Target"});
|
||||
org.mockito.Mockito.verify(source,org.mockito.Mockito.never()).teleportAsync(org.mockito.ArgumentMatchers.any(org.bukkit.Location.class));
|
||||
basics.onCommand(target,accept,"tpaccept",new String[]{});
|
||||
basics.onCommand(target,accept,"tpaccept",new String[]{});
|
||||
org.mockito.Mockito.verify(source,org.mockito.Mockito.times(1)).teleportAsync(destination);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
package com.example.duneess;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.*;
|
||||
import org.bukkit.inventory.*;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.MockedStatic;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
class ExchangeMenuTest {
|
||||
@Test void ordinaryInventoriesAreNeverHijackedByTitle() {
|
||||
ExchangeMenu menu=new ExchangeMenu(mock(DuneEss.class));
|
||||
InventoryClickEvent click=mock(InventoryClickEvent.class);
|
||||
InventoryView view=mock(InventoryView.class);Inventory inventory=mock(Inventory.class);
|
||||
when(click.getView()).thenReturn(view);when(view.getTopInventory()).thenReturn(inventory);
|
||||
menu.click(click);verify(click,never()).setCancelled(anyBoolean());
|
||||
}
|
||||
@Test void bottomInventoryTransfersAndDragsAreCancelledWithoutRunningAnAction() {
|
||||
ExchangeMenu menu=new ExchangeMenu(mock(DuneEss.class));UUID owner=UUID.randomUUID();
|
||||
ExchangeMenu.Screen screen=new ExchangeMenu.Screen(owner);
|
||||
Inventory top=mock(Inventory.class),bottom=mock(Inventory.class);InventoryView view=mock(InventoryView.class);
|
||||
screen.inventory=top;when(top.getHolder()).thenReturn(screen);when(view.getTopInventory()).thenReturn(top);
|
||||
Player player=mock(Player.class);when(player.getUniqueId()).thenReturn(owner);
|
||||
InventoryClickEvent click=mock(InventoryClickEvent.class);when(click.getView()).thenReturn(view);
|
||||
when(click.getWhoClicked()).thenReturn(player);when(click.getClickedInventory()).thenReturn(bottom);
|
||||
AtomicInteger actions=new AtomicInteger();screen.actions.put(10,actions::incrementAndGet);
|
||||
menu.click(click);verify(click).setCancelled(true);assertEquals(0,actions.get());
|
||||
InventoryDragEvent drag=mock(InventoryDragEvent.class);when(drag.getView()).thenReturn(view);
|
||||
menu.drag(drag);verify(drag).setCancelled(true);
|
||||
}
|
||||
@Test void queuedSecondConfirmationCannotExecuteAfterFirstClosesScreen() {
|
||||
DuneEss plugin=mock(DuneEss.class);ExchangeMenu menu=new ExchangeMenu(plugin);
|
||||
UUID owner=UUID.randomUUID();ExchangeMenu.Screen screen=new ExchangeMenu.Screen(owner);
|
||||
Inventory top=mock(Inventory.class),closed=mock(Inventory.class);screen.inventory=top;
|
||||
InventoryView view=mock(InventoryView.class);when(view.getTopInventory()).thenReturn(top);
|
||||
when(top.getHolder()).thenReturn(screen);
|
||||
Player player=mock(Player.class);when(player.getUniqueId()).thenReturn(owner);when(player.isOnline()).thenReturn(true);
|
||||
when(player.getOpenInventory()).thenReturn(view);
|
||||
InventoryClickEvent click=mock(InventoryClickEvent.class);when(click.getView()).thenReturn(view);
|
||||
when(click.getWhoClicked()).thenReturn(player);when(click.getClickedInventory()).thenReturn(top);
|
||||
when(click.getClick()).thenReturn(ClickType.LEFT);when(click.getRawSlot()).thenReturn(30);
|
||||
AtomicInteger actions=new AtomicInteger();screen.actions.put(30,()->{actions.incrementAndGet();when(view.getTopInventory()).thenReturn(closed);});
|
||||
BukkitScheduler scheduler=mock(BukkitScheduler.class);List<Runnable> queued=new ArrayList<>();
|
||||
try(MockedStatic<Bukkit> bukkit=mockStatic(Bukkit.class)) {
|
||||
bukkit.when(Bukkit::getScheduler).thenReturn(scheduler);
|
||||
when(scheduler.runTask(eq(plugin),any(Runnable.class))).thenAnswer(invocation->{queued.add(invocation.getArgument(1));return null;});
|
||||
menu.click(click);menu.click(click);queued.forEach(Runnable::run);
|
||||
}
|
||||
assertEquals(1,actions.get());
|
||||
}
|
||||
@Test void administratorCommandRechecksPermission() {
|
||||
ExchangeMenu menu=new ExchangeMenu(mock(DuneEss.class));Player player=mock(Player.class);
|
||||
assertTrue(menu.onCommand(player,null,"exchange",new String[]{"admin"}));
|
||||
verify(player).sendMessage(contains("Operators only"));
|
||||
}
|
||||
}
|
||||
125
DuneEss/src/test/java/com/example/duneess/ExchangeStoreTest.java
Normal file
125
DuneEss/src/test/java/com/example/duneess/ExchangeStoreTest.java
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
package com.example.duneess;
|
||||
|
||||
import org.junit.jupiter.api.*;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class ExchangeStoreTest {
|
||||
private String url;
|
||||
private ExchangeStore store;
|
||||
private final UUID seller=UUID.randomUUID(),buyer=UUID.randomUUID();
|
||||
@BeforeEach void setup() throws Exception {
|
||||
url="jdbc:h2:mem:"+UUID.randomUUID()+";MODE=PostgreSQL;DB_CLOSE_DELAY=-1";
|
||||
store=new ExchangeStore(()->DriverManager.getConnection(url));
|
||||
try(Connection c=DriverManager.getConnection(url);Statement s=c.createStatement()) {
|
||||
s.execute("CREATE TABLE dune_economy_balances(uuid UUID PRIMARY KEY,balance NUMERIC(20,2) NOT NULL)");
|
||||
}
|
||||
wallet(seller,"0"); wallet(buyer,"100"); store.initialize(); store.initialize();
|
||||
}
|
||||
private void wallet(UUID id,String amount) throws SQLException {
|
||||
try(Connection c=DriverManager.getConnection(url);PreparedStatement q=c.prepareStatement("INSERT INTO dune_economy_balances VALUES(?,?)")) {
|
||||
q.setObject(1,id);q.setBigDecimal(2,new BigDecimal(amount));q.executeUpdate();
|
||||
}
|
||||
}
|
||||
private BigDecimal balance(UUID id) throws SQLException {
|
||||
try(Connection c=DriverManager.getConnection(url);PreparedStatement q=c.prepareStatement("SELECT balance FROM dune_economy_balances WHERE uuid=?")) {
|
||||
q.setObject(1,id);try(ResultSet r=q.executeQuery()){assertTrue(r.next());return r.getBigDecimal(1);}
|
||||
}
|
||||
}
|
||||
private long listing(int amount,String price) throws SQLException {
|
||||
store.list(seller,"Seller","arrakis","spice","ORANGE_DYE",amount,new BigDecimal(price),"preserved-payload","Melange");
|
||||
return store.browse("all","all",null,0).getFirst().id();
|
||||
}
|
||||
@Test void finalItemIsDeletedAndBothWalletsChangeExactlyOnce() throws Exception {
|
||||
long id=listing(1,"12.50");
|
||||
assertEquals("preserved-payload",store.buy(buyer,id).payload());
|
||||
assertEquals(new BigDecimal("87.50"),balance(buyer));
|
||||
assertEquals(new BigDecimal("12.50"),balance(seller));
|
||||
assertTrue(store.browse("all","all",null,0).isEmpty());
|
||||
assertThrows(IllegalArgumentException.class,()->store.buy(buyer,id));
|
||||
assertEquals(new BigDecimal("87.50"),balance(buyer));
|
||||
}
|
||||
@Test void partiallyFilledStockRemainsAndCancellationReturnsOnlyUnsoldQuantity() throws Exception {
|
||||
long id=listing(3,"10");store.buy(buyer,id);
|
||||
assertEquals(2,store.find(id).quantity());
|
||||
assertEquals(2,store.cancel(seller,id).quantity());
|
||||
assertTrue(store.browse("all","all",null,0).isEmpty());
|
||||
assertEquals(new BigDecimal("10.00"),balance(seller));
|
||||
}
|
||||
@Test void insufficientFundsAndSelfPurchaseCannotChangeStock() throws Exception {
|
||||
long id=listing(2,"101");
|
||||
assertThrows(IllegalArgumentException.class,()->store.buy(buyer,id));
|
||||
assertThrows(IllegalArgumentException.class,()->store.buy(seller,id));
|
||||
assertEquals(2,store.find(id).quantity());assertEquals(new BigDecimal("100.00"),balance(buyer));
|
||||
}
|
||||
@Test void wrongOwnerCannotCancelOrReclaim() throws Exception {
|
||||
long id=listing(2,"1");
|
||||
assertThrows(IllegalArgumentException.class,()->store.cancel(buyer,id));
|
||||
assertEquals(2,store.find(id).quantity());
|
||||
}
|
||||
@Test void failedSellerCreditRollsBackBuyerDebit() throws Exception {
|
||||
long id=listing(1,"10");
|
||||
try(Connection c=DriverManager.getConnection(url);PreparedStatement q=c.prepareStatement("DELETE FROM dune_economy_balances WHERE uuid=?")) {
|
||||
q.setObject(1,seller);q.executeUpdate();
|
||||
}
|
||||
assertThrows(IllegalArgumentException.class,()->store.buy(buyer,id));
|
||||
assertEquals(new BigDecimal("100.00"),balance(buyer));assertEquals(1,store.find(id).quantity());
|
||||
}
|
||||
@Test void filtersAndPaginationIncludeAllCategoriesWithoutEmptyCategoryPredicate() throws Exception {
|
||||
listing(1,"1");
|
||||
store.list(seller,"Seller","caladan","building","OAK_LOG",64,new BigDecimal("2"),null,null);
|
||||
assertEquals(2,store.browse("all","all",null,0).size());
|
||||
assertEquals(1,store.browse("spice","arrakis",null,0).size());
|
||||
assertTrue(store.browse("spice","caladan",null,0).isEmpty());
|
||||
assertTrue(store.browse("all","all",buyer,0).isEmpty());
|
||||
for(int i=0;i<30;i++) listing(1,"1");
|
||||
assertEquals(29,store.browse("all","all",seller,0).size());
|
||||
assertEquals(4,store.browse("all","all",seller,1).size());
|
||||
}
|
||||
@Test void concurrentBuyersCannotBothBuyTheLastItem() throws Exception {
|
||||
UUID other=UUID.randomUUID(); wallet(other,"100");long id=listing(1,"25");
|
||||
try(ExecutorService pool=Executors.newFixedThreadPool(2)) {
|
||||
CountDownLatch start=new CountDownLatch(1);
|
||||
List<Future<Boolean>> results=new ArrayList<>();
|
||||
for(UUID player:List.of(buyer,other)) results.add(pool.submit(()->{
|
||||
start.await();try{store.buy(player,id);return true;}catch(IllegalArgumentException ex){return false;}
|
||||
}));
|
||||
start.countDown();int successes=0;for(Future<Boolean> result:results)if(result.get(5,TimeUnit.SECONDS)) successes++;
|
||||
assertEquals(1,successes);assertEquals(new BigDecimal("25.00"),balance(seller));
|
||||
assertEquals(new BigDecimal("175.00"),balance(buyer).add(balance(other)));
|
||||
}
|
||||
}
|
||||
@Test void invalidAmountsAndPricesAreRejectedBeforeWriting() {
|
||||
for(String price:List.of("0","-1","1000001","0.001"))
|
||||
assertThrows(IllegalArgumentException.class,()->listing(1,price));
|
||||
assertThrows(IllegalArgumentException.class,()->listing(0,"1"));
|
||||
assertThrows(IllegalArgumentException.class,()->listing(65,"1"));
|
||||
}
|
||||
@Test void committedSaleRecordsBuyerItemAndExactPaymentButFailuresDoNot() throws Exception {
|
||||
long id=listing(2,"12.50");store.buy(buyer,"BuyerName",id);
|
||||
try(Connection c=DriverManager.getConnection(url);Statement q=c.createStatement();ResultSet r=q.executeQuery("SELECT * FROM dune_exchange_sales")) {
|
||||
assertTrue(r.next());assertEquals(seller,r.getObject("seller",UUID.class));
|
||||
assertEquals(buyer,r.getObject("buyer",UUID.class));assertEquals("BuyerName",r.getString("buyer_name"));
|
||||
assertEquals(1,r.getInt("quantity"));assertEquals(new BigDecimal("12.50"),r.getBigDecimal("total_price"));assertFalse(r.next());
|
||||
}
|
||||
assertThrows(IllegalArgumentException.class,()->store.buy(seller,id));store.cancel(seller,id);
|
||||
try(Connection c=DriverManager.getConnection(url);Statement q=c.createStatement();ResultSet r=q.executeQuery("SELECT COUNT(*) FROM dune_exchange_sales")) {
|
||||
assertTrue(r.next());assertEquals(1,r.getInt(1));
|
||||
}
|
||||
}
|
||||
@Test void externallyOwnedTransactionRollsBackStockWalletsAndHistoryTogether() throws Exception {
|
||||
long id=listing(1,"25");
|
||||
try(Connection c=DriverManager.getConnection(url)) {
|
||||
c.setAutoCommit(false);ExchangeStore.bound(c).buy(buyer,"Buyer",id);
|
||||
assertFalse(c.isClosed());c.rollback();
|
||||
}
|
||||
assertEquals(1,store.find(id).quantity());assertEquals(new BigDecimal("100.00"),balance(buyer));
|
||||
assertEquals(new BigDecimal("0.00"),balance(seller));
|
||||
try(Connection c=DriverManager.getConnection(url);Statement q=c.createStatement();ResultSet r=q.executeQuery("SELECT COUNT(*) FROM dune_exchange_sales")) {
|
||||
assertTrue(r.next());assertEquals(0,r.getInt(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package com.example.duneess;
|
||||
import com.example.dunegui.PlanetSigils;
|
||||
import com.example.dunegui.PublicNames;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
class PlanetNamesTest {
|
||||
@Test void newDisplayNamesRetainSavedIdentifiersAndFullCapitalization(){
|
||||
assertEquals("Arrakduin",PlanetSigils.label("arrakis"));assertEquals("Kaladam",PlanetSigils.label("caladan"));
|
||||
assertEquals("Giedermark",PlanetSigils.label("giedi_prime"));assertEquals("Kaiterhof",PlanetSigils.label("kaitain"));
|
||||
assertEquals("Sigmadraken IV",PlanetSigils.label("sigma_draconis_iv"));
|
||||
assertEquals("arrakis_world_id",PublicNames.text("arrakis_world_id"));
|
||||
assertEquals("/duneess travel arrakis",PublicNames.text("/duneess travel arrakis"));
|
||||
assertEquals("Arrakduin and Kaladam",PublicNames.text("Serevan and Pelareth"));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
package com.example.dunegui;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import java.util.UUID;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
class MenuSessionTest {
|
||||
@Test void rejectsAnotherPlayerWithoutConsumingTheOwnerAction() {
|
||||
UUID owner=UUID.randomUUID(); MenuSession session=new MenuSession(owner);
|
||||
assertFalse(session.claim(UUID.randomUUID())); assertTrue(session.claim(owner)); assertFalse(session.claim(owner));
|
||||
}
|
||||
@Test void openingANewMenuInvalidatesThePreviousConfirmation() {
|
||||
UUID owner=UUID.randomUUID(); MenuSession old=new MenuSession(owner), next=new MenuSession(owner);
|
||||
assertFalse(old.claim(owner)); assertTrue(next.claim(owner));
|
||||
}
|
||||
@Test void expiringOldMenuDoesNotInvalidateTheNewMenu() {
|
||||
UUID owner=UUID.randomUUID(); MenuSession old=new MenuSession(owner), next=new MenuSession(owner);
|
||||
old.expire(); assertTrue(next.claim(owner));
|
||||
}
|
||||
@Test void expiredMenuCannotTrade() {
|
||||
UUID owner=UUID.randomUUID(); MenuSession session=new MenuSession(owner); session.expire(); assertFalse(session.claim(owner));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue

Staff