Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/nl/garvelink/iban/IBAN.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public static IBAN compose(CharSequence countryCode, CharSequence bban) {
StringBuilder sb =
new StringBuilder(CountryCodes.LONGEST_IBAN_LENGTH).append(countryCode).append("00").append(bban);
int checkDigits = Modulo97.calculateCheckDigits(sb);
sb.replace(2, 4, Integer.toString(checkDigits));
sb.replace(2, 4, String.format("%02d", checkDigits));
return parse(sb);
}

Expand Down
8 changes: 4 additions & 4 deletions src/test/java/nl/garvelink/iban/IBANTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
* Miscellaneous tests for the {@link IBAN} class.
*/
public class IBANTest {
private static final String VALID_IBAN = "NL91ABNA0417164300";
private static final String INVALID_IBAN = "NL12ABNA0417164300";
private static final String VALID_IBAN = "NL03ABNA0143267469";
private static final String INVALID_IBAN = "NL13ABNA0143267469";

@Test
public void getCountryCodeShouldReturnTheCountryCode() {
Expand All @@ -48,7 +48,7 @@ public void getCountryCodeShouldReturnTheCountryCode() {

@Test
public void getCheckDigitsShouldReturnTheCheckDigits() {
assertThat(IBAN.parse(VALID_IBAN).getCheckDigits(), is("91"));
assertThat(IBAN.parse(VALID_IBAN).getCheckDigits(), is("03"));
}

@Test
Expand Down Expand Up @@ -200,7 +200,7 @@ public void testSerializationRoundTrip() throws IOException, ClassNotFoundExcept
public void testSerializedFormCompatibility() throws IOException, ClassNotFoundException {
// This was manually sampled from the preceding test. This test is to ensure that the serialised form remains
// stable as the library evolves.
String serializedForm = "rO0ABXNyAB5ubC5nYXJ2ZWxpbmsuaWJhbi5JQkFOJE1lbWVudG8AAAAAAAAAAQwAAHhwdxwAAAAAAAAAAQASTkw5MUFCTkEwNDE3MTY0MzAweA==";
String serializedForm = "rO0ABXNyAB5ubC5nYXJ2ZWxpbmsuaWJhbi5JQkFOJE1lbWVudG8AAAAAAAAAAQwAAHhwdxwAAAAAAAAAAQASTkwwM0FCTkEwMTQzMjY3NDY5eA==";
ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(Base64.getDecoder().decode(serializedForm)));
IBAN copy = (IBAN) ois.readObject();
assertThat(copy.toPlainString(), is(equalTo(VALID_IBAN)));
Expand Down