PlayerCreator { Hero createPlayer(ShipConfig shipConfig, boolean shouldSpawnOnGalaxySpawnPosition, RespawnState respawnState, SolGame game, boolean isMouseControl, boolean isNewShip) { Vector2 position = findPlayerSpawnPosition(shipConfig, shouldSpawnOnGalaxySpawnPosition, game); game.getCam().setPos(position); if (isMouseControl) { game.getBeaconHandler().init(game, position); } Hero hero = configureAndCreateHero(shipConfig, respawnState, game, isMouseControl, isNewShip, position); game.getObjectManager().addObjDelayed(hero.getShip()); game.getObjectManager().resetDelays(); return hero; }    }
@Test public void testSpawnOnGalaxySpawnPositionSetsShipPosition() { playerCreator.createPlayer(shipConfig, true, respawnState, solGame, false, false); verifyBuildNewFar(shipConfiguration().withPosition(galaxySpawnPosition)); }
@Test public void testSpawnOnGalaxySpawnPositionSetsCameraPosition() { playerCreator.createPlayer(shipConfig, true, respawnState, solGame, false, false); verify(solGame.getCam()).setPos(eq(galaxySpawnPosition)); }
@Test public void testSpawnOnShipConfigSpawnPositionSetsShipPosition() { playerCreator.createPlayer(shipConfig, false, respawnState, solGame, false, false); verifyBuildNewFar(shipConfiguration().withPosition(shipConfigSpawnPosition)); }
@Test public void testSpawnOnShipConfigSpawnPositionSetsCameraPosition() { playerCreator.createPlayer(shipConfig, false, respawnState, solGame, false, false); verify(solGame.getCam()).setPos(eq(shipConfigSpawnPosition)); }
@Test public void testBeaconHandlerNotInitializedIfNotMouseControl() { playerCreator.createPlayer(shipConfig, false, respawnState, solGame, false, false); verify(solGame.getBeaconHandler(), never()).init(any(), any()); }
@Test public void testSpawnOnGalaxySpawnPositionInitsBeaconHandlerOnMouseControl() { playerCreator.createPlayer(shipConfig, true, respawnState, solGame, true, false); verify(solGame.getBeaconHandler()).init(any(), eq(galaxySpawnPosition)); }
@Test public void testSpawnOnShipConfigSpawnPositionInitsBeaconHandlerOnMouseControl() { playerCreator.createPlayer(shipConfig, false, respawnState, solGame, true, false); verify(solGame.getBeaconHandler()).init(any(), eq(shipConfigSpawnPosition)); }
@Test public void testMouseControlCreatesAiPilot() { playerCreator.createPlayer(shipConfig, false, respawnState, solGame, true, false); verifyBuildNewFar(shipConfiguration().withPilot(AiPilot.class)); }
@Test public void testNoMouseControlCreatesUiControlledPilot() { playerCreator.createPlayer(shipConfig, false, respawnState, solGame, false, false); verifyBuildNewFar(shipConfiguration().withPilot(UiControlledPilot.class)); }
@Test public void testUseRespawnMoneyIfNotZero() { float respawnMoney = 42f; respawnState.setRespawnMoney(respawnMoney); playerCreator.createPlayer(shipConfig, false, respawnState, solGame, false, false); verifyBuildNewFar(shipConfiguration().withMoney(respawnMoney)); }
@Test public void testUseShipConfigMoneyIfNoRespawnMoneyAndNoTutorial() { int shipConfigMoney = 42; when(shipConfig.getMoney()).thenReturn(shipConfigMoney); respawnState.setRespawnMoney(0); playerCreator.createPlayer(shipConfig, false, respawnState, solGame, false, false); verifyBuildNewFar(shipConfiguration().withMoney(shipConfigMoney)); }
@Test public void testUseTutorialMoneyIfNoRespawnMoneyAndTutorialActive() { when(solGame.isTutorial()).thenReturn(true); respawnState.setRespawnMoney(0); playerCreator.createPlayer(shipConfig, false, respawnState, solGame, false, false); verifyBuildNewFar(shipConfiguration().withMoney(TUTORIAL_MONEY)); }
@Test public void testUseRespawnHullIfNotNull() { HullConfig hullConfig = mock(HullConfig.class); respawnState.setRespawnHull(hullConfig); playerCreator.createPlayer(shipConfig, false, respawnState, solGame, false, false); verifyBuildNewFar(shipConfiguration().withHullConfig(hullConfig)); }
@Test public void testUseShipConfigHullIfRespawnHullIsNull() { HullConfig hullConfig = mock(HullConfig.class); respawnState.setRespawnHull(null); when(shipConfig.getHull()).thenReturn(hullConfig); playerCreator.createPlayer(shipConfig, false, respawnState, solGame, false, false); verifyBuildNewFar(shipConfiguration().withHullConfig(hullConfig)); }
@Test public void testUseEmptyItemsIfRespawnItemsNotEmpty() { respawnState.getRespawnItems().add(mock(SolItem.class)); playerCreator.createPlayer(shipConfig, false, respawnState, solGame, false, false); verifyBuildNewFar(shipConfiguration().withItems("")); }
@Test public void testUseShipConfigItemsIfRespawnItemsIsEmpty() { respawnState.getRespawnItems().clear(); String items = "core:plasmaGun+core:blaster 0.36|core:smallShield"; when(shipConfig.getItems()).thenReturn(items); playerCreator.createPlayer(shipConfig, false, respawnState, solGame, false, false); verifyBuildNewFar(shipConfiguration().withItems(items)); }
@Test public void testGiveAmmoIfNewShipAndRespawnItemsIsEmpty() { respawnState.getRespawnItems().clear(); playerCreator.createPlayer(shipConfig, false, respawnState, solGame, false, true); verifyBuildNewFar(shipConfiguration().withGiveAmmo(true)); }
@Test public void testGiveNoAmmoIfNewShipAndRespawnItemsNotEmpty() { respawnState.getRespawnItems().add(mock(SolItem.class)); playerCreator.createPlayer(shipConfig, false, respawnState, solGame, false, true); verifyBuildNewFar(shipConfiguration().withGiveAmmo(false)); }
@Test public void testGiveNoAmmoIfNoNewShipAndRespawnItemsEmpty() { respawnState.getRespawnItems().clear(); playerCreator.createPlayer(shipConfig, false, respawnState, solGame, false, false); verifyBuildNewFar(shipConfiguration().withGiveAmmo(false)); }
@Test public void testShipIsUsedToCreateHero() { Hero hero = playerCreator.createPlayer(shipConfig, false, respawnState, solGame, false, false); assertThat(hero.getShip()).isSameAs(solShip); }
@Test public void testAddRespawnItems() { SolItem item0 = mock(SolItem.class); respawnState.getRespawnItems().add(item0); SolItem item1 = mock(SolItem.class); respawnState.getRespawnItems().add(item1); playerCreator.createPlayer(shipConfig, false, respawnState, solGame, false, false); assertThat(shipItemContainer.getGroup(0)).containsExactly(item1); assertThat(shipItemContainer.getGroup(1)).containsExactly(item0); }
@Test public void testReEquipRespawnItemsSeen() { SolItem item = mock(SolItem.class); when(item.isEquipped()).thenReturn(1); respawnState.getRespawnItems().add(item); playerCreator.createPlayer(shipConfig, false, respawnState, solGame, false, false); verify(solShip).maybeEquip(any(), eq(item), eq(true)); assertThat(shipItemContainer.hasNew()).isFalse(); }
@Test public void testReEquipRespawnItemGunsPrimarySlot() { Gun gun = mock(Gun.class); when(gun.isEquipped()).thenReturn(1); respawnState.getRespawnItems().add(gun); playerCreator.createPlayer(shipConfig, false, respawnState, solGame, false, false); verify(solShip).maybeEquip(any(), eq(gun), eq(false), eq(true)); }
@Test public void testReEquipRespawnItemGunsSecondarySlot() { Gun gun = mock(Gun.class); when(gun.isEquipped()).thenReturn(2); respawnState.getRespawnItems().add(gun); playerCreator.createPlayer(shipConfig, false, respawnState, solGame, false, false); verify(solShip).maybeEquip(any(), eq(gun), eq(true), eq(true)); }
@Test public void testTutorialModeAddsSeenItemsIfRespawnItemsAreEmpty() { respawnState.getRespawnItems().clear(); when(solGame.isTutorial()).thenReturn(true); int groupCountBefore = shipItemContainer.groupCount(); playerCreator.createPlayer(shipConfig, false, respawnState, solGame, false, false); assertThat(shipItemContainer.groupCount()).isGreaterThan(groupCountBefore); assertThat(shipItemContainer.hasNew()).isFalse(); }
@Test public void testAddShipDelayed() { playerCreator.createPlayer(shipConfig, false, respawnState, solGame, false, false); verify(solGame.getObjectManager()).addObjDelayed(solShip); }
@Test public void testResetObjectDelays() { playerCreator.createPlayer(shipConfig, false, respawnState, solGame, false, false); verify(solGame.getObjectManager()).resetDelays(); }