Skip to content

Personal Identification Number provider for Norway (NO)#1681

Merged
asolntsev merged 3 commits intomainfrom
norway-personal-identification-number
Sep 27, 2025
Merged

Personal Identification Number provider for Norway (NO)#1681
asolntsev merged 3 commits intomainfrom
norway-personal-identification-number

Conversation

@asolntsev
Copy link
Copy Markdown
Collaborator

@asolntsev asolntsev commented Sep 26, 2025

This PR allows to generate a random national ID number for Norway:

Faker faker = new Faker(new Locale("no", "NO"));
String pin1 = faker.idNumber().valid();
PersonIdNumber pin2 = faker.idNumber().valid(new IdNumberRequest(21, 65, FEMALE));
String pin3 = faker.idNumber().invalid();

@what-the-diff
Copy link
Copy Markdown

what-the-diff bot commented Sep 26, 2025

PR Summary

  • Addition of functionality for Norwegian personal identification numbers
    A new component, called the NorwegianIdNumber class, has been added. This component is tasked with creating ID numbers that are unique and abide by the rules specific to Norwegian personal identification numbers.
  • Inclusion of key constants and methods
    This PR comprises of crucial constants that pertain to date formats and checksum calculations. Along with this, it includes different methods that help generate both valid and invalid ID numbers. These tools play a pivotal role in ensuring the authenticity and validity of the Norwegian ID numbers generated.
  • Adjustments in service configuration
    The service configuration for IdNumberGenerator has been updated to incorporate this newly added NorwegianIdNumber class. This adjustment allows the new class to function seamlessly, as a part of the overall system.
  • Creation of corresponding test class
    The PR includes a new test class named NorwegianIdNumberTest. It tests the functionality of the newly added NorwegianIdNumber generation methods. Tests for both valid and invalid use cases are included, ensuring that the system can handle a wide range of scenarios. Furthermore, checksum verification tests are in place to confirm the accuracy and correctness of the generated ID numbers.

@asolntsev asolntsev force-pushed the norway-personal-identification-number branch from 548510f to 3cce058 Compare September 26, 2025 14:15
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Sep 26, 2025

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 89.47368% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.28%. Comparing base (1081815) to head (5381f17).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...ava/net/datafaker/idnumbers/NorwegianIdNumber.java 89.47% 1 Missing and 3 partials ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #1681      +/-   ##
============================================
- Coverage     92.28%   92.28%   -0.01%     
- Complexity     3393     3410      +17     
============================================
  Files           333      334       +1     
  Lines          6714     6752      +38     
  Branches        666      670       +4     
============================================
+ Hits           6196     6231      +35     
- Misses          354      355       +1     
- Partials        164      166       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@asolntsev asolntsev self-assigned this Sep 26, 2025
@asolntsev asolntsev added the enhancement New feature or request label Sep 26, 2025
@asolntsev asolntsev added this to the 2.5.2 milestone Sep 26, 2025
Copy link
Copy Markdown

@pokebadgerswithspoon pokebadgerswithspoon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dead code, please remove

@asolntsev asolntsev force-pushed the norway-personal-identification-number branch from 3cce058 to 937218f Compare September 26, 2025 15:12
@asolntsev asolntsev force-pushed the norway-personal-identification-number branch from 519052b to 5186174 Compare September 26, 2025 19:30
Comment on lines +71 to +87
* <li>born 1854-1899: allocated from series 749-500</li>
* <li>born 1900-1999: allocated from series 499-000</li>
* <li>born 1940-1999: also allocated from series 999-900</li>
* <li>born 2000-2039: allocated from series 999-500</li>
* </ul>
*
* @see <a href="https://www.oecd.org/content/dam/oecd/en/topics/policy-issue-focus/aeoi/norway-tin.pdf">TIN Structure</a>
*/
private int generateSequenceNumber(BaseProviders faker, int year) {
if (year >= 1854 && year <= 1899) {
return faker.random().nextInt(50, 74);
} else if (year >= 1940 && year <= 1999) {
return faker.random().nextInt(90, 99);
} else if (year >= 1900 && year <= 1999) {
return faker.random().nextInt(0, 49);
} else if (year >= 2000 && year <= 2039) {
return faker.random().nextInt(50, 99);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you elaborate why javadoc and the doc (https://www.oecd.org/content/dam/oecd/en/topics/policy-issue-focus/aeoi/norway-tin.pdf) says

The three digits comprising the individual number are allocated sequentially within the
specific date of birth. Individual digits are allocated as follows

and this method returns 1 or 2 digits?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that it's a bit tricky to track :(
The point is that the third digit depends on the gender.
E.g. for year 1888, we pick a random number between 50 and 74, and append one more digit (the third digit) to it (even for women and odd for men).

@asolntsev asolntsev force-pushed the norway-personal-identification-number branch from 5186174 to 5381f17 Compare September 26, 2025 20:35
Copy link
Copy Markdown

@pokebadgerswithspoon pokebadgerswithspoon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

table of requirements is gone, sad this idea did not work, but handwritten if..else are not that scary in the end.
LTGM and approve if that counts

@asolntsev asolntsev merged commit 9e7a84e into main Sep 27, 2025
13 checks passed
@asolntsev asolntsev deleted the norway-personal-identification-number branch September 27, 2025 07:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants