Skip to content

Commit 543eb9a

Browse files
committed
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
1 parent 2f569d6 commit 543eb9a

File tree

73 files changed

+207
-298
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+207
-298
lines changed

fluentinterface/src/main/java/com/iluwatar/fluentinterface/fluentiterable/simple/SimpleFluentIterable.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,11 @@ public List<E> asList() {
171171
/**
172172
* @return a FluentIterable from a given iterable. Calls the SimpleFluentIterable constructor.
173173
*/
174-
public static final <E> FluentIterable<E> from(Iterable<E> iterable) {
174+
public static <E> FluentIterable<E> from(Iterable<E> iterable) {
175175
return new SimpleFluentIterable<>(iterable);
176176
}
177177

178-
public static final <E> FluentIterable<E> fromCopyOf(Iterable<E> iterable) {
178+
public static <E> FluentIterable<E> fromCopyOf(Iterable<E> iterable) {
179179
List<E> copy = FluentIterable.copyToList(iterable);
180180
return new SimpleFluentIterable<>(copy);
181181
}

front-controller/src/main/java/com/iluwatar/front/controller/FrontController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,16 @@ public void handleRequest(String request) {
3636
}
3737

3838
private Command getCommand(String request) {
39-
Class commandClass = getCommandClass(request);
39+
Class<?> commandClass = getCommandClass(request);
4040
try {
4141
return (Command) commandClass.newInstance();
4242
} catch (Exception e) {
4343
throw new ApplicationException(e);
4444
}
4545
}
4646

47-
private static Class getCommandClass(String request) {
48-
Class result;
47+
private static Class<?> getCommandClass(String request) {
48+
Class<?> result;
4949
try {
5050
result = Class.forName("com.iluwatar.front.controller." + request + "Command");
5151
} catch (ClassNotFoundException e) {

front-controller/src/test/java/com/iluwatar/front/controller/ApplicationExceptionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
public class ApplicationExceptionTest {
3535

3636
@Test
37-
public void testCause() throws Exception {
37+
public void testCause() {
3838
final Exception cause = new Exception();
3939
assertSame(cause, new ApplicationException(cause).getCause());
4040
}

guarded-suspension/src/test/java/com/iluwatar/guarded/suspension/GuardedQueueTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void testGet() {
4141
GuardedQueue g = new GuardedQueue();
4242
ExecutorService executorService = Executors.newFixedThreadPool(2);
4343
executorService.submit(() -> value = g.get());
44-
executorService.submit(() -> g.put(Integer.valueOf(10)));
44+
executorService.submit(() -> g.put(10));
4545
executorService.shutdown();
4646
try {
4747
executorService.awaitTermination(30, TimeUnit.SECONDS);

half-sync-half-async/src/test/java/com/iluwatar/halfsynchalfasync/AppTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
public class AppTest {
3535

3636
@Test
37-
public void test() throws InterruptedException, ExecutionException {
37+
public void test() {
3838
App.main(null);
3939
}
4040
}

half-sync-half-async/src/test/java/com/iluwatar/halfsynchalfasync/AsynchronousServiceTest.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
*/
2323
package com.iluwatar.halfsynchalfasync;
2424

25+
import org.junit.jupiter.api.BeforeEach;
2526
import org.junit.jupiter.api.Test;
2627
import org.mockito.InOrder;
2728

@@ -44,11 +45,17 @@
4445
* @author Jeroen Meulemeester
4546
*/
4647
public class AsynchronousServiceTest {
48+
private AsynchronousService service;
49+
private AsyncTask<Object> task;
50+
51+
@BeforeEach
52+
public void setUp() {
53+
service = new AsynchronousService(new LinkedBlockingQueue<>());
54+
task = mock(AsyncTask.class);
55+
}
4756

4857
@Test
4958
public void testPerfectExecution() throws Exception {
50-
final AsynchronousService service = new AsynchronousService(new LinkedBlockingQueue<>());
51-
final AsyncTask<Object> task = mock(AsyncTask.class);
5259
final Object result = new Object();
5360
when(task.call()).thenReturn(result);
5461
service.execute(task);
@@ -65,8 +72,6 @@ public void testPerfectExecution() throws Exception {
6572

6673
@Test
6774
public void testCallException() throws Exception {
68-
final AsynchronousService service = new AsynchronousService(new LinkedBlockingQueue<>());
69-
final AsyncTask<Object> task = mock(AsyncTask.class);
7075
final IOException exception = new IOException();
7176
when(task.call()).thenThrow(exception);
7277
service.execute(task);
@@ -82,9 +87,7 @@ public void testCallException() throws Exception {
8287
}
8388

8489
@Test
85-
public void testPreCallException() throws Exception {
86-
final AsynchronousService service = new AsynchronousService(new LinkedBlockingQueue<>());
87-
final AsyncTask<Object> task = mock(AsyncTask.class);
90+
public void testPreCallException() {
8891
final IllegalStateException exception = new IllegalStateException();
8992
doThrow(exception).when(task).onPreCall();
9093
service.execute(task);

intercepting-filter/src/main/java/com/iluwatar/intercepting/filter/Client.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222
*/
2323
package com.iluwatar.intercepting.filter;
2424

25-
import java.awt.BorderLayout;
26-
import java.awt.GridLayout;
27-
2825
import javax.swing.JButton;
2926
import javax.swing.JFrame;
3027
import javax.swing.JLabel;
@@ -33,6 +30,9 @@
3330
import javax.swing.JTextArea;
3431
import javax.swing.JTextField;
3532
import javax.swing.SwingUtilities;
33+
import javax.swing.WindowConstants;
34+
import java.awt.BorderLayout;
35+
import java.awt.GridLayout;
3636

3737
/**
3838
* The Client class is responsible for handling the input and running them through filters inside the
@@ -60,7 +60,7 @@ public class Client extends JFrame { // NOSONAR
6060
*/
6161
public Client() {
6262
super("Client System");
63-
setDefaultCloseOperation(EXIT_ON_CLOSE);
63+
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
6464
setSize(300, 300);
6565
jl = new JLabel("RUNNING...");
6666
jtFields = new JTextField[3];

intercepting-filter/src/main/java/com/iluwatar/intercepting/filter/Target.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,19 @@
2222
*/
2323
package com.iluwatar.intercepting.filter;
2424

25-
import java.awt.BorderLayout;
26-
import java.awt.Dimension;
27-
import java.awt.event.ActionEvent;
28-
import java.awt.event.ActionListener;
29-
3025
import javax.swing.JButton;
3126
import javax.swing.JFrame;
3227
import javax.swing.JPanel;
3328
import javax.swing.JRootPane;
3429
import javax.swing.JScrollPane;
3530
import javax.swing.JTable;
3631
import javax.swing.SwingUtilities;
32+
import javax.swing.WindowConstants;
3733
import javax.swing.table.DefaultTableModel;
34+
import java.awt.BorderLayout;
35+
import java.awt.Dimension;
36+
import java.awt.event.ActionEvent;
37+
import java.awt.event.ActionListener;
3838

3939
/**
4040
* This is where the requests are displayed after being validated by filters.
@@ -47,7 +47,6 @@ public class Target extends JFrame { //NOSONAR
4747
private static final long serialVersionUID = 1L;
4848

4949
private JTable jt;
50-
private JScrollPane jsp;
5150
private DefaultTableModel dtm;
5251
private JButton del;
5352

@@ -56,7 +55,7 @@ public class Target extends JFrame { //NOSONAR
5655
*/
5756
public Target() {
5857
super("Order System");
59-
setDefaultCloseOperation(EXIT_ON_CLOSE);
58+
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
6059
setSize(640, 480);
6160
dtm =
6261
new DefaultTableModel(new Object[] {"Name", "Contact Number", "Address", "Deposit Number",
@@ -73,7 +72,7 @@ private void setup() {
7372
bot.setLayout(new BorderLayout());
7473
bot.add(del, BorderLayout.EAST);
7574
add(bot, BorderLayout.SOUTH);
76-
jsp = new JScrollPane(jt);
75+
JScrollPane jsp = new JScrollPane(jt);
7776
jsp.setPreferredSize(new Dimension(500, 250));
7877
add(jsp, BorderLayout.CENTER);
7978

intercepting-filter/src/test/java/com/iluwatar/intercepting/filter/FilterManagerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@
4040
public class FilterManagerTest {
4141

4242
@Test
43-
public void testFilterRequest() throws Exception {
43+
public void testFilterRequest() {
4444
final Target target = mock(Target.class);
4545
final FilterManager filterManager = new FilterManager();
4646
assertEquals("RUNNING...", filterManager.filterRequest(mock(Order.class)));
4747
verifyZeroInteractions(target);
4848
}
4949

5050
@Test
51-
public void testAddFilter() throws Exception {
51+
public void testAddFilter() {
5252
final Target target = mock(Target.class);
5353
final FilterManager filterManager = new FilterManager();
5454

intercepting-filter/src/test/java/com/iluwatar/intercepting/filter/FilterTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,15 @@ static List<Object[]> getTestData() {
8989

9090
@ParameterizedTest
9191
@MethodSource("getTestData")
92-
public void testExecute(Filter filter, Order order, String expectedResult) throws Exception {
92+
public void testExecute(Filter filter, Order order, String expectedResult) {
9393
final String result = filter.execute(order);
9494
assertNotNull(result);
9595
assertEquals(expectedResult, result.trim());
9696
}
9797

9898
@ParameterizedTest
9999
@MethodSource("getTestData")
100-
public void testNext(Filter filter) throws Exception {
100+
public void testNext(Filter filter) {
101101
assertNull(filter.getNext());
102102
assertSame(filter, filter.getLast());
103103
}

0 commit comments

Comments
 (0)