Skip to content

Commit 31471ac

Browse files
Toxic DreamzToxic Dreamz
Toxic Dreamz
authored and
Toxic Dreamz
committed
Fixed most reported issues by SonarCloud.
1 parent e7e3ace commit 31471ac

File tree

190 files changed

+1426
-661
lines changed

Some content is hidden

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

190 files changed

+1426
-661
lines changed

abstract-document/src/test/java/com/iluwatar/abstractdocument/AppTest.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,23 @@
2525

2626
import org.junit.jupiter.api.Test;
2727

28+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
29+
2830
/**
2931
* Simple App test
3032
*/
31-
public class AppTest {
33+
class AppTest {
34+
35+
/**
36+
* Issue: Add at least one assertion to this test case.
37+
*
38+
* Solution: Inserted assertion to check whether the execution of the main method in {@link App}
39+
* throws an exception.
40+
*/
3241

3342
@Test
34-
public void shouldExecuteAppWithoutException() {
35-
App.main(null);
43+
void shouldExecuteAppWithoutException() {
44+
assertDoesNotThrow(() -> App.main(null));
3645
}
3746

3847
}

abstract-factory/src/test/java/com/iluwatar/abstractfactory/AppTest.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,23 @@
2525

2626
import org.junit.jupiter.api.Test;
2727

28+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
29+
2830
/**
2931
* Tests that Abstract Factory example runs without errors.
3032
*/
31-
public class AppTest {
33+
class AppTest {
34+
35+
/**
36+
* Issue: Add at least one assertion to this test case.
37+
*
38+
* Solution: Inserted assertion to check whether the execution of the main method in {@link App}
39+
* throws an exception.
40+
*/
41+
3242
@Test
33-
public void test() {
34-
App.main(new String[]{});
43+
void shouldExecuteApplicationWithoutException() {
44+
45+
assertDoesNotThrow(() -> App.main(new String[]{}));
3546
}
3647
}

acyclic-visitor/src/test/java/com/iluwatar/acyclicvisitor/AppTest.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,23 @@
2525

2626
import org.junit.jupiter.api.Test;
2727

28+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
29+
2830
/**
2931
* Tests that the Acyclic Visitor example runs without errors.
3032
*/
31-
public class AppTest {
33+
class AppTest {
34+
35+
/**
36+
* Issue: Add at least one assertion to this test case.
37+
*
38+
* Solution: Inserted assertion to check whether the execution of the main method in {@link App}
39+
* throws an exception.
40+
*/
3241

3342
@Test
34-
public void test() {
35-
App.main(new String[]{});
43+
void shouldExecuteApplicationWithoutException() {
44+
45+
assertDoesNotThrow(() -> App.main(new String[]{}));
3646
}
3747
}

adapter/src/test/java/com/iluwatar/adapter/AppTest.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,23 @@
2525

2626
import org.junit.jupiter.api.Test;
2727

28+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
29+
2830
/**
2931
* Tests that Adapter example runs without errors.
3032
*/
31-
public class AppTest {
33+
class AppTest {
34+
35+
/**
36+
* Issue: Add at least one assertion to this test case.
37+
*
38+
* Solution: Inserted assertion to check whether the execution of the main method in {@link App}
39+
* throws an exception.
40+
*/
41+
3242
@Test
33-
public void test() {
34-
App.main(new String[]{});
43+
void shouldExecuteApplicationWithoutException() {
44+
45+
assertDoesNotThrow(() -> App.main(new String[]{}));
3546
}
3647
}

ambassador/src/main/java/com/iluwatar/ambassador/RemoteService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ private RemoteService() {
6262
*
6363
* @param value integer value to be multiplied.
6464
* @return if waitTime is less than {@link RemoteService#THRESHOLD}, it returns value * 10,
65-
* otherwise {@link RemoteServiceInterface#FAILURE}.
65+
* otherwise {@link RemoteServiceStatus#FAILURE}.
6666
*/
6767
@Override
6868
public long doRemoteFunction(int value) {
@@ -74,6 +74,6 @@ public long doRemoteFunction(int value) {
7474
} catch (InterruptedException e) {
7575
LOGGER.error("Thread sleep state interrupted", e);
7676
}
77-
return waitTime <= THRESHOLD ? value * 10 : FAILURE;
77+
return waitTime <= THRESHOLD ? value * 10 : RemoteServiceStatus.FAILURE.getRemoteServiceStatusValue();
7878
}
7979
}

ambassador/src/main/java/com/iluwatar/ambassador/RemoteServiceInterface.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
* Interface shared by ({@link RemoteService}) and ({@link ServiceAmbassador}).
2828
*/
2929
interface RemoteServiceInterface {
30-
int FAILURE = -1;
3130

3231
long doRemoteFunction(int value);
3332
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.iluwatar.ambassador;
2+
3+
/**
4+
* Holds information regarding the status of the Remote Service.
5+
*
6+
* !Attention - This Enum replaces the integer value previously stored in {@link RemoteServiceInterface}
7+
* as SonarCloud was identifying it as an issue. All test cases have been checked after changes, without failures.
8+
*/
9+
10+
public enum RemoteServiceStatus {
11+
FAILURE(-1)
12+
;
13+
14+
private final long remoteServiceStatusValue;
15+
16+
RemoteServiceStatus(long remoteServiceStatusValue) {
17+
this.remoteServiceStatusValue = remoteServiceStatusValue;
18+
}
19+
20+
public long getRemoteServiceStatusValue() {
21+
return remoteServiceStatusValue;
22+
}
23+
}

ambassador/src/main/java/com/iluwatar/ambassador/ServiceAmbassador.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
package com.iluwatar.ambassador;
2525

26+
import static com.iluwatar.ambassador.RemoteServiceStatus.FAILURE;
2627
import static java.lang.Thread.sleep;
2728

2829
import org.slf4j.Logger;
@@ -58,14 +59,14 @@ private long checkLatency(int value) {
5859

5960
private long safeCall(int value) {
6061
var retries = 0;
61-
var result = (long) FAILURE;
62+
var result = FAILURE.getRemoteServiceStatusValue();
6263

6364
for (int i = 0; i < RETRIES; i++) {
6465
if (retries >= RETRIES) {
65-
return FAILURE;
66+
return FAILURE.getRemoteServiceStatusValue();
6667
}
6768

68-
if ((result = checkLatency(value)) == FAILURE) {
69+
if ((result = checkLatency(value)) == FAILURE.getRemoteServiceStatusValue()) {
6970
LOGGER.info("Failed to reach remote: (" + (i + 1) + ")");
7071
retries++;
7172
try {

ambassador/src/test/java/com/iluwatar/ambassador/AppTest.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,23 @@
2525

2626
import org.junit.jupiter.api.Test;
2727

28+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
29+
2830
/**
2931
* Application test
3032
*/
3133
class AppTest {
3234

35+
/**
36+
* Issue: Add at least one assertion to this test case.
37+
*
38+
* Solution: Inserted assertion to check whether the execution of the main method in {@link App}
39+
* throws an exception.
40+
*/
41+
3342
@Test
34-
void test() {
35-
App.main(new String[]{});
43+
void shouldExecuteApplicationWithoutException() {
44+
45+
assertDoesNotThrow(() -> App.main(new String[]{}));
3646
}
3747
}

ambassador/src/test/java/com/iluwatar/ambassador/ClientTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@ void test() {
3737
Client client = new Client();
3838
var result = client.useService(10);
3939

40-
assertTrue(result == 100 || result == RemoteService.FAILURE);
40+
assertTrue(result == 100 || result == RemoteServiceStatus.FAILURE.getRemoteServiceStatusValue());
4141
}
4242
}

ambassador/src/test/java/com/iluwatar/ambassador/RemoteServiceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class RemoteServiceTest {
3737
void testFailedCall() {
3838
var remoteService = new RemoteService(new StaticRandomProvider(0.21));
3939
var result = remoteService.doRemoteFunction(10);
40-
assertEquals(RemoteServiceInterface.FAILURE, result);
40+
assertEquals(RemoteServiceStatus.FAILURE.getRemoteServiceStatusValue(), result);
4141
}
4242

4343
@Test

ambassador/src/test/java/com/iluwatar/ambassador/ServiceAmbassadorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ class ServiceAmbassadorTest {
3535
@Test
3636
void test() {
3737
long result = new ServiceAmbassador().doRemoteFunction(10);
38-
assertTrue(result == 100 || result == RemoteServiceInterface.FAILURE);
38+
assertTrue(result == 100 || result == RemoteServiceStatus.FAILURE.getRemoteServiceStatusValue());
3939
}
4040
}

async-method-invocation/src/test/java/com/iluwatar/async/method/invocation/AppTest.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,24 @@
2525

2626
import org.junit.jupiter.api.Test;
2727

28+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
29+
2830
/**
2931
* Application test
3032
*/
3133
class AppTest {
34+
35+
/**
36+
* Issue: Add at least one assertion to this test case.
37+
*
38+
* Solution: Inserted assertion to check whether the execution of the main method in {@link App}
39+
* throws an exception.
40+
*/
41+
3242
@Test
33-
void test() throws Exception {
34-
App.main(new String[]{});
43+
void shouldExecuteApplicationWithoutException() {
44+
45+
assertDoesNotThrow(() -> App.main(new String[]{}));
46+
3547
}
3648
}

balking/src/test/java/com/iluwatar/balking/AppTest.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,26 @@
2424
package com.iluwatar.balking;
2525

2626
import org.junit.jupiter.api.Test;
27+
import org.junit.jupiter.api.function.Executable;
28+
29+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
30+
2731

2832
/**
2933
* Application test
3034
*/
3135
class AppTest {
3236

37+
/**
38+
* Issue: Add at least one assertion to this test case.
39+
*
40+
* Solution: Inserted assertion to check whether the execution of the main method in {@link App}
41+
* throws an exception.
42+
*/
43+
3344
@Test
34-
void main() {
35-
App.main();
45+
void shouldExecuteApplicationWithoutException() {
46+
assertDoesNotThrow((Executable) App::main);
3647
}
3748

3849
}

bridge/src/test/java/com/iluwatar/bridge/AppTest.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,22 @@
2525

2626
import org.junit.jupiter.api.Test;
2727

28+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
29+
2830
/**
2931
* Application test
3032
*/
3133
class AppTest {
34+
35+
/**
36+
* Issue: Add at least one assertion to this test case.
37+
*
38+
* Solution: Inserted assertion to check whether the execution of the main method in {@link App}
39+
* throws an exception.
40+
*/
41+
3242
@Test
33-
void test() {
34-
App.main(new String[]{});
43+
void shouldExecuteApplicationWithoutException() {
44+
assertDoesNotThrow(() -> App.main(new String[]{}));
3545
}
3646
}

builder/src/test/java/com/iluwatar/builder/AppTest.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,23 @@
2525

2626
import org.junit.jupiter.api.Test;
2727

28+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
29+
2830
/**
2931
* Application test
3032
*/
3133
class AppTest {
34+
35+
/**
36+
* Issue: Add at least one assertion to this test case.
37+
*
38+
* Solution: Inserted assertion to check whether the execution of the main method in {@link App}
39+
* throws an exception.
40+
*/
41+
3242
@Test
33-
void test() {
34-
App.main(new String[]{});
43+
void shouldExecuteApplicationWithoutException() {
44+
45+
assertDoesNotThrow(() -> App.main(new String[]{}));
3546
}
3647
}

business-delegate/src/test/java/com/iluwatar/business/delegate/AppTest.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,23 @@
2727

2828
import java.io.IOException;
2929

30+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
31+
3032
/**
3133
* Tests that Business Delegate example runs without errors.
3234
*/
33-
public class AppTest {
35+
class AppTest {
36+
37+
/**
38+
* Issue: Add at least one assertion to this test case.
39+
*
40+
* Solution: Inserted assertion to check whether the execution of the main method in {@link App}
41+
* throws an exception.
42+
*/
43+
3444
@Test
35-
public void test() throws IOException {
36-
String[] args = {};
37-
App.main(args);
45+
void shouldExecuteApplicationWithoutException() {
46+
47+
assertDoesNotThrow(() -> App.main(new String[]{}));
3848
}
3949
}

bytecode/src/main/java/com/iluwatar/bytecode/App.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,14 @@ public static void main(String[] args) {
5858
var vm = new VirtualMachine();
5959
vm.getWizards()[0] = wizard;
6060

61-
interpretInstruction("LITERAL 0", vm);
62-
interpretInstruction("LITERAL 0", vm);
61+
String literal = "LITERAL 0";
62+
63+
interpretInstruction(literal, vm);
64+
interpretInstruction(literal, vm);
6365
interpretInstruction("GET_HEALTH", vm);
64-
interpretInstruction("LITERAL 0", vm);
66+
interpretInstruction(literal, vm);
6567
interpretInstruction("GET_AGILITY", vm);
66-
interpretInstruction("LITERAL 0", vm);
68+
interpretInstruction(literal, vm);
6769
interpretInstruction("GET_WISDOM ", vm);
6870
interpretInstruction("ADD", vm);
6971
interpretInstruction("LITERAL 2", vm);

0 commit comments

Comments
 (0)