diff --git a/build.gradle b/build.gradle
index 188e87d..b32d8c2 100644
--- a/build.gradle
+++ b/build.gradle
@@ -13,7 +13,7 @@ jacocoTestReport {
}
group 'io.github.viepovsky'
-version '2.0.0'
+version '2.0.1'
repositories {
mavenCentral()
@@ -39,7 +39,7 @@ publishing {
mavenJava(MavenPublication) {
groupId = 'io.github.viepovsky'
artifactId = 'pesel'
- version = "2.0.0"
+ version = "2.0.1"
from components.java
pom {
diff --git a/src/main/java/io/github/viepovsky/polishutils/pesel/InvalidPeselException.java b/src/main/java/io/github/viepovsky/polishutils/pesel/InvalidPeselException.java
index 9477c73..32f10ec 100644
--- a/src/main/java/io/github/viepovsky/polishutils/pesel/InvalidPeselException.java
+++ b/src/main/java/io/github/viepovsky/polishutils/pesel/InvalidPeselException.java
@@ -1,7 +1,7 @@
package io.github.viepovsky.polishutils.pesel;
/**
- * Checked exception thrown when an invalid PESEL number is encountered.
+ * Unchecked exception thrown when an invalid PESEL number is encountered.
* Is thrown when the PESEL:
*
* - has an invalid length (other than 11)
@@ -10,7 +10,7 @@
*
- has an invalid birth date (e.g. the 32nd of any month)
*
*/
-public class InvalidPeselException extends Exception {
+public class InvalidPeselException extends RuntimeException {
/**
* Constructs a {@code InvalidPeselException} with the specified
* detail message.
diff --git a/src/main/java/io/github/viepovsky/polishutils/pesel/Pesel.java b/src/main/java/io/github/viepovsky/polishutils/pesel/Pesel.java
index 285819e..e02dd77 100644
--- a/src/main/java/io/github/viepovsky/polishutils/pesel/Pesel.java
+++ b/src/main/java/io/github/viepovsky/polishutils/pesel/Pesel.java
@@ -47,7 +47,7 @@ public class Pesel extends PeselNumbers {
* @param pesel the PESEL number
* @throws InvalidPeselException if the given PESEL is invalid
*/
- public Pesel(String pesel) throws InvalidPeselException {
+ public Pesel(String pesel) {
this(new PeselDecoder(), pesel);
}
@@ -59,7 +59,7 @@ public Pesel(String pesel) throws InvalidPeselException {
* @param pesel the PESEL number
* @throws InvalidPeselException if the given PESEL is invalid
*/
- private Pesel(PeselDecoder peselDecoder, String pesel) throws InvalidPeselException {
+ private Pesel(PeselDecoder peselDecoder, String pesel) {
super(pesel);
PeselValidator.assertIsValid(pesel);
this.birthDate = peselDecoder.decodeBirthDate(pesel);
diff --git a/src/main/java/io/github/viepovsky/polishutils/pesel/PeselGenerator.java b/src/main/java/io/github/viepovsky/polishutils/pesel/PeselGenerator.java
index 922da86..977c80a 100644
--- a/src/main/java/io/github/viepovsky/polishutils/pesel/PeselGenerator.java
+++ b/src/main/java/io/github/viepovsky/polishutils/pesel/PeselGenerator.java
@@ -53,11 +53,11 @@ public class PeselGenerator {
/**
* The minimum date range from which a PESEL number will be generated.
*/
- private LocalDate minDate;
+ private final LocalDate minDate;
/**
* The maximum date range to which a PESEL number will be generated.
*/
- private LocalDate maxDate;
+ private final LocalDate maxDate;
/**
* Creates a new instance of the {@code PeselGenerator} class with the specified {@code PeselGeneratorParams}.
diff --git a/src/main/java/io/github/viepovsky/polishutils/pesel/PeselGeneratorParams.java b/src/main/java/io/github/viepovsky/polishutils/pesel/PeselGeneratorParams.java
index 7ecc681..98e3486 100644
--- a/src/main/java/io/github/viepovsky/polishutils/pesel/PeselGeneratorParams.java
+++ b/src/main/java/io/github/viepovsky/polishutils/pesel/PeselGeneratorParams.java
@@ -51,7 +51,7 @@ public class PeselGeneratorParams {
/**
* The gender that will be included in the generated PESEL numbers.
*/
- private Gender gender;
+ private final Gender gender;
/**
* The earliest date from which a PESEL number will be generated.
*/
diff --git a/src/main/java/io/github/viepovsky/polishutils/pesel/PeselNumbers.java b/src/main/java/io/github/viepovsky/polishutils/pesel/PeselNumbers.java
index ae249df..758a962 100644
--- a/src/main/java/io/github/viepovsky/polishutils/pesel/PeselNumbers.java
+++ b/src/main/java/io/github/viepovsky/polishutils/pesel/PeselNumbers.java
@@ -39,7 +39,7 @@ class PeselNumbers {
* @param pesel the PESEL number
* @throws InvalidPeselException if the given PESEL is invalid
*/
- PeselNumbers(String pesel) throws InvalidPeselException {
+ PeselNumbers(String pesel) {
PeselValidator.assertIsNotNull(pesel);
PeselValidator.assertIsLengthValid(pesel);
PeselValidator.assertIsOnlyDigits(pesel);
diff --git a/src/main/java/io/github/viepovsky/polishutils/pesel/PeselValidator.java b/src/main/java/io/github/viepovsky/polishutils/pesel/PeselValidator.java
index b6db807..86c251a 100644
--- a/src/main/java/io/github/viepovsky/polishutils/pesel/PeselValidator.java
+++ b/src/main/java/io/github/viepovsky/polishutils/pesel/PeselValidator.java
@@ -48,7 +48,7 @@ public static boolean isValid(String pesel) {
* @param pesel the PESEL number
* @throws InvalidPeselException if the given PESEL is invalid
*/
- public static void assertIsValid(String pesel) throws InvalidPeselException {
+ public static void assertIsValid(String pesel) {
assertIsNotNull(pesel);
assertIsLengthValid(pesel);
assertIsOnlyDigits(pesel);
@@ -74,9 +74,9 @@ static void assertIsNotNull(String pesel) {
* @param pesel the PESEL number
* @throws InvalidPeselException if given PESEL length is other than 11
*/
- static void assertIsLengthValid(String pesel) throws InvalidPeselException {
+ static void assertIsLengthValid(String pesel) {
if (pesel.length() != 11) {
- throw new InvalidPeselException("PESEL length is invalid");
+ throw new InvalidPeselException("PESEL length is invalid, should be 11 numbers");
}
}
@@ -86,9 +86,9 @@ static void assertIsLengthValid(String pesel) throws InvalidPeselException {
* @param pesel the PESEL number
* @throws InvalidPeselException if given PESEL has other characters than digits
*/
- static void assertIsOnlyDigits(String pesel) throws InvalidPeselException {
+ static void assertIsOnlyDigits(String pesel) {
if (!pesel.matches("[0-9]*")) {
- throw new InvalidPeselException("PESEL contains invalid characters");
+ throw new InvalidPeselException("PESEL contains invalid characters, should contain only digits 0-9");
}
}
@@ -98,7 +98,7 @@ static void assertIsOnlyDigits(String pesel) throws InvalidPeselException {
* @param pesel the PESEL number
* @throws InvalidPeselException if given PESEL has invalid control number
*/
- static void assertIsControlDigitValid(String pesel) throws InvalidPeselException {
+ static void assertIsControlDigitValid(String pesel) {
if (!isControlDigitValid(pesel)) {
throw new InvalidPeselException("PESEL control sum number is invalid");
}
@@ -127,7 +127,7 @@ private static boolean isControlDigitValid(String pesel) {
* @param pesel the PESEL number
* @throws InvalidPeselException if the given PESEL date of birth is invalid
*/
- static void assertIsBirthDateValid(String pesel) throws InvalidPeselException {
+ static void assertIsBirthDateValid(String pesel) {
if (!isBirthDateValid(pesel)) {
throw new InvalidPeselException("PESEL birth date is invalid");
}
diff --git a/src/test/java/io/github/viepovsky/polishutils/pesel/PeselGeneratorTest.java b/src/test/java/io/github/viepovsky/polishutils/pesel/PeselGeneratorTest.java
index 0a6c6eb..99b85cd 100644
--- a/src/test/java/io/github/viepovsky/polishutils/pesel/PeselGeneratorTest.java
+++ b/src/test/java/io/github/viepovsky/polishutils/pesel/PeselGeneratorTest.java
@@ -14,7 +14,7 @@
public class PeselGeneratorTest {
@ParameterizedTest
@MethodSource("providePesels")
- void should_generate_pesel_with_given_params(LocalDate minDate, LocalDate maxDate) throws InvalidPeselException {
+ void should_generate_pesel_with_given_params(LocalDate minDate, LocalDate maxDate) {
PeselGeneratorParams.Gender gender = PeselGeneratorParams.Gender.FEMALE;
var params = PeselGeneratorParams.builder()
@@ -45,7 +45,7 @@ private static Stream providePesels() {
}
@RepeatedTest(100)
- void should_generate_only_female_pesel() throws InvalidPeselException {
+ void should_generate_only_female_pesel() {
var params = PeselGeneratorParams.builder()
.gender(PeselGeneratorParams.Gender.FEMALE)
.build();
@@ -60,7 +60,7 @@ void should_generate_only_female_pesel() throws InvalidPeselException {
}
@RepeatedTest(100)
- void should_generate_only_male_pesel() throws InvalidPeselException {
+ void should_generate_only_male_pesel() {
var params = PeselGeneratorParams.builder()
.gender(PeselGeneratorParams.Gender.MALE)
.build();
@@ -75,7 +75,7 @@ void should_generate_only_male_pesel() throws InvalidPeselException {
}
@RepeatedTest(100)
- void should_generate_pesel_with_default_params() throws InvalidPeselException {
+ void should_generate_pesel_with_default_params() {
var params = PeselGeneratorParams.builder().build();
var generator = new PeselGenerator(params);
String generatedPesel = generator.generatePesel();
@@ -114,7 +114,7 @@ void should_swap_min_and_max_date_if_put_in_incorrect_way() {
}
@RepeatedTest(100)
- void should_generate_correct_pesel_if_only_min_param_is_given() throws InvalidPeselException {
+ void should_generate_correct_pesel_if_only_min_param_is_given() {
LocalDate minDate = LocalDate.of(2200, 1, 1);
var params = PeselGeneratorParams.builder()
.minDate(minDate)
@@ -131,7 +131,7 @@ void should_generate_correct_pesel_if_only_min_param_is_given() throws InvalidPe
}
@RepeatedTest(100)
- void should_generate_correct_pesel_if_only_max_param_is_given() throws InvalidPeselException {
+ void should_generate_correct_pesel_if_only_max_param_is_given() {
LocalDate maxDate = LocalDate.of(2200, 1, 1);
var params = PeselGeneratorParams.builder()
.maxDate(maxDate)
@@ -148,7 +148,7 @@ void should_generate_correct_pesel_if_only_max_param_is_given() throws InvalidPe
}
@Test
- void should_generate_pesel_with_given_date() throws InvalidPeselException {
+ void should_generate_pesel_with_given_date() {
LocalDate minDate = LocalDate.of(1955, 11, 22);
LocalDate maxDate = LocalDate.of(1955, 11, 22);
var params = PeselGeneratorParams.builder()
diff --git a/src/test/java/io/github/viepovsky/polishutils/pesel/PeselTest.java b/src/test/java/io/github/viepovsky/polishutils/pesel/PeselTest.java
index 15b4a1c..027c456 100644
--- a/src/test/java/io/github/viepovsky/polishutils/pesel/PeselTest.java
+++ b/src/test/java/io/github/viepovsky/polishutils/pesel/PeselTest.java
@@ -39,7 +39,7 @@ private static Stream provideInvalidPesels() {
@ParameterizedTest
@MethodSource("providePesels")
- void should_return_correct_birth_date(String givenParam, LocalDate expectedDate) throws InvalidPeselException {
+ void should_return_correct_birth_date(String givenParam, LocalDate expectedDate) {
var pesel = new Pesel(givenParam);
assertEquals(expectedDate, pesel.getBirthDate());
}
@@ -70,7 +70,7 @@ private static Stream providePesels() {
"81122018287",
"64031643742"
})
- void should_return_gender_female(String givenPesel) throws InvalidPeselException {
+ void should_return_gender_female(String givenPesel) {
var pesel = new Pesel(givenPesel);
assertEquals(Pesel.Gender.FEMALE.toString(), pesel.getGender());
}
@@ -88,13 +88,13 @@ void should_return_gender_female(String givenPesel) throws InvalidPeselException
"66020829795",
"74040152795"
})
- void should_return_gender_male(String givenPesel) throws InvalidPeselException {
+ void should_return_gender_male(String givenPesel) {
var pesel = new Pesel(givenPesel);
assertEquals(Pesel.Gender.MALE.toString(), pesel.getGender());
}
@Test
- void should_get_correct_pesel_numbers() throws InvalidPeselException {
+ void should_get_correct_pesel_numbers() {
var pesel = new Pesel("74040152795");
int retrievedBirthDate = pesel.getBirthDateNumbers();