Skip to content

Commit

Permalink
Write system chars to correct position in record
Browse files Browse the repository at this point in the history
The ISO 2709 record builder wrote individually set system chars to the
wrong position in the record label.

Fixes #284
  • Loading branch information
cboehme committed May 25, 2018
1 parent f96ef28 commit 46dee86
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ void setSystemChars(final char[] systemChars) {

void setSystemChar(final int index, final char value) {
assert 0 <= index && index < SYSTEM_CHARS_LENGTH;
buffer.setWritePosition(SYSTEM_CHARS_LENGTH + index);
buffer.setWritePosition(SYSTEM_CHARS_START + index);
buffer.writeChar(value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,18 @@ public void shouldThrowExceptionIfSystemCharsIsNull() {
builder.setSystemChars(null); // Exception expected
}

@Test
public void shouldWriteSystemCharToRecordLabel() {
builder.setSystemChar(0, 'U');
builder.setSystemChar(1, 'S');
builder.setSystemChar(2, 'C');

final byte[] record = builder.build();

assertEquals(0x55, record[17]);
assertEquals(0x53, record[18]);
assertEquals(0x43, record[19]);
}
@Test(expected = IllegalArgumentException.class)
public void shouldThrowExceptionIfSystemCharIndexGreaterThan2() {
builder.setSystemChar(3, '1');
Expand Down

0 comments on commit 46dee86

Please sign in to comment.