mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-17 22:59:43 +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:
+16
-8
@@ -29,7 +29,9 @@ import org.junit.jupiter.api.Test;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CalculatorViewModelTest {
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class CalculatorViewModelTest {
|
||||
|
||||
private CalculatorModel modelAfterExecutingActions(List<CalculatorAction> actions) {
|
||||
CalculatorViewModel viewModel = new CalculatorViewModel();
|
||||
@@ -42,7 +44,8 @@ public class CalculatorViewModelTest {
|
||||
@Test
|
||||
void testSetup() {
|
||||
CalculatorModel model = modelAfterExecutingActions(new ArrayList<>());
|
||||
assert model.getVariable() == 0 && model.getOutput() == 0;
|
||||
assertEquals(0, model.getVariable());
|
||||
assertEquals(0, model.getOutput());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -51,7 +54,8 @@ public class CalculatorViewModelTest {
|
||||
new SetVariableCalculatorAction(10.0)
|
||||
);
|
||||
CalculatorModel model = modelAfterExecutingActions(actions);
|
||||
assert model.getVariable() == 10.0 && model.getOutput() == 0;
|
||||
assertEquals(10.0, model.getVariable());
|
||||
assertEquals(0, model.getOutput());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -64,7 +68,8 @@ public class CalculatorViewModelTest {
|
||||
new AdditionCalculatorAction()
|
||||
);
|
||||
CalculatorModel model = modelAfterExecutingActions(actions);
|
||||
assert model.getVariable() == 7.0 && model.getOutput() == 11.0;
|
||||
assertEquals(7.0, model.getVariable());
|
||||
assertEquals(11.0, model.getOutput());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -76,7 +81,8 @@ public class CalculatorViewModelTest {
|
||||
new SubtractionCalculatorAction()
|
||||
);
|
||||
CalculatorModel model = modelAfterExecutingActions(actions);
|
||||
assert model.getVariable() == 2.0 && model.getOutput() == 2.0;
|
||||
assertEquals(2.0, model.getVariable());
|
||||
assertEquals(2.0, model.getOutput());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -88,7 +94,8 @@ public class CalculatorViewModelTest {
|
||||
new MultiplicationCalculatorAction()
|
||||
);
|
||||
CalculatorModel model = modelAfterExecutingActions(actions);
|
||||
assert model.getVariable() == 2.0 && model.getOutput() == 8.0;
|
||||
assertEquals(2.0, model.getVariable());
|
||||
assertEquals(8.0, model.getOutput());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -101,6 +108,7 @@ public class CalculatorViewModelTest {
|
||||
new DivisionCalculatorAction()
|
||||
);
|
||||
CalculatorModel model = modelAfterExecutingActions(actions);
|
||||
assert model.getVariable() == 2.0 && model.getOutput() == 2.0;
|
||||
assertEquals(2.0, model.getVariable());
|
||||
assertEquals(2.0, model.getOutput());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user