📍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

@ -29,8 +29,7 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;
/**
* The Promise object is used for asynchronous computations. A Promise represents an operation that
@ -60,10 +59,9 @@ import org.slf4j.LoggerFactory;
*
* @see CompletableFuture
*/
@Slf4j
public class App {
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
private static final String DEFAULT_URL =
"https://raw.githubusercontent.com/iluwatar/java-design-patterns/master/promise/README.md";
private final ExecutorService executor;

View File

@ -36,16 +36,14 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;
/**
* Utility to perform various operations.
*/
@Slf4j
public class Utility {
private static final Logger LOGGER = LoggerFactory.getLogger(Utility.class);
/**
* Calculates character frequency of the file provided.
*

View File

@ -36,7 +36,6 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.function.Consumer;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@ -44,7 +43,7 @@ import org.junit.jupiter.api.Test;
/**
* Tests Promise class.
*/
public class PromiseTest {
class PromiseTest {
private Executor executor;
private Promise<Integer> promise;
@ -56,7 +55,7 @@ public class PromiseTest {
}
@Test
public void promiseIsFulfilledWithTheResultantValueOfExecutingTheTask()
void promiseIsFulfilledWithTheResultantValueOfExecutingTheTask()
throws InterruptedException, ExecutionException {
promise.fulfillInAsync(new NumberCrunchingTask(), executor);
@ -66,7 +65,7 @@ public class PromiseTest {
}
@Test
public void promiseIsFulfilledWithAnExceptionIfTaskThrowsAnException()
void promiseIsFulfilledWithAnExceptionIfTaskThrowsAnException()
throws InterruptedException {
testWaitingForeverForPromiseToBeFulfilled();
testWaitingSomeTimeForPromiseToBeFulfilled();
@ -120,7 +119,7 @@ public class PromiseTest {
}
@Test
public void dependentPromiseIsFulfilledAfterTheConsumerConsumesTheResultOfThisPromise()
void dependentPromiseIsFulfilledAfterTheConsumerConsumesTheResultOfThisPromise()
throws InterruptedException, ExecutionException {
var dependentPromise = promise
.fulfillInAsync(new NumberCrunchingTask(), executor)
@ -132,7 +131,7 @@ public class PromiseTest {
}
@Test
public void dependentPromiseIsFulfilledWithAnExceptionIfConsumerThrowsAnException()
void dependentPromiseIsFulfilledWithAnExceptionIfConsumerThrowsAnException()
throws InterruptedException {
var dependentPromise = promise
.fulfillInAsync(new NumberCrunchingTask(), executor)
@ -160,7 +159,7 @@ public class PromiseTest {
}
@Test
public void dependentPromiseIsFulfilledAfterTheFunctionTransformsTheResultOfThisPromise()
void dependentPromiseIsFulfilledAfterTheFunctionTransformsTheResultOfThisPromise()
throws InterruptedException, ExecutionException {
var dependentPromise = promise
.fulfillInAsync(new NumberCrunchingTask(), executor)
@ -176,7 +175,7 @@ public class PromiseTest {
}
@Test
public void dependentPromiseIsFulfilledWithAnExceptionIfTheFunctionThrowsException()
void dependentPromiseIsFulfilledWithAnExceptionIfTheFunctionThrowsException()
throws InterruptedException {
var dependentPromise = promise
.fulfillInAsync(new NumberCrunchingTask(), executor)
@ -204,17 +203,18 @@ public class PromiseTest {
}
@Test
public void fetchingAnAlreadyFulfilledPromiseReturnsTheFulfilledValueImmediately()
void fetchingAnAlreadyFulfilledPromiseReturnsTheFulfilledValueImmediately()
throws ExecutionException {
var promise = new Promise<Integer>();
promise.fulfill(NumberCrunchingTask.CRUNCHED_NUMBER);
promise.get(1000, TimeUnit.SECONDS);
Integer result = promise.get(1000, TimeUnit.SECONDS);
assertEquals(NumberCrunchingTask.CRUNCHED_NUMBER, result);
}
@SuppressWarnings("unchecked")
@Test
public void exceptionHandlerIsCalledWhenPromiseIsFulfilledExceptionally() {
void exceptionHandlerIsCalledWhenPromiseIsFulfilledExceptionally() {
var promise = new Promise<>();
var exceptionHandler = mock(Consumer.class);
promise.onError(exceptionHandler);