Skip to content

Commit

Permalink
Removed several Sonarlint warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
robtimus committed Jun 24, 2020
1 parent 0640800 commit d553efa
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/github/robtimus/tryparse/TryParse.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public final class TryParse {
private static final int DEFAULT_RADIX = 10;

private TryParse() {
throw new Error("cannot create instances of " + getClass().getName()); //$NON-NLS-1$
throw new IllegalStateException("cannot create instances of " + getClass().getName()); //$NON-NLS-1$
}

// int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ final class UnsignedMultiplyLongBounds {
}

private UnsignedMultiplyLongBounds() {
throw new Error("cannot create instances of " + getClass().getName()); //$NON-NLS-1$
throw new IllegalStateException("cannot create instances of " + getClass().getName()); //$NON-NLS-1$
}

static long get(int radix) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
import java.util.Optional;
import org.junit.jupiter.api.Test;

@SuppressWarnings({ "javadoc", "nls" })
public class TryParseBooleanTest {
@SuppressWarnings("nls")
class TryParseBooleanTest {

@Test
public void testTryParseBoolean() {
void testTryParseBoolean() {
checkWithAndWithoutSubsequences(true, "true");
checkWithAndWithoutSubsequences(true, "TRUE");
checkWithAndWithoutSubsequences(false, "false");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,43 +49,43 @@
import java.util.OptionalDouble;
import org.junit.jupiter.api.Test;

@SuppressWarnings({ "javadoc", "nls" })
public class TryParseCatchingTest {
@SuppressWarnings("nls")
class TryParseCatchingTest {

@Test
public void testParseDouble() {
void testParseDouble() {
assertEquals(OptionalDouble.empty(), tryParseDouble(null));
assertEquals(OptionalDouble.empty(), tryParseDouble(""));
assertEquals(123.456, tryParseDouble("123.456").getAsDouble(), 0.00001);
assertEquals(OptionalDouble.empty(), tryParseDouble("foo"));
}

@Test
public void testParseURI() {
void testParseURI() {
assertEquals(Optional.empty(), tryParseURI(null));
// an empty URI is valid
assertEquals(Optional.of(URI.create("http://example.org")), tryParseURI("http://example.org"));
assertEquals(Optional.empty(), tryParseURI("http://example.org##"));
}

@Test
public void testParseURL() throws MalformedURLException {
void testParseURL() throws MalformedURLException {
assertEquals(Optional.empty(), tryParseURL(null));
assertEquals(Optional.empty(), tryParseURL(""));
assertEquals(Optional.of(new URL("http://example.org")), tryParseURL("http://example.org"));
assertEquals(Optional.empty(), tryParseURL("foo"));
}

@Test
public void testParseInstant() {
void testParseInstant() {
assertEquals(Optional.empty(), tryParseInstant(null));
assertEquals(Optional.empty(), tryParseInstant(""));
assertEquals(Optional.of(Instant.parse("2007-12-03T10:15:30.00Z")), tryParseInstant("2007-12-03T10:15:30.00Z"));
assertEquals(Optional.empty(), tryParseURL("2007-12-03T10:15:30.00ZX"));
}

@Test
public void testParseLocalDate() {
void testParseLocalDate() {
assertEquals(Optional.empty(), tryParseLocalDate(null));
assertEquals(Optional.empty(), tryParseLocalDate(""));
assertEquals(Optional.of(LocalDate.of(2007, 12, 3)), tryParseLocalDate("2007-12-03"));
Expand All @@ -99,7 +99,7 @@ public void testParseLocalDate() {
}

@Test
public void testParseLocalDateTime() {
void testParseLocalDateTime() {
assertEquals(Optional.empty(), tryParseLocalDateTime(null));
assertEquals(Optional.empty(), tryParseLocalDateTime(""));
assertEquals(Optional.of(LocalDateTime.of(2007, 12, 3, 10, 15, 30)), tryParseLocalDateTime("2007-12-03T10:15:30"));
Expand All @@ -113,7 +113,7 @@ public void testParseLocalDateTime() {
}

@Test
public void testParseLocalTime() {
void testParseLocalTime() {
assertEquals(Optional.empty(), tryParseLocalTime(null));
assertEquals(Optional.empty(), tryParseLocalTime(""));
assertEquals(Optional.of(LocalTime.of(10, 15, 30)), tryParseLocalTime("10:15:30"));
Expand All @@ -127,7 +127,7 @@ public void testParseLocalTime() {
}

@Test
public void testParseOffsetDateTime() {
void testParseOffsetDateTime() {
assertEquals(Optional.empty(), tryParseOffsetDateTime(null));
assertEquals(Optional.empty(), tryParseOffsetDateTime(""));
assertEquals(Optional.of(OffsetDateTime.of(2007, 12, 3, 10, 15, 30, 0, ZoneOffset.ofHours(1))),
Expand All @@ -143,7 +143,7 @@ public void testParseOffsetDateTime() {
}

@Test
public void testParseOffsetTime() {
void testParseOffsetTime() {
assertEquals(Optional.empty(), tryParseOffsetTime(null));
assertEquals(Optional.empty(), tryParseOffsetTime(""));
assertEquals(Optional.of(OffsetTime.of(10, 15, 30, 0, ZoneOffset.ofHours(1))), tryParseOffsetTime("10:15:30+01:00"));
Expand All @@ -157,7 +157,7 @@ public void testParseOffsetTime() {
}

@Test
public void testParseZonedDateTime() {
void testParseZonedDateTime() {
assertEquals(Optional.empty(), tryParseZonedDateTime(null));
assertEquals(Optional.empty(), tryParseZonedDateTime(""));
assertEquals(Optional.of(ZonedDateTime.of(2007, 12, 3, 10, 15, 30, 0, ZoneId.of("Europe/Paris"))),
Expand All @@ -173,7 +173,7 @@ public void testParseZonedDateTime() {
}

@Test
public void testParseTemporal() {
void testParseTemporal() {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");
assertEquals(Optional.empty(), tryParseTemporal(null, formatter, LocalDate::from));
assertEquals(Optional.empty(), tryParseTemporal("", formatter, LocalDate::from));
Expand All @@ -182,7 +182,7 @@ public void testParseTemporal() {
}

@Test
public void testParse() {
void testParse() {
assertEquals(Optional.empty(), tryParse(null, o -> o));
assertEquals(Optional.of(""), tryParse("", o -> o));
assertEquals(Optional.of("foo"), tryParse("foo", o -> o));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
import java.util.OptionalInt;
import org.junit.jupiter.api.Test;

@SuppressWarnings({ "javadoc", "nls" })
public class TryParseIntTest {
@SuppressWarnings("nls")
class TryParseIntTest {

@Test
public void testTryParseInt() {
void testTryParseInt() {
checkNegativeNumber(-128);
for (int i = -32; i < 0; i++) {
checkNegativeNumber(i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
import java.util.OptionalLong;
import org.junit.jupiter.api.Test;

@SuppressWarnings({ "javadoc", "nls" })
public class TryParseLongTest {
@SuppressWarnings("nls")
class TryParseLongTest {

@Test
public void testTryParseLong() {
void testTryParseLong() {
checkNegativeNumber(-128);
for (long i = -32; i < 0; i++) {
checkNegativeNumber(i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
import java.util.OptionalInt;
import org.junit.jupiter.api.Test;

@SuppressWarnings({ "javadoc", "nls" })
public class TryParseUnsignedIntTest {
@SuppressWarnings("nls")
class TryParseUnsignedIntTest {

private static final long MAX_UNSIGNED_INT_VALUE = 0xFFFF_FFFFL;

@Test
public void testTryParseUnsignedInt() {
void testTryParseUnsignedInt() {
checkNegativeNumber(-128);
for (int i = -32; i < 0; i++) {
checkNegativeNumber(i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
import java.util.OptionalLong;
import org.junit.jupiter.api.Test;

@SuppressWarnings({ "javadoc", "nls" })
public class TryParseUnsignedLongTest {
@SuppressWarnings("nls")
class TryParseUnsignedLongTest {

private static final BigInteger MAX_UNSIGNED_LONG_VALUE = BigInteger.valueOf(2).pow(64).subtract(BigInteger.ONE);

@Test
public void testTryParseUnsignedLong() {
void testTryParseUnsignedLong() {
checkNegativeNumber(-128);
for (long i = -32; i < 0; i++) {
checkNegativeNumber(i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,20 @@
import java.math.BigInteger;
import org.junit.jupiter.api.Test;

@SuppressWarnings("javadoc")
public class UnsignedMultiplyLongBoundsTest {
class UnsignedMultiplyLongBoundsTest {

private static final BigInteger MAX_UNSIGNED_LONG_VALUE = BigInteger.valueOf(2).pow(64).subtract(BigInteger.ONE);

@Test
public void testGet() {
void testGet() {
for (int radix = Character.MIN_RADIX; radix <= Character.MAX_RADIX; radix++) {
long expected = MAX_UNSIGNED_LONG_VALUE.divide(BigInteger.valueOf(radix)).longValueExact();
assertEquals(expected, UnsignedMultiplyLongBounds.get(radix));
}
}

@Test
public void testGetRadixToHigh() {
void testGetRadixToHigh() {
assertThrows(IndexOutOfBoundsException.class, () -> UnsignedMultiplyLongBounds.get(Character.MAX_RADIX + 1));
}
}

0 comments on commit d553efa

Please sign in to comment.