Skip to content

Commit bee18d7

Browse files
author
eugenp
committed
core java cleanup
1 parent fe23591 commit bee18d7

21 files changed

Lines changed: 124 additions & 113 deletions

‎core-java/src/main/java/org/baeldung/equalshashcode/entities/ComplexClass.java‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package org.baeldung.equalshashcode.entities;
22

3-
import java.util.ArrayList;
4-
import java.util.HashSet;
53
import java.util.List;
64
import java.util.Set;
75

@@ -10,7 +8,7 @@ public class ComplexClass {
108
private List<?> genericList;
119
private Set<Integer> integerSet;
1210

13-
public ComplexClass(ArrayList<?> genericArrayList, HashSet<Integer> integerHashSet) {
11+
public ComplexClass(List<?> genericArrayList, Set<Integer> integerHashSet) {
1412
super();
1513
this.genericList = genericArrayList;
1614
this.integerSet = integerHashSet;

core-java/src/test/java/com/baeldung/CharToStringTest.java renamed to core-java/src/test/java/com/baeldung/CharToStringUnitTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import static org.assertj.core.api.Assertions.assertThat;
66

7-
public class CharToStringTest {
7+
public class CharToStringUnitTest {
88

99
@Test
1010
public void givenChar_whenCallingStringValueOf_shouldConvertToString() {

core-java/src/test/java/com/baeldung/collectors/Java8CollectorsTest.java renamed to core-java/src/test/java/com/baeldung/collectors/Java8CollectorsUnitTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
import static org.assertj.core.api.Assertions.assertThat;
3737
import static org.assertj.core.api.Assertions.assertThatThrownBy;
3838

39-
public class Java8CollectorsTest {
39+
public class Java8CollectorsUnitTest {
4040

4141
private final List<String> givenList = Arrays.asList("a", "bb", "ccc", "dd");
4242

core-java/src/test/java/com/baeldung/file/FileOperationsTest.java renamed to core-java/src/test/java/com/baeldung/file/FileOperationsUnitTest.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
package com.baeldung.file;
22

3-
import org.apache.commons.io.FileUtils;
4-
import org.hamcrest.CoreMatchers;
5-
import org.hamcrest.Matchers;
6-
import org.junit.Assert;
7-
import org.junit.Test;
8-
93
import java.io.BufferedReader;
104
import java.io.File;
115
import java.io.FileInputStream;
@@ -20,7 +14,13 @@
2014
import java.nio.file.Paths;
2115
import java.util.stream.Stream;
2216

23-
public class FileOperationsTest {
17+
import org.apache.commons.io.FileUtils;
18+
import org.hamcrest.CoreMatchers;
19+
import org.hamcrest.Matchers;
20+
import org.junit.Assert;
21+
import org.junit.Test;
22+
23+
public class FileOperationsUnitTest {
2424

2525
@Test
2626
public void givenFileName_whenUsingClassloader_thenFileData() throws IOException {
@@ -30,15 +30,15 @@ public void givenFileName_whenUsingClassloader_thenFileData() throws IOException
3030
File file = new File(classLoader.getResource("fileTest.txt").getFile());
3131
InputStream inputStream = new FileInputStream(file);
3232
String data = readFromInputStream(inputStream);
33-
33+
3434
Assert.assertEquals(expectedData, data.trim());
3535
}
3636

3737
@Test
3838
public void givenFileNameAsAbsolutePath_whenUsingClasspath_thenFileData() throws IOException {
3939
String expectedData = "Hello World from fileTest.txt!!!";
40-
41-
Class clazz = FileOperationsTest.class;
40+
41+
Class clazz = FileOperationsUnitTest.class;
4242
InputStream inputStream = clazz.getResourceAsStream("/fileTest.txt");
4343
String data = readFromInputStream(inputStream);
4444

@@ -69,44 +69,44 @@ public void givenURLName_whenUsingURL_thenFileData() throws IOException {
6969

7070
Assert.assertThat(data.trim(), CoreMatchers.containsString(expectedData));
7171
}
72-
72+
7373
@Test
7474
public void givenFileName_whenUsingFileUtils_thenFileData() throws IOException {
7575
String expectedData = "Hello World from fileTest.txt!!!";
76-
76+
7777
ClassLoader classLoader = getClass().getClassLoader();
7878
File file = new File(classLoader.getResource("fileTest.txt").getFile());
7979
String data = FileUtils.readFileToString(file);
80-
80+
8181
Assert.assertEquals(expectedData, data.trim());
8282
}
83-
83+
8484
@Test
8585
public void givenFilePath_whenUsingFilesReadAllBytes_thenFileData() throws IOException, URISyntaxException {
8686
String expectedData = "Hello World from fileTest.txt!!!";
8787

8888
Path path = Paths.get(getClass().getClassLoader().getResource("fileTest.txt").toURI());
89-
89+
9090
byte[] fileBytes = Files.readAllBytes(path);
9191
String data = new String(fileBytes);
9292

9393
Assert.assertEquals(expectedData, data.trim());
9494
}
95-
95+
9696
@Test
9797
public void givenFilePath_whenUsingFilesLines_thenFileData() throws IOException, URISyntaxException {
9898
String expectedData = "Hello World from fileTest.txt!!!";
9999

100100
Path path = Paths.get(getClass().getClassLoader().getResource("fileTest.txt").toURI());
101-
101+
102102
StringBuilder data = new StringBuilder();
103103
Stream<String> lines = Files.lines(path);
104104
lines.forEach(line -> data.append(line).append("\n"));
105105
lines.close();
106-
106+
107107
Assert.assertEquals(expectedData, data.toString().trim());
108108
}
109-
109+
110110
private String readFromInputStream(InputStream inputStream) throws IOException {
111111
StringBuilder resultStringBuilder = new StringBuilder();
112112
try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream))) {

core-java/src/test/java/com/baeldung/java/nio/selector/EchoTest.java renamed to core-java/src/test/java/com/baeldung/java/nio/selector/NioEchoIntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import org.junit.Test;
88

9-
public class EchoTest {
9+
public class NioEchoIntegrationTest {
1010

1111
@Test
1212
public void givenClient_whenServerEchosMessage_thenCorrect() throws IOException, InterruptedException {

core-java/src/test/java/com/baeldung/java8/Java8DefaultStaticIntefaceMethodsTest.java renamed to core-java/src/test/java/com/baeldung/java8/Java8DefaultStaticIntefaceMethodsUnitTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import static org.junit.Assert.assertEquals;
88

9-
public class Java8DefaultStaticIntefaceMethodsTest {
9+
public class Java8DefaultStaticIntefaceMethodsUnitTest {
1010

1111
@Test
1212
public void callStaticInterfaceMethdosMethods_whenExpectedResults_thenCorrect() {

core-java/src/test/java/com/baeldung/java8/Java8ExecutorServiceTest.java renamed to core-java/src/test/java/com/baeldung/java8/Java8ExecutorServiceIntegrationTest.java

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
11
package com.baeldung.java8;
22

3-
4-
import org.junit.Before;
5-
import org.junit.Test;
3+
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertFalse;
5+
import static org.junit.Assert.assertTrue;
66

77
import java.util.ArrayList;
88
import java.util.List;
9-
import java.util.concurrent.*;
10-
11-
import static org.junit.Assert.*;
9+
import java.util.concurrent.Callable;
10+
import java.util.concurrent.ExecutionException;
11+
import java.util.concurrent.ExecutorService;
12+
import java.util.concurrent.Executors;
13+
import java.util.concurrent.Future;
14+
import java.util.concurrent.LinkedBlockingQueue;
15+
import java.util.concurrent.ScheduledExecutorService;
16+
import java.util.concurrent.ThreadPoolExecutor;
17+
import java.util.concurrent.TimeUnit;
18+
import java.util.concurrent.TimeoutException;
1219

20+
import org.junit.Before;
21+
import org.junit.Test;
1322

14-
public class Java8ExecutorServiceTest {
23+
public class Java8ExecutorServiceIntegrationTest {
1524

1625
private Runnable runnableTask;
1726
private Callable<String> callableTask;
@@ -53,9 +62,7 @@ public void creationSubmittingTaskShuttingDown_whenShutDown_thenCorrect() {
5362
@Test
5463
public void creationSubmittingTasksShuttingDownNow_whenShutDownAfterAwating_thenCorrect() {
5564

56-
ExecutorService threadPoolExecutor =
57-
new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS,
58-
new LinkedBlockingQueue<>());
65+
ExecutorService threadPoolExecutor = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>());
5966

6067
for (int i = 0; i < 100; i++) {
6168
threadPoolExecutor.submit(callableTask);
@@ -138,8 +145,7 @@ public void submittingTask_whenCanceled_thenCorrect() {
138145
@Test
139146
public void submittingTaskScheduling_whenExecuted_thenCorrect() {
140147

141-
ScheduledExecutorService executorService = Executors
142-
.newSingleThreadScheduledExecutor();
148+
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
143149

144150
Future<String> resultFuture = executorService.schedule(callableTask, 1, TimeUnit.SECONDS);
145151
String result = null;

core-java/src/test/java/com/baeldung/java8/Java8ForkJoinTest.java renamed to core-java/src/test/java/com/baeldung/java8/Java8ForkJoinIntegrationTest.java

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
package com.baeldung.java8;
22

3-
4-
import com.baeldung.forkjoin.CustomRecursiveAction;
5-
import com.baeldung.forkjoin.CustomRecursiveTask;
6-
import com.baeldung.forkjoin.util.PoolUtil;
7-
import org.junit.Before;
8-
import org.junit.Test;
3+
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertNotNull;
5+
import static org.junit.Assert.assertTrue;
96

107
import java.util.Random;
118
import java.util.concurrent.ForkJoinPool;
129

13-
import static org.junit.Assert.*;
10+
import org.junit.Before;
11+
import org.junit.Test;
12+
13+
import com.baeldung.forkjoin.CustomRecursiveAction;
14+
import com.baeldung.forkjoin.CustomRecursiveTask;
15+
import com.baeldung.forkjoin.util.PoolUtil;
1416

15-
public class Java8ForkJoinTest {
17+
public class Java8ForkJoinIntegrationTest {
1618

1719
private int[] arr;
1820
private CustomRecursiveTask customRecursiveTask;
@@ -27,28 +29,23 @@ public void init() {
2729
customRecursiveTask = new CustomRecursiveTask(arr);
2830
}
2931

30-
3132
@Test
3233
public void callPoolUtil_whenExistsAndExpectedType_thenCorrect() {
33-
3434
ForkJoinPool forkJoinPool = PoolUtil.forkJoinPool;
3535
ForkJoinPool forkJoinPoolTwo = PoolUtil.forkJoinPool;
3636

3737
assertNotNull(forkJoinPool);
3838
assertEquals(2, forkJoinPool.getParallelism());
3939
assertEquals(forkJoinPool, forkJoinPoolTwo);
40-
4140
}
4241

4342
@Test
4443
public void callCommonPool_whenExistsAndExpectedType_thenCorrect() {
45-
4644
ForkJoinPool commonPool = ForkJoinPool.commonPool();
4745
ForkJoinPool commonPoolTwo = ForkJoinPool.commonPool();
4846

4947
assertNotNull(commonPool);
5048
assertEquals(commonPool, commonPoolTwo);
51-
5249
}
5350

5451
@Test
@@ -63,7 +60,6 @@ public void executeRecursiveAction_whenExecuted_thenCorrect() {
6360

6461
@Test
6562
public void executeRecursiveTask_whenExecuted_thenCorrect() {
66-
6763
ForkJoinPool forkJoinPool = ForkJoinPool.commonPool();
6864

6965
forkJoinPool.execute(customRecursiveTask);
@@ -73,12 +69,10 @@ public void executeRecursiveTask_whenExecuted_thenCorrect() {
7369
forkJoinPool.submit(customRecursiveTask);
7470
int resultTwo = customRecursiveTask.join();
7571
assertTrue(customRecursiveTask.isDone());
76-
7772
}
7873

7974
@Test
8075
public void executeRecursiveTaskWithFJ_whenExecuted_thenCorrect() {
81-
8276
CustomRecursiveTask customRecursiveTaskFirst = new CustomRecursiveTask(arr);
8377
CustomRecursiveTask customRecursiveTaskSecond = new CustomRecursiveTask(arr);
8478
CustomRecursiveTask customRecursiveTaskLast = new CustomRecursiveTask(arr);
@@ -95,6 +89,6 @@ public void executeRecursiveTaskWithFJ_whenExecuted_thenCorrect() {
9589
assertTrue(customRecursiveTaskSecond.isDone());
9690
assertTrue(customRecursiveTaskLast.isDone());
9791
assertTrue(result != 0);
98-
9992
}
93+
10094
}

core-java/src/test/java/com/baeldung/java8/Java8FunctionalInteracesLambdasTest.java renamed to core-java/src/test/java/com/baeldung/java8/Java8FunctionalInteracesLambdasUnitTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import static org.junit.Assert.assertEquals;
1212
import static org.junit.Assert.assertNotEquals;
1313

14-
public class Java8FunctionalInteracesLambdasTest {
14+
public class Java8FunctionalInteracesLambdasUnitTest {
1515

1616
private UseFoo useFoo;
1717

core-java/src/test/java/com/baeldung/java8/Java8MethodReferenceTest.java renamed to core-java/src/test/java/com/baeldung/java8/Java8MethodReferenceUnitTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import static org.junit.Assert.assertEquals;
1313
import static org.junit.Assert.assertTrue;
1414

15-
public class Java8MethodReferenceTest {
15+
public class Java8MethodReferenceUnitTest {
1616

1717
private List<String> list;
1818

0 commit comments

Comments
 (0)