Skip to content

Commit

Permalink
Fixed most reported issues by SonarCloud.
Browse files Browse the repository at this point in the history
  • Loading branch information
Toxic Dreamz authored and Toxic Dreamz committed Aug 15, 2020
1 parent e7e3ace commit 31471ac
Show file tree
Hide file tree
Showing 190 changed files with 1,426 additions and 661 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,23 @@

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;

/**
* Simple App test
*/
public class AppTest {
class AppTest {

/**
* Issue: Add at least one assertion to this test case.
*
* Solution: Inserted assertion to check whether the execution of the main method in {@link App}
* throws an exception.
*/

@Test
public void shouldExecuteAppWithoutException() {
App.main(null);
void shouldExecuteAppWithoutException() {
assertDoesNotThrow(() -> App.main(null));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,23 @@

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;

/**
* Tests that Abstract Factory example runs without errors.
*/
public class AppTest {
class AppTest {

/**
* Issue: Add at least one assertion to this test case.
*
* Solution: Inserted assertion to check whether the execution of the main method in {@link App}
* throws an exception.
*/

@Test
public void test() {
App.main(new String[]{});
void shouldExecuteApplicationWithoutException() {

assertDoesNotThrow(() -> App.main(new String[]{}));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,23 @@

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;

/**
* Tests that the Acyclic Visitor example runs without errors.
*/
public class AppTest {
class AppTest {

/**
* Issue: Add at least one assertion to this test case.
*
* Solution: Inserted assertion to check whether the execution of the main method in {@link App}
* throws an exception.
*/

@Test
public void test() {
App.main(new String[]{});
void shouldExecuteApplicationWithoutException() {

assertDoesNotThrow(() -> App.main(new String[]{}));
}
}
17 changes: 14 additions & 3 deletions adapter/src/test/java/com/iluwatar/adapter/AppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,23 @@

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;

/**
* Tests that Adapter example runs without errors.
*/
public class AppTest {
class AppTest {

/**
* Issue: Add at least one assertion to this test case.
*
* Solution: Inserted assertion to check whether the execution of the main method in {@link App}
* throws an exception.
*/

@Test
public void test() {
App.main(new String[]{});
void shouldExecuteApplicationWithoutException() {

assertDoesNotThrow(() -> App.main(new String[]{}));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private RemoteService() {
*
* @param value integer value to be multiplied.
* @return if waitTime is less than {@link RemoteService#THRESHOLD}, it returns value * 10,
* otherwise {@link RemoteServiceInterface#FAILURE}.
* otherwise {@link RemoteServiceStatus#FAILURE}.
*/
@Override
public long doRemoteFunction(int value) {
Expand All @@ -74,6 +74,6 @@ public long doRemoteFunction(int value) {
} catch (InterruptedException e) {
LOGGER.error("Thread sleep state interrupted", e);
}
return waitTime <= THRESHOLD ? value * 10 : FAILURE;
return waitTime <= THRESHOLD ? value * 10 : RemoteServiceStatus.FAILURE.getRemoteServiceStatusValue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
* Interface shared by ({@link RemoteService}) and ({@link ServiceAmbassador}).
*/
interface RemoteServiceInterface {
int FAILURE = -1;

long doRemoteFunction(int value);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.iluwatar.ambassador;

/**
* Holds information regarding the status of the Remote Service.
*
* !Attention - This Enum replaces the integer value previously stored in {@link RemoteServiceInterface}
* as SonarCloud was identifying it as an issue. All test cases have been checked after changes, without failures.
*/

public enum RemoteServiceStatus {
FAILURE(-1)
;

private final long remoteServiceStatusValue;

RemoteServiceStatus(long remoteServiceStatusValue) {
this.remoteServiceStatusValue = remoteServiceStatusValue;
}

public long getRemoteServiceStatusValue() {
return remoteServiceStatusValue;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

package com.iluwatar.ambassador;

import static com.iluwatar.ambassador.RemoteServiceStatus.FAILURE;
import static java.lang.Thread.sleep;

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

private long safeCall(int value) {
var retries = 0;
var result = (long) FAILURE;
var result = FAILURE.getRemoteServiceStatusValue();

for (int i = 0; i < RETRIES; i++) {
if (retries >= RETRIES) {
return FAILURE;
return FAILURE.getRemoteServiceStatusValue();
}

if ((result = checkLatency(value)) == FAILURE) {
if ((result = checkLatency(value)) == FAILURE.getRemoteServiceStatusValue()) {
LOGGER.info("Failed to reach remote: (" + (i + 1) + ")");
retries++;
try {
Expand Down
14 changes: 12 additions & 2 deletions ambassador/src/test/java/com/iluwatar/ambassador/AppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,23 @@

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;

/**
* Application test
*/
class AppTest {

/**
* Issue: Add at least one assertion to this test case.
*
* Solution: Inserted assertion to check whether the execution of the main method in {@link App}
* throws an exception.
*/

@Test
void test() {
App.main(new String[]{});
void shouldExecuteApplicationWithoutException() {

assertDoesNotThrow(() -> App.main(new String[]{}));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ void test() {
Client client = new Client();
var result = client.useService(10);

assertTrue(result == 100 || result == RemoteService.FAILURE);
assertTrue(result == 100 || result == RemoteServiceStatus.FAILURE.getRemoteServiceStatusValue());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class RemoteServiceTest {
void testFailedCall() {
var remoteService = new RemoteService(new StaticRandomProvider(0.21));
var result = remoteService.doRemoteFunction(10);
assertEquals(RemoteServiceInterface.FAILURE, result);
assertEquals(RemoteServiceStatus.FAILURE.getRemoteServiceStatusValue(), result);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ class ServiceAmbassadorTest {
@Test
void test() {
long result = new ServiceAmbassador().doRemoteFunction(10);
assertTrue(result == 100 || result == RemoteServiceInterface.FAILURE);
assertTrue(result == 100 || result == RemoteServiceStatus.FAILURE.getRemoteServiceStatusValue());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,24 @@

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;

/**
* Application test
*/
class AppTest {

/**
* Issue: Add at least one assertion to this test case.
*
* Solution: Inserted assertion to check whether the execution of the main method in {@link App}
* throws an exception.
*/

@Test
void test() throws Exception {
App.main(new String[]{});
void shouldExecuteApplicationWithoutException() {

assertDoesNotThrow(() -> App.main(new String[]{}));

}
}
15 changes: 13 additions & 2 deletions balking/src/test/java/com/iluwatar/balking/AppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,26 @@
package com.iluwatar.balking;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;


/**
* Application test
*/
class AppTest {

/**
* Issue: Add at least one assertion to this test case.
*
* Solution: Inserted assertion to check whether the execution of the main method in {@link App}
* throws an exception.
*/

@Test
void main() {
App.main();
void shouldExecuteApplicationWithoutException() {
assertDoesNotThrow((Executable) App::main);
}

}
14 changes: 12 additions & 2 deletions bridge/src/test/java/com/iluwatar/bridge/AppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,22 @@

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;

/**
* Application test
*/
class AppTest {

/**
* Issue: Add at least one assertion to this test case.
*
* Solution: Inserted assertion to check whether the execution of the main method in {@link App}
* throws an exception.
*/

@Test
void test() {
App.main(new String[]{});
void shouldExecuteApplicationWithoutException() {
assertDoesNotThrow(() -> App.main(new String[]{}));
}
}
15 changes: 13 additions & 2 deletions builder/src/test/java/com/iluwatar/builder/AppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,23 @@

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;

/**
* Application test
*/
class AppTest {

/**
* Issue: Add at least one assertion to this test case.
*
* Solution: Inserted assertion to check whether the execution of the main method in {@link App}
* throws an exception.
*/

@Test
void test() {
App.main(new String[]{});
void shouldExecuteApplicationWithoutException() {

assertDoesNotThrow(() -> App.main(new String[]{}));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,23 @@

import java.io.IOException;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;

/**
* Tests that Business Delegate example runs without errors.
*/
public class AppTest {
class AppTest {

/**
* Issue: Add at least one assertion to this test case.
*
* Solution: Inserted assertion to check whether the execution of the main method in {@link App}
* throws an exception.
*/

@Test
public void test() throws IOException {
String[] args = {};
App.main(args);
void shouldExecuteApplicationWithoutException() {

assertDoesNotThrow(() -> App.main(new String[]{}));
}
}
10 changes: 6 additions & 4 deletions bytecode/src/main/java/com/iluwatar/bytecode/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,14 @@ public static void main(String[] args) {
var vm = new VirtualMachine();
vm.getWizards()[0] = wizard;

interpretInstruction("LITERAL 0", vm);
interpretInstruction("LITERAL 0", vm);
String literal = "LITERAL 0";

interpretInstruction(literal, vm);
interpretInstruction(literal, vm);
interpretInstruction("GET_HEALTH", vm);
interpretInstruction("LITERAL 0", vm);
interpretInstruction(literal, vm);
interpretInstruction("GET_AGILITY", vm);
interpretInstruction("LITERAL 0", vm);
interpretInstruction(literal, vm);
interpretInstruction("GET_WISDOM ", vm);
interpretInstruction("ADD", vm);
interpretInstruction("LITERAL 2", vm);
Expand Down
Loading

0 comments on commit 31471ac

Please sign in to comment.