From c7f0c28713a30b6f38394c374edfb62c509d7cfd Mon Sep 17 00:00:00 2001 From: Pascal Christoph Date: Mon, 13 May 2024 13:49:38 +0200 Subject: [PATCH] Take hints from @blackwinter into account (#531) --- .../biblio/marc21/MarcXmlEncoderTest.java | 31 +++++++++---------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/MarcXmlEncoderTest.java b/metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/MarcXmlEncoderTest.java index f57b87e3f..674d2f145 100644 --- a/metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/MarcXmlEncoderTest.java +++ b/metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/MarcXmlEncoderTest.java @@ -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; @@ -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); } @@ -243,21 +240,15 @@ 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"); @@ -265,11 +256,17 @@ private void issue336_createRecordWithTopLevelLeader_correctMarc21Xml(MarcXmlEnc encoder.closeStream(); String expected = XML_DECLARATION + XML_ROOT_OPEN + "8u3287432" + - "00048naa a2200037uc 4500" + XML_MARC_COLLECTION_END_TAG; + "" + expectedLeader + "" + 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);