Fixed most reported issues by SonarCloud.

This commit is contained in:
Toxic Dreamz
2020-08-15 21:47:39 +04:00
parent e7e3ace01f
commit 31471acb69
190 changed files with 1426 additions and 661 deletions

View File

@ -38,6 +38,9 @@ import java.util.Map;
*/
public final class RainbowFishSerializer {
public static final String LENGTH_METERS = "lengthMeters";
public static final String WEIGHT_TONS = "weightTons";
private RainbowFishSerializer() {
}
@ -48,8 +51,8 @@ public final class RainbowFishSerializer {
var map = Map.of(
"name", rainbowFish.getName(),
"age", String.format("%d", rainbowFish.getAge()),
"lengthMeters", String.format("%d", rainbowFish.getLengthMeters()),
"weightTons", String.format("%d", rainbowFish.getWeightTons())
LENGTH_METERS, String.format("%d", rainbowFish.getLengthMeters()),
WEIGHT_TONS, String.format("%d", rainbowFish.getWeightTons())
);
try (var fileOut = new FileOutputStream(filename);
@ -65,8 +68,8 @@ public final class RainbowFishSerializer {
var map = Map.of(
"name", rainbowFish.getName(),
"age", String.format("%d", rainbowFish.getAge()),
"lengthMeters", String.format("%d", rainbowFish.getLengthMeters()),
"weightTons", String.format("%d", rainbowFish.getWeightTons()),
"lengthMeters", String.format("%d", rainbowFish.getLengthMeters()),
WEIGHT_TONS, String.format("%d", rainbowFish.getWeightTons()),
"angry", Boolean.toString(rainbowFish.getAngry()),
"hungry", Boolean.toString(rainbowFish.getHungry()),
"sleeping", Boolean.toString(rainbowFish.getSleeping())
@ -93,7 +96,7 @@ public final class RainbowFishSerializer {
map.get("name"),
Integer.parseInt(map.get("age")),
Integer.parseInt(map.get("lengthMeters")),
Integer.parseInt(map.get("weightTons"))
Integer.parseInt(map.get(WEIGHT_TONS))
);
}
}

View File

@ -29,19 +29,21 @@ import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
/**
* Application test
*/
public class AppTest {
class AppTest {
@Test
public void test() throws ClassNotFoundException, IOException {
App.main(new String[]{});
void shouldExecuteWithoutException() {
assertDoesNotThrow(() -> App.main(new String[]{}));
}
@BeforeEach
@AfterEach
public void cleanup() {
void cleanup() {
var file1 = new File("fish1.out");
file1.delete();
var file2 = new File("fish2.out");