Package org.gedcom4j.parser

Source Code of org.gedcom4j.parser.Issue62Test

package org.gedcom4j.parser;

import static org.junit.Assert.*;

import java.io.IOException;

import org.gedcom4j.model.Gedcom;
import org.gedcom4j.model.Individual;
import org.gedcom4j.model.IndividualEvent;
import org.junit.Before;
import org.junit.Test;

/**
* Test case for Issue 62, where events have descriptions and continuation lines like FTM exports, even though the spec
* doesn't allow them.
*
* @author frizbog
*/
public class Issue62Test {

    /**
     * The birth event from the GEDCOM file. In the test file, this tag has lengthy text with concatenation lines in
     * violation of the spec.
     */
    private IndividualEvent birth;

    /**
     * The cremation event from the GEDCOM file. In the test file, this tag has a Y in the [Y|<NULL>] field.
     */
    private IndividualEvent cremation;

    /**
     * The burial event from the test GEDCOM file. In the file, this tag has nothing (i.e., "null") in the
     * [Y|<NULL>] field.
     */
    private IndividualEvent burial;

    /**
     * The death event from the test GEDCOM file. In the file, this tag has a single line of descriptive text, in
     * violation of the spec.
     */
    private IndividualEvent death;

    /**
     * Parse the GEDCOM and set up fields for use in test cases
     *
     * @throws IOException
     *             if the file can't be read
     * @throws GedcomParserException
     *             if there's a parsing problem
     */
    @Before
    public void setUp() throws IOException, GedcomParserException {
        GedcomParser gp = new GedcomParser();
        gp.load("sample/Event Tag Test.ged");
        Gedcom g = gp.gedcom;
        assertNotNull(g);
        assertTrue(gp.errors.isEmpty());
        assertEquals("Two tags had descriptions where [Y|<NULL>] belonged", 2, gp.warnings.size());
        assertFalse(g.individuals.isEmpty());
        assertEquals(1, g.individuals.size());
        Individual i = g.individuals.values().iterator().next();
        assertNotNull(i);
        assertEquals(4, i.events.size());
        birth = i.events.get(0);
        assertNotNull(birth);
        cremation = i.events.get(1);
        assertNotNull(cremation);
        burial = i.events.get(2);
        assertNotNull(burial);
        death = i.events.get(3);
        assertNotNull(death);
    }

    /**
     * The multi-line description following the BIRT tag should be in the description field
     */
    @Test
    public void testBirthDescription() {
        assertNotNull(birth.description);
        assertNotNull(birth.description.value);
        System.out.println(birth.description.value);
        assertTrue(birth.description.value.startsWith("This was entered"));
        assertTrue(birth.description.value.endsWith("laborum."));
        assertEquals(552, birth.description.value.length());
    }

    /**
     * yNull should always be Y or "null" (not necessarily Java's idea of null, but just empty/missing in the GEDCOM).
     * In the test file, there was a lengthy description following the BIRT tag (with a bunch of CONC lines), so Y was
     * not specified, so this should have been treated as a "null" in the GEDCOM.
     */
    @Test
    public void testBirthYNull() {
        assertNull("", birth.yNull);
    }

    /**
     * The BURI tag had a single line of description following it
     */
    @Test
    public void testBurialDescription() {
        assertNotNull(burial.description);
        assertEquals("Unmarked grave", burial.description.value);
    }

    /**
     * yNull should always be Y or "null" (not necessarily Java's idea of null, but just empty/missing in the GEDCOM).
     * In the test file, the BURI tag had nothing after it
     */
    @Test
    public void testBurialYNull() {
        assertNull(burial.yNull);
    }

    /**
     * The CREM tag has no description value, since it had a Y value in the [Y|&lt;NULL&gt;] field.
     */
    @Test
    public void testCremationDescription() {
        assertNull(cremation.description);
    }

    /**
     * yNull should always be Y or "null" (not necessarily Java's idea of null, but just empty/missing in the GEDCOM).
     * In the test file, the CREM tag had a Y.
     */
    @Test
    public void testCremationYNull() {
        assertEquals("Y", cremation.yNull);
    }

    /**
     * The DEAT tag has no description value since it had nothing after the tag
     */
    @Test
    public void testDeathDescription() {
        assertNull(death.description);
    }

    /**
     * yNull should always be Y or "null" (not necessarily Java's idea of null, but just empty/missing in the GEDCOM).
     * In the test file, there was a description following the DEAT tag, so Y was not specified, so this should have
     * been treated as a "null" in the GEDCOM.
     */
    @Test
    public void testDeathYNull() {
        assertNull(death.yNull);
    }
}
TOP

Related Classes of org.gedcom4j.parser.Issue62Test

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.