Skip to content

Commit

Permalink
Add test for #524 (#454)
Browse files Browse the repository at this point in the history
- fix typo
- remove superflous endEntity
- add method to avoid unnecessary char-string conversion
  • Loading branch information
dr0i committed Apr 22, 2024
1 parent e2c4c0d commit eb38a1b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,24 +199,27 @@ public void literal(final String name, final String value) {
private void processLeaderAsOneLiteral(final String value) {
if (value.length() != Iso2709Constants.RECORD_LABEL_LENGTH) {
throw new FormatException(
"leader literal must contain " + Iso2709Constants.RECORD_LABEL_LENGTH + " characters:" + value);
"leader literal must contain " + Iso2709Constants.RECORD_LABEL_LENGTH + " characters: " + value);
}
processLeaderAsSubfields(Marc21EventNames.RECORD_STATUS_LITERAL, String.valueOf(value.charAt(Iso2709Constants.RECORD_STATUS_POS)));
processLeaderAsSubfields(Marc21EventNames.RECORD_TYPE_LITERAL, String.valueOf(value.charAt(Iso2709Constants.IMPL_CODES_START)));
processLeaderAsSubfields(Marc21EventNames.BIBLIOGRAPHIC_LEVEL_LITERAL, String.valueOf(value.charAt(Iso2709Constants.IMPL_CODES_START + 1)));
processLeaderAsSubfields(Marc21EventNames.TYPE_OF_CONTROL_LITERAL, String.valueOf(value.charAt(Iso2709Constants.IMPL_CODES_START + 2)));
processLeaderAsSubfields(Marc21EventNames.CHARACTER_CODING_LITERAL, String.valueOf(value.charAt(Iso2709Constants.RECORD_STATUS_POS + Iso2709Constants.IMPL_CODES_LENGTH)));
processLeaderAsSubfields(Marc21EventNames.ENCODING_LEVEL_LITERAL, String.valueOf(value.charAt(Iso2709Constants.SYSTEM_CHARS_START)));
processLeaderAsSubfields(Marc21EventNames.CATALOGING_FORM_LITERAL, String.valueOf(value.charAt(Iso2709Constants.SYSTEM_CHARS_START + 1)));
processLeaderAsSubfields(Marc21EventNames.MULTIPART_LEVEL_LITERAL, String.valueOf(value.charAt(Iso2709Constants.SYSTEM_CHARS_START + 2)));
processLeaderAsSubfields(Marc21EventNames.RECORD_STATUS_LITERAL, value.charAt(Iso2709Constants.RECORD_STATUS_POS));
processLeaderAsSubfields(Marc21EventNames.RECORD_TYPE_LITERAL, value.charAt(Iso2709Constants.IMPL_CODES_START));
processLeaderAsSubfields(Marc21EventNames.BIBLIOGRAPHIC_LEVEL_LITERAL, value.charAt(Iso2709Constants.IMPL_CODES_START + 1));
processLeaderAsSubfields(Marc21EventNames.TYPE_OF_CONTROL_LITERAL, value.charAt(Iso2709Constants.IMPL_CODES_START + 2));
processLeaderAsSubfields(Marc21EventNames.CHARACTER_CODING_LITERAL, value.charAt(Iso2709Constants.RECORD_STATUS_POS + Iso2709Constants.IMPL_CODES_LENGTH));
processLeaderAsSubfields(Marc21EventNames.ENCODING_LEVEL_LITERAL, value.charAt(Iso2709Constants.SYSTEM_CHARS_START));
processLeaderAsSubfields(Marc21EventNames.CATALOGING_FORM_LITERAL, value.charAt(Iso2709Constants.SYSTEM_CHARS_START + 1));
processLeaderAsSubfields(Marc21EventNames.MULTIPART_LEVEL_LITERAL, value.charAt(Iso2709Constants.SYSTEM_CHARS_START + 2));
}

private void processLeaderAsSubfields(final String name, final String value) {
if (value.length() != 1) {
throw new FormatException(
"literal must only contain a single character:" + name);
}
final char code = value.charAt(0);
processLeaderAsSubfields(name, value.charAt(0));
}

private void processLeaderAsSubfields(final String name, final char code) {
switch (name) {
case Marc21EventNames.RECORD_STATUS_LITERAL:
requireValidCode(code, Marc21Constants.RECORD_STATUS_CODES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ public void issue454ShouldNotFailWhenProcessingEntityLeaderAsOneString() {
marc21Encoder.startEntity(LEADER_ENTITY);
marc21Encoder.literal(LEADER_ENTITY, "02602pam a2200529 c 4500");
marc21Encoder.endEntity();
marc21Encoder.endEntity();
marc21Encoder.endRecord();

verify(receiver).process(matches("00026pam a2200025 c 4500\u001e\u001d"));
Expand All @@ -130,10 +129,22 @@ public void issue454ShouldNotFailWhenProcessingEntityLeaderAsOneString() {
public void issue454ShouldNotFailWhenProcessingLeaderAsOneString() {
marc21Encoder.startRecord("");
marc21Encoder.literal(LEADER_ENTITY, "02602pam a2200529 c 4500");
marc21Encoder.endEntity();
marc21Encoder.endRecord();

verify(receiver).process(matches("00026pam a2200025 c 4500\u001e\u001d"));
}

@Test
public void issue524ShouldComputeValidLeader() {
marc21Encoder.startRecord("");
marc21Encoder.literal(LEADER_ENTITY, "00000pam a7777777 c 4444");
marc21Encoder.startEntity("021a ");
marc21Encoder.literal("v", "Fritz");
marc21Encoder.literal("n", "Bauer");
marc21Encoder.endEntity();
marc21Encoder.endRecord();

verify(receiver).process(matches("00055pam a2200037 c 4500021001700000\u001e.*\u001d"));
}

}

0 comments on commit eb38a1b

Please sign in to comment.