📍Use lombok, reformat, and optimize the code (#1560)
* Use lombok, reformat, and optimize the code * Fix merge conflicts and some sonar issues Co-authored-by: va1m <va1m@email.com>
This commit is contained in:
@ -23,18 +23,16 @@
|
||||
|
||||
package com.iluwatar.gameloop;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* A game loop runs continuously during gameplay. Each turn of the loop, it processes
|
||||
* user input without blocking, updates the game state, and renders the game. It tracks
|
||||
* the passage of time to control the rate of gameplay.
|
||||
*/
|
||||
@Slf4j
|
||||
public class App {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
||||
|
||||
/**
|
||||
* Each type of game loop will run for 2 seconds.
|
||||
*/
|
||||
|
@ -23,17 +23,17 @@
|
||||
|
||||
package com.iluwatar.gameloop;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* App unit test class.
|
||||
*/
|
||||
public class AppTest {
|
||||
|
||||
@Test
|
||||
public void shouldExecuteApplicationWithoutException() {
|
||||
void shouldExecuteApplicationWithoutException() {
|
||||
assertDoesNotThrow(() -> App.main(new String[]{}));
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ public class FixedStepGameLoopTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdate() {
|
||||
void testUpdate() {
|
||||
gameLoop.update();
|
||||
assertEquals(0.01f, gameLoop.controller.getBulletPosition(), 0);
|
||||
}
|
||||
|
@ -27,26 +27,27 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* FrameBasedGameLoop unit test class.
|
||||
*/
|
||||
public class FrameBasedGameLoopTest {
|
||||
class FrameBasedGameLoopTest {
|
||||
|
||||
private FrameBasedGameLoop gameLoop;
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
void setup() {
|
||||
gameLoop = new FrameBasedGameLoop();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
void tearDown() {
|
||||
gameLoop = null;
|
||||
}
|
||||
|
||||
@org.junit.jupiter.api.Test
|
||||
public void testUpdate() {
|
||||
@Test
|
||||
void testUpdate() {
|
||||
gameLoop.update();
|
||||
assertEquals(0.5f, gameLoop.controller.getBulletPosition(), 0);
|
||||
}
|
||||
|
@ -23,11 +23,13 @@
|
||||
|
||||
package com.iluwatar.gameloop;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class GameControllerTest {
|
||||
class GameControllerTest {
|
||||
|
||||
private GameController controller;
|
||||
|
||||
@ -41,15 +43,15 @@ public class GameControllerTest {
|
||||
controller = null;
|
||||
}
|
||||
|
||||
@org.junit.jupiter.api.Test
|
||||
public void testMoveBullet() {
|
||||
@Test
|
||||
void testMoveBullet() {
|
||||
controller.moveBullet(1.5f);
|
||||
Assertions.assertEquals(1.5f, controller.bullet.getPosition(), 0);
|
||||
assertEquals(1.5f, controller.bullet.getPosition(), 0);
|
||||
}
|
||||
|
||||
@org.junit.jupiter.api.Test
|
||||
public void testGetBulletPosition() {
|
||||
Assertions.assertEquals(controller.bullet.getPosition(), controller.getBulletPosition(), 0);
|
||||
@Test
|
||||
void testGetBulletPosition() {
|
||||
assertEquals(controller.bullet.getPosition(), controller.getBulletPosition(), 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -23,14 +23,17 @@
|
||||
|
||||
package com.iluwatar.gameloop;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* GameLoop unit test class.
|
||||
*/
|
||||
public class GameLoopTest {
|
||||
class GameLoopTest {
|
||||
|
||||
private GameLoop gameLoop;
|
||||
|
||||
@ -38,33 +41,33 @@ public class GameLoopTest {
|
||||
* Create mock implementation of GameLoop.
|
||||
*/
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
void setup() {
|
||||
gameLoop = new GameLoop() {
|
||||
@Override
|
||||
protected void processGameLoop() {}
|
||||
protected void processGameLoop() {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
void tearDown() {
|
||||
gameLoop = null;
|
||||
}
|
||||
|
||||
@org.junit.jupiter.api.Test
|
||||
public void testRun() {
|
||||
@Test
|
||||
void testRun() {
|
||||
gameLoop.run();
|
||||
Assertions.assertEquals(GameStatus.RUNNING, gameLoop.status);
|
||||
}
|
||||
|
||||
@org.junit.jupiter.api.Test
|
||||
public void testStop() {
|
||||
@Test
|
||||
void testStop() {
|
||||
gameLoop.stop();
|
||||
Assertions.assertEquals(GameStatus.STOPPED, gameLoop.status);
|
||||
}
|
||||
|
||||
@org.junit.jupiter.api.Test
|
||||
public void testIsGameRunning() {
|
||||
Assertions.assertFalse(gameLoop.isGameRunning());
|
||||
@Test
|
||||
void testIsGameRunning() {
|
||||
assertFalse(gameLoop.isGameRunning());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -23,29 +23,30 @@
|
||||
|
||||
package com.iluwatar.gameloop;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* VariableStepGameLoop unit test class.
|
||||
*/
|
||||
public class VariableStepGameLoopTest {
|
||||
class VariableStepGameLoopTest {
|
||||
|
||||
private VariableStepGameLoop gameLoop;
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
void setup() {
|
||||
gameLoop = new VariableStepGameLoop();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
void tearDown() {
|
||||
gameLoop = null;
|
||||
}
|
||||
|
||||
@org.junit.jupiter.api.Test
|
||||
public void testUpdate() {
|
||||
@Test
|
||||
void testUpdate() {
|
||||
gameLoop.update(20L);
|
||||
Assertions.assertEquals(0.01f, gameLoop.controller.getBulletPosition(), 0);
|
||||
}
|
||||
|
Reference in New Issue
Block a user