Search in sources :

Example 6 with GameWorld

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();
}
Also used : Game(de.gurkenlabs.litiengine.Game) Rectangle2D(java.awt.geom.Rectangle2D) Environment(de.gurkenlabs.litiengine.environment.Environment) GameWorld(de.gurkenlabs.litiengine.environment.GameWorld) StaticShadowLayer(de.gurkenlabs.litiengine.graphics.StaticShadowLayer) AmbientLight(de.gurkenlabs.litiengine.graphics.AmbientLight) Test(org.junit.jupiter.api.Test)

Example 7 with GameWorld

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();
}
Also used : Game(de.gurkenlabs.litiengine.Game) Rectangle2D(java.awt.geom.Rectangle2D) Environment(de.gurkenlabs.litiengine.environment.Environment) GameWorld(de.gurkenlabs.litiengine.environment.GameWorld) StaticShadowLayer(de.gurkenlabs.litiengine.graphics.StaticShadowLayer) AmbientLight(de.gurkenlabs.litiengine.graphics.AmbientLight) Test(org.junit.jupiter.api.Test)

Example 8 with GameWorld

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();
}
Also used : Game(de.gurkenlabs.litiengine.Game) GameWorld(de.gurkenlabs.litiengine.environment.GameWorld) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Game (de.gurkenlabs.litiengine.Game)8 GameWorld (de.gurkenlabs.litiengine.environment.GameWorld)8 Test (org.junit.jupiter.api.Test)8 Environment (de.gurkenlabs.litiengine.environment.Environment)6 AmbientLight (de.gurkenlabs.litiengine.graphics.AmbientLight)4 StaticShadowLayer (de.gurkenlabs.litiengine.graphics.StaticShadowLayer)4 Rectangle2D (java.awt.geom.Rectangle2D)4 Graphics2D (java.awt.Graphics2D)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 GameConfiguration (de.gurkenlabs.litiengine.configuration.GameConfiguration)1 GraphicConfiguration (de.gurkenlabs.litiengine.configuration.GraphicConfiguration)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1