use of de.gurkenlabs.litiengine.environment.GameWorld in project litiengine by gurkenlabs.
the class LightSourceTests method updateAmbientLayers_doesNothingWhenNotLoaded.
@Test
void updateAmbientLayers_doesNothingWhenNotLoaded() {
// arrange
when(lightSourceInactiveSpy.isLoaded()).thenReturn(// should be default, just making sure
false);
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(0)).updateSection(any(Rectangle2D.class));
verify(staticShadowLayerMock, times(0)).updateSection(any(Rectangle2D.class));
// cleanup
gameMockedStatic.close();
}
use of de.gurkenlabs.litiengine.environment.GameWorld in project litiengine by gurkenlabs.
the class LightSourceTests method updateAmbientLayers_doesNothingWithoutGameEnvironment.
@Test
void updateAmbientLayers_doesNothingWithoutGameEnvironment() {
// 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(null);
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(actualWorld, times(2)).environment();
verify(ambientLightMock, times(0)).updateSection(any(Rectangle2D.class));
verify(staticShadowLayerMock, times(0)).updateSection(any(Rectangle2D.class));
// cleanup
gameMockedStatic.close();
}
use of de.gurkenlabs.litiengine.environment.GameWorld in project litiengine by gurkenlabs.
the class EntityTests method testRemoveTagGameEnvironmentNull.
@Test
void testRemoveTagGameEnvironmentNull() {
// arrange
String tag = "test tag";
List<String> tagListSpy = spy(new ArrayList<>());
tagListSpy.add(tag);
TestEntity entitySpy = spy(new TestEntity());
when(entitySpy.getTags()).thenReturn(tagListSpy);
MockedStatic<Game> gameMockedStatic = mockStatic(Game.class);
GameWorld gameWorldMock = mock(GameWorld.class);
when(gameWorldMock.environment()).thenReturn(null);
gameMockedStatic.when(Game::world).thenReturn(gameWorldMock);
// act
entitySpy.removeTag(tag);
// assert
verify(tagListSpy, times(1)).remove(tag);
verify(entitySpy, times(0)).getEnvironment();
// cleanup
gameMockedStatic.close();
}
Aggregations