Skip to content

Commit

Permalink
Deprecate NationalIdFactory.getNationalId(...) in favor of NationalId…
Browse files Browse the repository at this point in the history
…Factory.newInstance(...)
  • Loading branch information
afbernardino committed Jul 18, 2021
1 parent 75662a4 commit faaea2b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/github/reducktion/socrates/Socrates.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class Socrates {
* @throws UnsupportedOperationException if the country is not supported
*/
public boolean validateId(final String id, final Country country) {
final NationalId nationalId = NationalIdFactory.getNationalId(id, country);
final NationalId nationalId = NationalIdFactory.newInstance(id, country);
return nationalId.isValid();
}

Expand All @@ -35,7 +35,7 @@ public boolean validateId(final String id, final Country country) {
* @throws UnsupportedOperationException if the country is not supported
*/
public Optional<Citizen> extractCitizenFromId(final String id, final Country country) {
final NationalId nationalId = NationalIdFactory.getNationalId(id, country);
final NationalId nationalId = NationalIdFactory.newInstance(id, country);
return nationalId.extractCitizen();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,28 @@ private NationalIdFactory() {}
/**
* Returns a new instance of {@link NationalId}, that is specific for the country parameter.
*
* @deprecated use {@link #newInstance(String, Country)} instead
*
* @param id the national id
* @param country the {@link Country}
* @return a new instance of {@link NationalId}
* @throws UnsupportedOperationException if the country is not supported
*
*/
@Deprecated
public static NationalId getNationalId(final String id, final Country country) {
return newInstance(id, country);
}

/**
* Returns a new instance of {@link NationalId}, that is specific for the country parameter.
*
* @param id the national id
* @param country the {@link Country}
* @return a new instance of {@link NationalId}
* @throws UnsupportedOperationException if the country is not supported
*/
public static NationalId newInstance(final String id, final Country country) {
switch (country) {
case BE: return new BelgiumNationalId(id);
case BR: return new BrazilNationalId(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class NationalIdFactoryTest {

@ParameterizedTest(name = "#{index} - Test with Argument={0},{1}")
@MethodSource("nationalIdForCountryProvider")
void getNationalId_shouldReturnCorrectInstanceForCountry(final Country country, final Class clazz) {
final NationalId nationalId = NationalIdFactory.getNationalId(null, country);
void newInstance_shouldReturnCorrectInstanceForCountry(final Country country, final Class clazz) {
final NationalId nationalId = NationalIdFactory.newInstance(null, country);

assertThat(nationalId, is(instanceOf(clazz)));
}
Expand Down

0 comments on commit faaea2b

Please sign in to comment.