Search in sources :

Example 1 with StaticShadowLayer

use of de.gurkenlabs.litiengine.graphics.StaticShadowLayer 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();
}
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 2 with StaticShadowLayer

use of de.gurkenlabs.litiengine.graphics.StaticShadowLayer 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();
}
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 3 with StaticShadowLayer

use of de.gurkenlabs.litiengine.graphics.StaticShadowLayer in project litiengine by gurkenlabs.

the class Environment method addStaticShadows.

private void addStaticShadows() {
    final Color color = this.getMap().getColorValue(MapProperty.SHADOWCOLOR, StaticShadow.DEFAULT_COLOR);
    this.staticShadowLayer = new StaticShadowLayer(this, color);
}
Also used : Color(java.awt.Color) StaticShadowLayer(de.gurkenlabs.litiengine.graphics.StaticShadowLayer)

Example 4 with StaticShadowLayer

use of de.gurkenlabs.litiengine.graphics.StaticShadowLayer 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 5 with StaticShadowLayer

use of de.gurkenlabs.litiengine.graphics.StaticShadowLayer 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)

Aggregations

StaticShadowLayer (de.gurkenlabs.litiengine.graphics.StaticShadowLayer)5 Game (de.gurkenlabs.litiengine.Game)4 Environment (de.gurkenlabs.litiengine.environment.Environment)4 GameWorld (de.gurkenlabs.litiengine.environment.GameWorld)4 AmbientLight (de.gurkenlabs.litiengine.graphics.AmbientLight)4 Rectangle2D (java.awt.geom.Rectangle2D)4 Test (org.junit.jupiter.api.Test)4 Color (java.awt.Color)1