mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-16 06:58:54 +00:00
fix: Fix sonar issues (#2925)
* Remove unused member which was also causing a false positive sonar issue. Fixes sonar issue https://sonarcloud.io/project/issues?open=AY3gHwu5DIZTZkppqVEG&id=iluwatar_java-design-patterns * Fixes sonar issue https://sonarcloud.io/project/issues?open=AXK0OzDA-CiGJS70dLki&id=iluwatar_java-design-patterns related to "Refactor the code of the lambda to not have multiple invocations throwing the same checked exception." Also, updated the code to use Instant and Duration to deal with time instead of int. Added the awaitility library to perform assertions in test which is more reliable than using Thread.sleep directly to wait for events to happen. * checkstyle fix * Add sneaky throws to fix sonar lint issue. This is fine as the newFile method is not being tested but instead the new SimpleFileWriter(...) is. * The first booking needs to happen outside the assertions. Fixed other warnings * Use records to pass around related objects instead of using a large number of individual params, which sonar did not like. * Checkstyle fixes * checkstyle fixes * Remove complexity to keep sonar happy. * Split into different methods to reduce complexity. Could be broken down even further but currently Sonar is happy. * Move files to correct package * Add valid assertions to tests * rename constants to avoid confusion * Sonar warning related to cognitive complexity can be suppressed as the methods are quite generic and not functional enough to be separated out. * Use constants to keep Sonar happy * Use correct constant naming conventions * Use correct constant naming conventions * Use lombok to define noargsconstructor * Use a single method to do the logging * Remove unused constructor and redundant method * Use a reusable method for logging
This commit is contained in:
+7
-8
@@ -50,17 +50,16 @@ public final class CalculatorViewModel {
|
||||
*/
|
||||
void handleAction(final CalculatorAction action) {
|
||||
switch (action.tag()) {
|
||||
case AdditionCalculatorAction.TAG -> add();
|
||||
case SubtractionCalculatorAction.TAG -> subtract();
|
||||
case MultiplicationCalculatorAction.TAG -> multiply();
|
||||
case DivisionCalculatorAction.TAG -> divide();
|
||||
case SetVariableCalculatorAction.TAG -> {
|
||||
case AdditionCalculatorAction.ADDITION -> add();
|
||||
case SubtractionCalculatorAction.SUBTRACTION -> subtract();
|
||||
case MultiplicationCalculatorAction.MULTIPLICATION -> multiply();
|
||||
case DivisionCalculatorAction.DIVISION -> divide();
|
||||
case SetVariableCalculatorAction.SET_VARIABLE -> {
|
||||
SetVariableCalculatorAction setVariableAction =
|
||||
(SetVariableCalculatorAction) action;
|
||||
setVariable(setVariableAction.getVariable());
|
||||
}
|
||||
default -> {
|
||||
}
|
||||
default -> throw new IllegalArgumentException("Unknown tag");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,4 +123,4 @@ public final class CalculatorViewModel {
|
||||
model.getOutput() / model.getVariable()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -31,13 +31,13 @@ public class AdditionCalculatorAction implements CalculatorAction {
|
||||
/**
|
||||
* Subclass tag.
|
||||
* */
|
||||
public static final String TAG = "ADDITION";
|
||||
public static final String ADDITION = "ADDITION";
|
||||
|
||||
/**
|
||||
* Makes checking subclass type trivial.
|
||||
* */
|
||||
@Override
|
||||
public String tag() {
|
||||
return TAG;
|
||||
return ADDITION;
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -31,13 +31,13 @@ public class DivisionCalculatorAction implements CalculatorAction {
|
||||
/**
|
||||
* Subclass tag.
|
||||
* */
|
||||
public static final String TAG = "DIVISION";
|
||||
public static final String DIVISION = "DIVISION";
|
||||
|
||||
/**
|
||||
* Makes checking subclass type trivial.
|
||||
* */
|
||||
@Override
|
||||
public String tag() {
|
||||
return TAG;
|
||||
return DIVISION;
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -31,13 +31,13 @@ public class MultiplicationCalculatorAction implements CalculatorAction {
|
||||
/**
|
||||
* Subclass tag.
|
||||
* */
|
||||
public static final String TAG = "MULTIPLICATION";
|
||||
public static final String MULTIPLICATION = "MULTIPLICATION";
|
||||
|
||||
/**
|
||||
* Makes checking subclass type trivial.
|
||||
* */
|
||||
@Override
|
||||
public String tag() {
|
||||
return TAG;
|
||||
return MULTIPLICATION;
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -36,7 +36,7 @@ public final class SetVariableCalculatorAction implements CalculatorAction {
|
||||
/**
|
||||
* Subclass tag.
|
||||
*/
|
||||
public static final String TAG = "SET_VARIABLE";
|
||||
public static final String SET_VARIABLE = "SET_VARIABLE";
|
||||
|
||||
/**
|
||||
* Used by {@link com.iluwatar.model.view.intent.CalculatorViewModel}.
|
||||
@@ -49,6 +49,6 @@ public final class SetVariableCalculatorAction implements CalculatorAction {
|
||||
*/
|
||||
@Override
|
||||
public String tag() {
|
||||
return TAG;
|
||||
return SET_VARIABLE;
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -31,13 +31,13 @@ public class SubtractionCalculatorAction implements CalculatorAction {
|
||||
/**
|
||||
* Subclass tag.
|
||||
* */
|
||||
public static final String TAG = "SUBTRACTION";
|
||||
public static final String SUBTRACTION = "SUBTRACTION";
|
||||
|
||||
/**
|
||||
* Makes checking subclass type trivial.
|
||||
* */
|
||||
@Override
|
||||
public String tag() {
|
||||
return TAG;
|
||||
return SUBTRACTION;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user