📍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:
va1m
2021-03-13 13:19:21 +01:00
committed by GitHub
parent 0e26a6adb5
commit 5cf2fe009b
681 changed files with 2472 additions and 4966 deletions

View File

@ -23,26 +23,22 @@
package com.iluwatar.twin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
/**
* This class represents a Ball which extends {@link GameItem} and implements the logic for ball
* item, like move and draw. It hold a reference of {@link BallThread} to delegate the suspend and
* resume task.
*/
@Slf4j
public class BallItem extends GameItem {
private static final Logger LOGGER = LoggerFactory.getLogger(BallItem.class);
private boolean isSuspended;
@Setter
private BallThread twin;
public void setTwin(BallThread twin) {
this.twin = twin;
}
@Override
public void doDraw() {

View File

@ -23,28 +23,24 @@
package com.iluwatar.twin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
/**
* This class is a UI thread for drawing the {@link BallItem}, and provide the method for suspend
* and resume. It hold the reference of {@link BallItem} to delegate the draw task.
*/
@Slf4j
public class BallThread extends Thread {
private static final Logger LOGGER = LoggerFactory.getLogger(BallThread.class);
@Setter
private BallItem twin;
private volatile boolean isSuspended;
private volatile boolean isRunning = true;
public void setTwin(BallItem twin) {
this.twin = twin;
}
/**
* Run the thread.
*/

View File

@ -23,16 +23,14 @@
package com.iluwatar.twin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;
/**
* GameItem is a common class which provides some common methods for game object.
*/
@Slf4j
public abstract class GameItem {
private static final Logger LOGGER = LoggerFactory.getLogger(GameItem.class);
/**
* Template method, do some common logic before draw.
*/

View File

@ -60,7 +60,7 @@ public class BallItemTest {
}
@Test
public void testClick() {
void testClick() {
final var ballThread = mock(BallThread.class);
final var ballItem = new BallItem();
ballItem.setTwin(ballThread);
@ -78,7 +78,7 @@ public class BallItemTest {
}
@Test
public void testDoDraw() {
void testDoDraw() {
final var ballItem = new BallItem();
final var ballThread = mock(BallThread.class);
ballItem.setTwin(ballThread);
@ -92,7 +92,7 @@ public class BallItemTest {
}
@Test
public void testMove() {
void testMove() {
final var ballItem = new BallItem();
final var ballThread = mock(BallThread.class);
ballItem.setTwin(ballThread);

View File

@ -42,13 +42,13 @@ import org.junit.jupiter.api.Test;
*
* @author Jeroen Meulemeester
*/
public class BallThreadTest {
class BallThreadTest {
/**
* Verify if the {@link BallThread} can be resumed
*/
@Test
public void testSuspend() {
void testSuspend() {
assertTimeout(ofMillis(5000), () -> {
final var ballThread = new BallThread();
@ -74,7 +74,7 @@ public class BallThreadTest {
* Verify if the {@link BallThread} can be resumed
*/
@Test
public void testResume() {
void testResume() {
assertTimeout(ofMillis(5000), () -> {
final var ballThread = new BallThread();
@ -104,7 +104,7 @@ public class BallThreadTest {
* Verify if the {@link BallThread} is interruptible
*/
@Test
public void testInterrupt() {
void testInterrupt() {
assertTimeout(ofMillis(5000), () -> {
final var ballThread = new BallThread();
final var exceptionHandler = mock(UncaughtExceptionHandler.class);