Minor refactorings and code style changes. 1) Removed several use of raw types 2) Removed unnecessary throws clauses 3) Used lambda expressions wherever applicable 4) Used apt assertion methods for readability 5) Use of try with resources wherever applicable 6) Corrected incorrect order of assertXXX arguments

This commit is contained in:
Narendra Pathai
2018-10-20 17:50:52 +05:30
parent 2f569d670a
commit 543eb9a4be
73 changed files with 207 additions and 298 deletions

View File

@ -34,7 +34,7 @@ import java.util.concurrent.ExecutionException;
public class AppTest {
@Test
public void test() throws InterruptedException, ExecutionException {
public void test() {
App.main(null);
}
}

View File

@ -22,6 +22,7 @@
*/
package com.iluwatar.halfsynchalfasync;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InOrder;
@ -44,11 +45,17 @@ import static org.mockito.Mockito.when;
* @author Jeroen Meulemeester
*/
public class AsynchronousServiceTest {
private AsynchronousService service;
private AsyncTask<Object> task;
@BeforeEach
public void setUp() {
service = new AsynchronousService(new LinkedBlockingQueue<>());
task = mock(AsyncTask.class);
}
@Test
public void testPerfectExecution() throws Exception {
final AsynchronousService service = new AsynchronousService(new LinkedBlockingQueue<>());
final AsyncTask<Object> task = mock(AsyncTask.class);
final Object result = new Object();
when(task.call()).thenReturn(result);
service.execute(task);
@ -65,8 +72,6 @@ public class AsynchronousServiceTest {
@Test
public void testCallException() throws Exception {
final AsynchronousService service = new AsynchronousService(new LinkedBlockingQueue<>());
final AsyncTask<Object> task = mock(AsyncTask.class);
final IOException exception = new IOException();
when(task.call()).thenThrow(exception);
service.execute(task);
@ -82,9 +87,7 @@ public class AsynchronousServiceTest {
}
@Test
public void testPreCallException() throws Exception {
final AsynchronousService service = new AsynchronousService(new LinkedBlockingQueue<>());
final AsyncTask<Object> task = mock(AsyncTask.class);
public void testPreCallException() {
final IllegalStateException exception = new IllegalStateException();
doThrow(exception).when(task).onPreCall();
service.execute(task);