2010-09-19 01:29:21 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
/***************************************************************************
|
2023-01-29 13:33:20 -08:00
|
|
|
* (C) Copyright 2003-2023 - Stendhal *
|
2010-09-19 01:29:21 +00:00
|
|
|
***************************************************************************
|
|
|
|
|
***************************************************************************
|
|
|
|
|
* *
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
|
* (at your option) any later version. *
|
|
|
|
|
* *
|
|
|
|
|
***************************************************************************/
|
2008-01-20 13:41:31 +00:00
|
|
|
package utilities;
|
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.assertNotNull;
|
|
|
|
|
import static org.junit.Assert.assertTrue;
|
|
|
|
|
|
2016-03-06 18:54:24 +02:00
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.LinkedList;
|
2008-01-20 13:41:31 +00:00
|
|
|
import java.util.List;
|
2016-03-06 18:54:24 +02:00
|
|
|
import java.util.Map;
|
2008-01-20 13:41:31 +00:00
|
|
|
|
|
|
|
|
import org.junit.After;
|
2016-03-06 18:54:24 +02:00
|
|
|
import org.junit.Before;
|
|
|
|
|
|
|
|
|
|
import games.stendhal.server.core.config.ZoneConfigurator;
|
|
|
|
|
import games.stendhal.server.core.engine.SingletonRepository;
|
|
|
|
|
import games.stendhal.server.entity.npc.SpeakerNPC;
|
2008-01-20 13:41:31 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* NPCTest is the base class for tests dealing with NPCs.
|
|
|
|
|
*
|
|
|
|
|
* @author Martin Fuchs
|
|
|
|
|
*/
|
2008-01-27 19:25:10 +00:00
|
|
|
public abstract class ZonePlayerAndNPCTestImpl extends ZoneAndPlayerTestImpl {
|
2008-01-20 13:41:31 +00:00
|
|
|
|
2016-03-06 18:54:24 +02:00
|
|
|
private final List<String> npcNames = new LinkedList<>();
|
|
|
|
|
|
|
|
|
|
private final Map<ZoneConfigurator, String> zoneConfiguratorsAndZones = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
protected ZonePlayerAndNPCTestImpl() {
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-20 13:41:31 +00:00
|
|
|
/**
|
|
|
|
|
* Register NPC names for cleanup in tearDown().
|
2017-05-28 01:03:01 +02:00
|
|
|
* @param zoneName
|
|
|
|
|
*
|
2008-01-20 13:41:31 +00:00
|
|
|
* @param npcNames
|
|
|
|
|
*/
|
2008-07-12 14:44:47 +00:00
|
|
|
protected ZonePlayerAndNPCTestImpl(final String zoneName, final String... npcNames) {
|
2008-01-20 13:41:31 +00:00
|
|
|
super(zoneName);
|
2016-03-06 18:54:24 +02:00
|
|
|
|
2008-01-20 13:41:31 +00:00
|
|
|
assertTrue(npcNames.length > 0);
|
|
|
|
|
|
2008-07-12 14:44:47 +00:00
|
|
|
for (final String npcName : npcNames) {
|
2008-01-20 13:41:31 +00:00
|
|
|
this.npcNames.add(npcName);
|
|
|
|
|
}
|
2022-12-01 21:00:31 -08:00
|
|
|
}
|
2008-01-20 13:41:31 +00:00
|
|
|
|
2016-03-06 18:54:24 +02:00
|
|
|
@Before
|
|
|
|
|
@Override
|
|
|
|
|
public void setUp() throws Exception {
|
|
|
|
|
for (Map.Entry<ZoneConfigurator, String> configuratorToZone : zoneConfiguratorsAndZones.entrySet()) {
|
|
|
|
|
setupZone(configuratorToZone.getValue(), configuratorToZone.getKey());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
super.setUp();
|
|
|
|
|
|
|
|
|
|
for (final String npcName : npcNames) {
|
|
|
|
|
resetNPC(npcName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-20 19:41:01 +00:00
|
|
|
@Override
|
2008-01-20 13:41:31 +00:00
|
|
|
@After
|
|
|
|
|
public void tearDown() throws Exception {
|
2008-07-12 14:44:47 +00:00
|
|
|
for (final String npcName : npcNames) {
|
2016-03-06 18:54:24 +02:00
|
|
|
removeNPC(npcName);
|
2008-01-20 13:41:31 +00:00
|
|
|
}
|
2016-03-06 18:54:24 +02:00
|
|
|
|
2008-01-20 13:41:31 +00:00
|
|
|
super.tearDown();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return the SpeakerNPC of the given name.
|
2017-05-28 01:03:01 +02:00
|
|
|
*
|
2008-01-20 13:41:31 +00:00
|
|
|
* @param npcName
|
|
|
|
|
* @return SpeakerNPC
|
|
|
|
|
*/
|
2008-07-12 14:44:47 +00:00
|
|
|
protected SpeakerNPC getNPC(final String npcName) {
|
|
|
|
|
final SpeakerNPC npc = SingletonRepository.getNPCList().get(npcName);
|
2008-01-20 13:41:31 +00:00
|
|
|
|
|
|
|
|
assertNotNull(npc);
|
|
|
|
|
|
|
|
|
|
return npc;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-06 18:54:24 +02:00
|
|
|
protected void addZoneConfigurator(ZoneConfigurator zoneConfigurator, String zoneName) {
|
|
|
|
|
zoneConfiguratorsAndZones.put(zoneConfigurator, zoneName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void setNpcNames(final String... npcNames) {
|
|
|
|
|
assertTrue(npcNames.length > 0);
|
|
|
|
|
|
|
|
|
|
for (final String npcName : npcNames) {
|
|
|
|
|
this.npcNames.add(npcName);
|
|
|
|
|
}
|
2023-01-29 13:33:20 -08:00
|
|
|
}
|
2008-01-20 13:41:31 +00:00
|
|
|
}
|