use of de.gurkenlabs.litiengine.environment.GameWorld in project litiengine by gurkenlabs.
the class EntityTests method testRemoveTagEmpty.
@Test
void testRemoveTagEmpty() {
// arrange
String tag = "test tag";
List<String> tagListSpy = spy(new ArrayList<>());
tagListSpy.add(tag);
TestEntity entitySpy = spy(new TestEntity());
when(entitySpy.getTags()).thenReturn(tagListSpy);
Environment environmentMock = mock(Environment.class);
Map<String, Collection<IEntity>> entities = new HashMap<>();
List<IEntity> entitiesContent = new ArrayList<>();
entitiesContent.add(entitySpy);
entities.put(tag, entitiesContent);
when(environmentMock.getEntitiesByTag()).thenReturn(entities);
when(entitySpy.getEnvironment()).thenReturn(environmentMock);
MockedStatic<Game> gameMockedStatic = mockStatic(Game.class);
GameWorld gameWorldMock = mock(GameWorld.class);
when(gameWorldMock.environment()).thenReturn(mock(Environment.class));
gameMockedStatic.when(Game::world).thenReturn(gameWorldMock);
assertEquals(1, entities.size());
// act
entitySpy.removeTag(tag);
// assert
verify(tagListSpy, times(1)).remove(tag);
assertEquals(0, entities.size());
// cleanup
gameMockedStatic.close();
}
use of de.gurkenlabs.litiengine.environment.GameWorld in project litiengine by gurkenlabs.
the class LightSourceTests method render_withDynamicShadows.
@Test
void render_withDynamicShadows() {
// arrange
GameConfiguration actualGameConfigSpy = spy(Game.config());
GraphicConfiguration actualGraphicsConfigSpy = spy(actualGameConfigSpy.graphics());
MockedStatic<Game> gameMockedStatic = mockStatic(Game.class);
gameMockedStatic.when(Game::config).thenReturn(// otherwise it is null because of the mock
actualGameConfigSpy);
when(actualGameConfigSpy.graphics()).thenReturn(actualGraphicsConfigSpy);
when(actualGraphicsConfigSpy.renderDynamicShadows()).thenReturn(true);
Environment mockedEnv = mock(Environment.class);
GameWorld mockedWorld = mock(GameWorld.class);
when(mockedWorld.environment()).thenReturn(mockedEnv);
gameMockedStatic.when(Game::world).thenReturn(mockedWorld);
Graphics2D graphicMock = mock(Graphics2D.class);
assertTrue(Game.config().graphics().renderDynamicShadows());
// act
lightSourceInactiveSpy.render(graphicMock);
// assert
verify(mockedWorld, times(1)).environment();
// cleanup
gameMockedStatic.close();
}
use of de.gurkenlabs.litiengine.environment.GameWorld in project litiengine by gurkenlabs.
the class LightSourceTests method updateAmbientLayers_delegatesWhenLoaded.
@Test
void updateAmbientLayers_delegatesWhenLoaded() {
// arrange
when(lightSourceInactiveSpy.isLoaded()).thenReturn(true);
GameWorld actualWorld = spy(Game.world());
MockedStatic<Game> gameMockedStatic = mockStatic(Game.class);
gameMockedStatic.when(Game::world).thenReturn(// otherwise it is null because of the mock
actualWorld);
Environment environmentMock = mock(Environment.class);
when(actualWorld.environment()).thenReturn(environmentMock);
AmbientLight ambientLightMock = mock(AmbientLight.class);
when(environmentMock.getAmbientLight()).thenReturn(ambientLightMock);
StaticShadowLayer staticShadowLayerMock = mock(StaticShadowLayer.class);
when(environmentMock.getStaticShadowLayer()).thenReturn(staticShadowLayerMock);
// act
// means to trigger private method within
lightSourceInactiveSpy.setColor(Color.GREEN);
// assert
verify(lightSourceInactiveSpy, times(1)).isLoaded();
verify(ambientLightMock, times(1)).updateSection(any(Rectangle2D.class));
verify(staticShadowLayerMock, times(1)).updateSection(any(Rectangle2D.class));
// cleanup
gameMockedStatic.close();
}
use of de.gurkenlabs.litiengine.environment.GameWorld in project litiengine by gurkenlabs.
the class LightSourceTests method render_noDynamicShadows.
@Test
void render_noDynamicShadows() {
// arrange
GameWorld mockedWorld = mock(GameWorld.class);
MockedStatic<Game> gameMockedStatic = mockStatic(Game.class);
gameMockedStatic.when(Game::world).thenReturn(mockedWorld);
gameMockedStatic.when(Game::config).thenCallRealMethod();
Graphics2D graphicMock = mock(Graphics2D.class);
// is default
assertFalse(Game.config().graphics().renderDynamicShadows());
// act
lightSourceInactiveSpy.render(graphicMock);
// assert
verify(mockedWorld, times(0)).environment();
// cleanup
gameMockedStatic.close();
}
use of de.gurkenlabs.litiengine.environment.GameWorld in project litiengine by gurkenlabs.
the class LightSourceTests method updateAmbientLayers_doesNothingWithoutLayers.
@Test
void updateAmbientLayers_doesNothingWithoutLayers() {
// arrange
when(lightSourceInactiveSpy.isLoaded()).thenReturn(true);
GameWorld actualWorld = spy(Game.world());
MockedStatic<Game> gameMockedStatic = mockStatic(Game.class);
gameMockedStatic.when(Game::world).thenReturn(// otherwise it is null because of the mock
actualWorld);
Environment environmentMock = mock(Environment.class);
when(actualWorld.environment()).thenReturn(environmentMock);
AmbientLight ambientLightMock = mock(AmbientLight.class);
when(environmentMock.getAmbientLight()).thenReturn(null);
StaticShadowLayer staticShadowLayerMock = mock(StaticShadowLayer.class);
when(environmentMock.getStaticShadowLayer()).thenReturn(null);
// act
// means to trigger private method within
lightSourceInactiveSpy.setColor(Color.GREEN);
// assert
verify(lightSourceInactiveSpy, times(1)).isLoaded();
verify(ambientLightMock, times(0)).updateSection(any(Rectangle2D.class));
verify(staticShadowLayerMock, times(0)).updateSection(any(Rectangle2D.class));
// cleanup
gameMockedStatic.close();
}
Aggregations