Skip to content

Commit 31471ac

Browse files
Toxic DreamzToxic Dreamz
authored andcommitted
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
}

0 commit comments

Comments
 (0)