Skip to content

Commit

Permalink
Take hints from @blackwinter into account (#531)
Browse files Browse the repository at this point in the history
  • Loading branch information
dr0i committed May 13, 2024
1 parent fde6ba1 commit c7f0c28
Showing 1 changed file with 14 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.ComparisonFailure;
import org.junit.Test;
import static org.metafacture.biblio.marc21.Marc21EventNames.BIBLIOGRAPHIC_LEVEL_LITERAL;
import static org.metafacture.biblio.marc21.Marc21EventNames.CATALOGING_FORM_LITERAL;
Expand Down Expand Up @@ -58,15 +57,13 @@ public class MarcXmlEncoderTest {
private static final String RECORD_ID = "92005291";

private static StringBuilder resultCollector;
private static MarcXmlEncoder encoder;
private static MarcXmlEncoder encoder_ensureCorrectMarc21Xml;
private final MarcXmlEncoder encoder = new MarcXmlEncoder();
private final MarcXmlEncoder encoder_ensureCorrectMarc21Xml = new MarcXmlEncoder();


@Before
public void setUp() {
encoder = new MarcXmlEncoder();
initializeEncoder(encoder);
encoder_ensureCorrectMarc21Xml = new MarcXmlEncoder();
encoder_ensureCorrectMarc21Xml.setEnsureCorrectMarc21Xml(true);
initializeEncoder(encoder_ensureCorrectMarc21Xml);
}
Expand Down Expand Up @@ -243,33 +240,33 @@ public void issue336_createRecordWithTopLevelLeader() {

@Test
public void issue336_createRecordWithTopLevelLeader_ensureCorrectMarc21Xml() {
issue336_createRecordWithTopLevelLeader_correctMarc21Xml(encoder_ensureCorrectMarc21Xml);
createRecordWithTopLevelLeader(encoder_ensureCorrectMarc21Xml, "00048naa a2200037uc 4500");
}

@Test(expected = NullPointerException.class)
public void setParameterAfterSettingReceiver_ensureCorrectMarc21Xml() {
encoder_ensureCorrectMarc21Xml.setEnsureCorrectMarc21Xml(true);
issue336_createRecordWithTopLevelLeader_correctMarc21Xml(encoder_ensureCorrectMarc21Xml);
}

@Test(expected = ComparisonFailure.class)
public void issue336_createRecordWithTopLevelLeader_correctMarc21Xml() {
issue336_createRecordWithTopLevelLeader_correctMarc21Xml(encoder);
@Test
public void issue336_createRecordWithTopLevelLeader_defaultMarc21Xml() {
createRecordWithTopLevelLeader(encoder,"00000naa a2200000uc 4500");
}

private void issue336_createRecordWithTopLevelLeader_correctMarc21Xml(MarcXmlEncoder encoder) {
private void createRecordWithTopLevelLeader(final MarcXmlEncoder encoder, final String expectedLeader) {
encoder.startRecord("1");
encoder.literal("001", "8u3287432");
encoder.literal(Marc21EventNames.LEADER_ENTITY, "00000naa a2200000uc 4500");
encoder.endRecord();
encoder.closeStream();
String expected = XML_DECLARATION + XML_ROOT_OPEN
+ "<marc:record><marc:controlfield tag=\"001\">8u3287432</marc:controlfield>" +
"<marc:leader>00048naa a2200037uc 4500</marc:leader></marc:record>" + XML_MARC_COLLECTION_END_TAG;
"<marc:leader>" + expectedLeader + "</marc:leader></marc:record>" + XML_MARC_COLLECTION_END_TAG;
String actual = resultCollector.toString();
assertEquals(expected, actual);
}

@Test(expected = NullPointerException.class)
public void setParameterAfterSettingReceiver() {
encoder_ensureCorrectMarc21Xml.setEnsureCorrectMarc21Xml(true);
createRecordWithTopLevelLeader(encoder_ensureCorrectMarc21Xml,"ignored");
}

@Test
public void issue527ShouldEmitLeaderAlwaysAsWholeString() {
issue527ShouldEmitLeaderAlwaysAsWholeString(encoder);
Expand Down

0 comments on commit c7f0c28

Please sign in to comment.