📄 fleetstest.java
字号:
/*
* FleetsTest.java
* JUnit based test
*
* Created on 8 pa焏ziernik 2005, 23:47
*/
package net.sf.jawp.server.test;
import java.util.Collection;
import junit.framework.TestCase;
import net.sf.jawp.api.domain.Planet;
import net.sf.jawp.api.domain.SpaceCoords;
import net.sf.jawp.api.service.JAWPGameService;
import net.sf.jawp.game.system.JAWPGameController;
/**
*
* @author jarek
*/
public class FleetsTest extends TestCase
{
public FleetsTest(final String testName)
{
super(testName);
}
protected void setUp() throws Exception
{
}
protected void tearDown() throws Exception
{
}
private static Planet findOwnPlanet( final Collection<Planet> planets, final long realmKey)
{
for ( final Planet p : planets )
{
if ( p.getOwner().getKey() == realmKey)
{
return p;
}
}
return null;
}
private static Planet findOtherPlanet( final Collection<Planet> planets, final long realmKey)
{
for ( final Planet p : planets )
{
if ( p.getOwner().getKey() != realmKey)
{
return p;
}
}
return null;
}
public void testMove()
{
final JAWPGameController gctrl = TestHelper.createSimpleGame();
try
{
final JAWPGameService serv = TestHelper.loginToTestGame(gctrl);
final Collection<Planet> allPlanets = serv.getPlanets();
final Planet from = findOwnPlanet( allPlanets, serv.getRealm().getKey());
final Planet to = findOtherPlanet( allPlanets, serv.getRealm().getKey());
serv.moveFleet( from.getKey(), to.getKey(), from.getHomeFleetSize() );
}
finally
{
gctrl.dispose();
}
}
/**
* movement should not be possible from not own planets
*/
public void testMoveFail()
{
final JAWPGameController gctrl = TestHelper.createSimpleGame();
try
{
final JAWPGameService serv = TestHelper.loginToTestGame(gctrl);
final Collection<Planet> allPlanets = serv.getPlanets();
final Planet from = findOwnPlanet( allPlanets, serv.getRealm().getKey());
final Planet to = findOtherPlanet( allPlanets, serv.getRealm().getKey());
try
{
serv.moveFleet( to.getKey(), from.getKey(), from.getHomeFleetSize() );
throw new IllegalStateException();
}
catch (final IllegalArgumentException iae)
{
//if there is exception it means this test passed
}
}
finally
{
gctrl.dispose();
}
}
/**
* after move there must be more than one fleet
*/
public void testMoveCheckNumberOfFleets()
{
final JAWPGameController gctrl = TestHelper.createSimpleGame();
try
{
final JAWPGameService serv = TestHelper.loginToTestGame(gctrl);
final Collection<Planet> allPlanets = serv.getPlanets();
final Planet from = findOwnPlanet( allPlanets, serv.getRealm().getKey());
final Planet to = findOtherPlanet( allPlanets, serv.getRealm().getKey());
serv.moveFleet( from.getKey(), to.getKey(), from.getHomeFleetSize() - 1 );
gctrl.doStep(1000);
assertTrue( serv.getOwnFleets().size() > 1);
}
finally
{
gctrl.dispose();
}
}
/**
* after move from planet coords must not change
*/
public void testMoveCheckPlanetCoords()
{
final JAWPGameController gctrl = TestHelper.createSimpleGame();
try
{
final JAWPGameService serv = TestHelper.loginToTestGame(gctrl);
final Collection<Planet> allPlanets = serv.getPlanets();
final Planet from = findOwnPlanet( allPlanets, serv.getRealm().getKey());
final SpaceCoords originalFromCoords = new SpaceCoords(from.getCoords());
final Planet to = findOtherPlanet( allPlanets, serv.getRealm().getKey());
serv.moveFleet( from.getKey(), to.getKey(), from.getHomeFleetSize() - 1 );
for (int i = 0; i < 10; ++i)
{
gctrl.doStep(1000);
}
assertTrue( originalFromCoords.equals( from.getCoords()));
}
finally
{
gctrl.dispose();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -