Skip to content

Commit

Permalink
iluwatar#105 Sonarqube code resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
Shanty97 committed Feb 11, 2024
1 parent 79037ac commit ed51774
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/main/java/math/DiceThrow.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ public enum DiceSides {

FOUR(4), SIX(6), EIGHT(8), TEN(10), TWELVE(12), TWENTY(20);

private final int diceSides;
private final int diSides;

DiceSides(int diceSides) {
this.diceSides = diceSides;
this.diSides = diceSides;
}

/**
Expand All @@ -52,7 +52,7 @@ public enum DiceSides {
* @return int denoting number of sides of a dice
*/
public int getDiceSides() {
return this.diceSides;
return this.diSides;
}

}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/math/RandomNumber.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
*/
public class RandomNumber {

private static Random random = new Random();

/**
* Return a random number between two given numbers.
*
Expand All @@ -41,8 +43,6 @@ public class RandomNumber {
*/
public static <T extends Number> Number getRandomNumber(T start, T end) {

Random random = new Random();

if ((start instanceof Byte && end instanceof Byte)) {
return (byte) (start.byteValue() + random.nextInt(end.byteValue() - start.byteValue() + 1));
} else if ((start instanceof Byte && end instanceof Byte)
Expand Down
5 changes: 3 additions & 2 deletions src/test/java/math/RandomNumberTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,9 @@ void test_doubleRandomNumber() {
@Test
void test_invalidNumberArguments() {
// Test for Double range
double d1 = Double.valueOf((double) 100.12);
int d2 = Integer.valueOf((int) 200);
assertThrows(IllegalArgumentException.class,
() -> RandomNumber.getRandomNumber(Double.valueOf((double) 100.12),
Integer.valueOf((int) 200)));
() -> RandomNumber.getRandomNumber(d1, d2));
}
}

0 comments on commit ed51774

Please sign in to comment.