From 6cab3540b95a0664188bc7caff6d8a103d1ed276 Mon Sep 17 00:00:00 2001 From: "Matt Harrah (frizbog)" Date: Tue, 8 Nov 2016 21:40:22 -0500 Subject: [PATCH] More unit tests, better test coverage --- .../org/gedcom4j/writer/GedcomWriter.java | 67 ++- ...nstructionProgressAndCancellationTest.java | 56 +- ...WriterFileProgressAndCancellationTest.java | 61 +- .../GedcomWriterVersionCompatibilityTest.java | 540 ++++++++++++++++++ 4 files changed, 684 insertions(+), 40 deletions(-) create mode 100644 src/test/java/org/gedcom4j/writer/GedcomWriterVersionCompatibilityTest.java diff --git a/src/main/java/org/gedcom4j/writer/GedcomWriter.java b/src/main/java/org/gedcom4j/writer/GedcomWriter.java index 81110f46..ae18d8be 100644 --- a/src/main/java/org/gedcom4j/writer/GedcomWriter.java +++ b/src/main/java/org/gedcom4j/writer/GedcomWriter.java @@ -127,7 +127,7 @@ public class GedcomWriter extends AbstractEmitter { /** * The list of observers on string construction */ - private final List> constructObservers = new CopyOnWriteArrayList<>(); + final List> constructObservers = new CopyOnWriteArrayList<>(); /** * Send a notification whenever more than this many lines are written to a file @@ -137,7 +137,7 @@ public class GedcomWriter extends AbstractEmitter { /** * The list of observers on file operations */ - private final List> fileObservers = new CopyOnWriteArrayList<>(); + final List> fileObservers = new CopyOnWriteArrayList<>(); /** * The number of lines constructed as last reported to the observers @@ -381,7 +381,6 @@ public void unregisterConstructObserver(ConstructProgressListener observer) { i++; } } - constructObservers.add(new WeakReference<>(observer)); } /** @@ -400,7 +399,6 @@ public void unregisterFileObserver(FileProgressListener observer) { i++; } } - fileObservers.add(new WeakReference<>(observer)); } /** @@ -507,43 +505,13 @@ protected void emit() throws GedcomWriterException { emitTrailer(); } - /** - * Notify construct observers if more than 100 lines have been constructed since last time we notified them - */ - void notifyConstructObserversIfNeeded() { - if (lines.size() - lastLineCountNotified > constructionNotificationRate) { - notifyConstructObservers(new ConstructProgressEvent(this, lines.size(), true)); - } - } - - /** - * Checks that the gedcom version specified is compatible with the data in the model. Not a perfect exhaustive check. - * - * @throws GedcomWriterException - * if data is detected that is incompatible with the selected version - */ - private void checkVersionCompatibility() throws GedcomWriterException { - - if (writeFrom.getHeader().getGedcomVersion() == null) { - // If there's not one specified, set up a default one that specifies - // 5.5.1 - writeFrom.getHeader().setGedcomVersion(new GedcomVersion()); - } - if (SupportedVersion.V5_5.toString().equals(writeFrom.getHeader().getGedcomVersion().getVersionNumber().getValue())) { - checkVersionCompatibility55(); - } else { - checkVersionCompatibility551(); - } - - } - /** * Check that the data is compatible with 5.5 style Gedcom files * * @throws GedcomWriterVersionDataMismatchException * if a data point is detected that is incompatible with the 5.5 standard */ - private void checkVersionCompatibility55() throws GedcomWriterVersionDataMismatchException { + void checkVersionCompatibility55() throws GedcomWriterVersionDataMismatchException { // Now that we know if we're working with a 5.5.1 file or not, let's // check some data points if (writeFrom.getHeader().getCopyrightData() != null && writeFrom.getHeader().getCopyrightData().size() > 1) { @@ -600,6 +568,35 @@ private void checkVersionCompatibility55() throws GedcomWriterVersionDataMismatc } } + /** + * Notify construct observers if more than 100 lines have been constructed since last time we notified them + */ + void notifyConstructObserversIfNeeded() { + if (lines.size() - lastLineCountNotified > constructionNotificationRate) { + notifyConstructObservers(new ConstructProgressEvent(this, lines.size(), true)); + } + } + + /** + * Checks that the gedcom version specified is compatible with the data in the model. Not a perfect exhaustive check. + * + * @throws GedcomWriterException + * if data is detected that is incompatible with the selected version + */ + private void checkVersionCompatibility() throws GedcomWriterException { + + if (writeFrom.getHeader().getGedcomVersion() == null) { + // If there's not one specified, set up a default one that specifies + // 5.5.1 + writeFrom.getHeader().setGedcomVersion(new GedcomVersion()); + } + if (SupportedVersion.V5_5.toString().equals(writeFrom.getHeader().getGedcomVersion().getVersionNumber().getValue())) { + checkVersionCompatibility55(); + } else { + checkVersionCompatibility551(); + } + } + /** * Check that the data is compatible with 5.5.1 style Gedcom files * diff --git a/src/test/java/org/gedcom4j/writer/GedcomWriterConstructionProgressAndCancellationTest.java b/src/test/java/org/gedcom4j/writer/GedcomWriterConstructionProgressAndCancellationTest.java index 2137affa..8f7d3c22 100644 --- a/src/test/java/org/gedcom4j/writer/GedcomWriterConstructionProgressAndCancellationTest.java +++ b/src/test/java/org/gedcom4j/writer/GedcomWriterConstructionProgressAndCancellationTest.java @@ -40,6 +40,7 @@ import org.gedcom4j.writer.event.ConstructProgressEvent; import org.gedcom4j.writer.event.ConstructProgressListener; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; /** @@ -52,7 +53,7 @@ public class GedcomWriterConstructionProgressAndCancellationTest implements Cons /** * Number of notifications received */ - private int notificationCount = 0; + private int constructionNotificationCount = 0; /** * How many notifications to cancel after @@ -69,14 +70,22 @@ public class GedcomWriterConstructionProgressAndCancellationTest implements Cons */ @Override public void progressNotification(ConstructProgressEvent e) { - notificationCount++; + constructionNotificationCount++; Assert.assertTrue(e.isComplete()); Assert.assertTrue(e.toString().startsWith("ConstructProgressEvent")); - if (notificationCount >= cancelAfter) { + if (constructionNotificationCount >= cancelAfter) { gw.cancel(); } } + /** + * Set up before each test + */ + @Before + public void setUp() { + constructionNotificationCount = 0; + } + /** * Test with cancelling after getting a couple notifications * @@ -103,6 +112,34 @@ public void testCancellation() throws IOException, GedcomParserException, Gedcom gw.write(new NullOutputStream()); } + /** + * Test changing construction notification rate + * + * @throws IOException + * if the file can't be read + * @throws GedcomParserException + * if the file can't be parsed + * @throws GedcomWriterException + * if the file can't be written (or is cancelled) + */ + @SuppressWarnings("resource") + @Test(expected = WriterCancelledException.class) + public void testChangingConstructionNotificationRate() throws IOException, GedcomParserException, GedcomWriterException { + GedcomParser gp = new GedcomParser(); + gp.load("sample/willis-ascii.ged"); + Gedcom g = gp.getGedcom(); + Validator gv = new Validator(g); + gv.setAutoRepairResponder(Validator.AUTO_REPAIR_ALL); + gv.validate(); // Cleanup whatever can be cleaned up + gw = new GedcomWriter(g); + gw.setValidationSuppressed(true); + gw.registerConstructObserver(this); + gw.setConstructionNotificationRate(1); + cancelAfter = 5; + gw.write(new NullOutputStream()); + assertEquals(5, constructionNotificationCount); + } + /** * Test without cancelling * @@ -126,7 +163,18 @@ public void testNoCancellation() throws IOException, GedcomParserException, Gedc gw.setValidationSuppressed(true); gw.registerConstructObserver(this); gw.write(new NullOutputStream()); - assertEquals(40, notificationCount); + assertEquals(40, constructionNotificationCount); + } + + /** + * Try setting the notification rate below the minimum value + * + * @throws WriterCancelledException + * if the writer gets cancelled, which won't happen in this test + */ + @Test(expected = IllegalArgumentException.class) + public void testSetConstructionNotificationRateNegativeTest() throws WriterCancelledException { + new GedcomWriter(new Gedcom()).setConstructionNotificationRate(0); } } diff --git a/src/test/java/org/gedcom4j/writer/GedcomWriterFileProgressAndCancellationTest.java b/src/test/java/org/gedcom4j/writer/GedcomWriterFileProgressAndCancellationTest.java index 0e7c5a90..f2914f29 100644 --- a/src/test/java/org/gedcom4j/writer/GedcomWriterFileProgressAndCancellationTest.java +++ b/src/test/java/org/gedcom4j/writer/GedcomWriterFileProgressAndCancellationTest.java @@ -571,6 +571,66 @@ public void testNoCancellationUtf8CrOnly() throws IOException, GedcomParserExcep assertEquals(557056, bytesWritten); } + /** + * Test registering/unregistering observers. + * + * @throws WriterCancelledException + * the writer cancelled exception + */ + @Test + public void testRegisterUnregisterObservers() throws WriterCancelledException { + ConstructProgressListener c = new ConstructProgressListener() { + /** + * {@inheritDoc} + */ + @Override + public void progressNotification(ConstructProgressEvent e) { + // Do nothing + } + }; + FileProgressListener f = new FileProgressListener() { + /** + * {@inheritDoc} + */ + @Override + public void progressNotification(FileProgressEvent e) { + // Do nothing + } + }; + gw = new GedcomWriter(new Gedcom()); + assertEquals(0, gw.constructObservers.size()); + assertEquals(0, gw.fileObservers.size()); + gw.registerConstructObserver(c); + assertEquals(1, gw.constructObservers.size()); + assertEquals(0, gw.fileObservers.size()); + gw.unregisterConstructObserver(c); + assertEquals(0, gw.constructObservers.size()); + assertEquals(0, gw.fileObservers.size()); + + gw.registerFileObserver(f); + assertEquals(0, gw.constructObservers.size()); + assertEquals(1, gw.fileObservers.size()); + gw.unregisterFileObserver(f); + assertEquals(0, gw.constructObservers.size()); + assertEquals(0, gw.fileObservers.size()); + + // Unregistering observers that aren't observing does nothing, silently + gw.unregisterConstructObserver(c); + gw.unregisterFileObserver(f); + + } + + /** + * Try setting the notification rate below the minimum value + * + * @throws WriterCancelledException + * if the writer gets cancelled, which won't happen in this test + */ + @Test(expected = IllegalArgumentException.class) + public void testSetFileNotificationRateNegativeTest() throws WriterCancelledException { + new GedcomWriter(new Gedcom()).setFileNotificationRate(0); + } + /** * Helper method to clean up bad data in the GEDCOM so it writes ok * @@ -601,5 +661,4 @@ private void cleanUpGedcom(GedcomParser gp, Encoding encoding) { } } } - } diff --git a/src/test/java/org/gedcom4j/writer/GedcomWriterVersionCompatibilityTest.java b/src/test/java/org/gedcom4j/writer/GedcomWriterVersionCompatibilityTest.java new file mode 100644 index 00000000..8a82e517 --- /dev/null +++ b/src/test/java/org/gedcom4j/writer/GedcomWriterVersionCompatibilityTest.java @@ -0,0 +1,540 @@ +/* + * Copyright (c) 2009-2016 Matthew R. Harrah + * + * MIT License + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ +package org.gedcom4j.writer; + +import java.util.Date; + +import org.gedcom4j.exception.GedcomWriterVersionDataMismatchException; +import org.gedcom4j.exception.WriterCancelledException; +import org.gedcom4j.factory.FamilyFactory; +import org.gedcom4j.factory.IndividualFactory; +import org.gedcom4j.factory.Sex; +import org.gedcom4j.model.CharacterSet; +import org.gedcom4j.model.Corporation; +import org.gedcom4j.model.FamilyChild; +import org.gedcom4j.model.Gedcom; +import org.gedcom4j.model.GedcomVersion; +import org.gedcom4j.model.Individual; +import org.gedcom4j.model.IndividualAttribute; +import org.gedcom4j.model.IndividualEvent; +import org.gedcom4j.model.Repository; +import org.gedcom4j.model.SourceSystem; +import org.gedcom4j.model.StringWithCustomFacts; +import org.gedcom4j.model.Submitter; +import org.gedcom4j.model.enumerations.IndividualAttributeType; +import org.gedcom4j.model.enumerations.SupportedVersion; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +/** + * Test for checking version compatibility for {@link GedcomWriter} + * + * @author frizbog + */ +@SuppressWarnings("PMD.TooManyMethods") +public class GedcomWriterVersionCompatibilityTest { + + /** + * JUnit rule + */ + @Rule + public ExpectedException thrown = ExpectedException.none(); + + /** + * Class under test + */ + private GedcomWriter classUnderTest; + + /** + * Test fixture Gedcom with the data + */ + private Gedcom g; + + /** + * Set up before each test + * + * @throws WriterCancelledException + * if things get cancelled, which isn't going to happen here + */ + @Before + public void setUp() throws WriterCancelledException { + g = new Gedcom(); + classUnderTest = new GedcomWriter(g); + classUnderTest.setValidationSuppressed(true); + } + + /** + * Test combining GEDCOM 5.5 and Email on the corporation + * + * @throws GedcomWriterVersionDataMismatchException + * if there's a version compatibility problem + */ + @Test + public void testGedcom55CorpEmails() throws GedcomWriterVersionDataMismatchException { + GedcomVersion gv = new GedcomVersion(); + gv.setVersionNumber(SupportedVersion.V5_5); + g.getHeader().setGedcomVersion(gv); + + // Emails on the corporation and Gedcom 5.5 are not a valid combination + Corporation c = new Corporation(); + c.getEmails(true).add(new StringWithCustomFacts("support@gedcom4j.org")); + SourceSystem ss = new SourceSystem(); + ss.setCorporation(c); + g.getHeader().setSourceSystem(ss); + + thrown.expect(GedcomWriterVersionDataMismatchException.class); + thrown.expectMessage("email"); + classUnderTest.checkVersionCompatibility55(); + } + + /** + * Test combining GEDCOM 5.5 and Fax Numbers on the corporation + * + * @throws GedcomWriterVersionDataMismatchException + * if there's a version compatibility problem + */ + @Test + public void testGedcom55CorpFaxNumbers() throws GedcomWriterVersionDataMismatchException { + GedcomVersion gv = new GedcomVersion(); + gv.setVersionNumber(SupportedVersion.V5_5); + g.getHeader().setGedcomVersion(gv); + + // Fax Numbers on the corporation and Gedcom 5.5 are not a valid combination + Corporation c = new Corporation(); + c.getFaxNumbers(true).add(new StringWithCustomFacts("800-555-1212")); + SourceSystem ss = new SourceSystem(); + ss.setCorporation(c); + g.getHeader().setSourceSystem(ss); + + thrown.expect(GedcomWriterVersionDataMismatchException.class); + thrown.expectMessage("fax numbers"); + classUnderTest.checkVersionCompatibility55(); + } + + /** + * Test combining GEDCOM 5.5 and WWW URLs on the corporation + * + * @throws GedcomWriterVersionDataMismatchException + * if there's a version compatibility problem + */ + @Test + public void testGedcom55CorpWwwUrls() throws GedcomWriterVersionDataMismatchException { + GedcomVersion gv = new GedcomVersion(); + gv.setVersionNumber(SupportedVersion.V5_5); + g.getHeader().setGedcomVersion(gv); + + // WWW URLs on the corporation and Gedcom 5.5 are not a valid combination + Corporation c = new Corporation(); + c.getWwwUrls(true).add(new StringWithCustomFacts("http://gedcom4j.org")); + SourceSystem ss = new SourceSystem(); + ss.setCorporation(c); + g.getHeader().setSourceSystem(ss); + + thrown.expect(GedcomWriterVersionDataMismatchException.class); + thrown.expectMessage("www urls"); + classUnderTest.checkVersionCompatibility55(); + } + + /** + * Test family status and GEDCOM 5.5 + * + * @throws GedcomWriterVersionDataMismatchException + * if there's a version compatibility problem + */ + @Test + public void testGedcom55FamilyStatus() throws GedcomWriterVersionDataMismatchException { + GedcomVersion gv = new GedcomVersion(); + gv.setVersionNumber(SupportedVersion.V5_5); + g.getHeader().setGedcomVersion(gv); + + Individual father = new IndividualFactory().create(g, "Dad", "Smith", Sex.MALE, (Date) null, null, (Date) null, null); + Individual mother = new IndividualFactory().create(g, "Mom", "Smith", Sex.MALE, (Date) null, null, (Date) null, null); + Individual child = new IndividualFactory().create(g, "Kid", "Smith", Sex.MALE, (Date) null, null, (Date) null, null); + new FamilyFactory().create(g, father, mother, child); + + FamilyChild familyChild = child.getFamiliesWhereChild().get(0); + familyChild.setStatus("Swell -- but not allowed in GEDCOM 5.5"); + + thrown.expect(GedcomWriterVersionDataMismatchException.class); + thrown.expectMessage("status"); + classUnderTest.checkVersionCompatibility55(); + } + + /** + * Test combining GEDCOM 5.5 and FACT type individual attributes + * + * @throws GedcomWriterVersionDataMismatchException + * if there's a version compatibility problem + */ + @Test + public void testGedcom55IndividualAttributeFacts() throws GedcomWriterVersionDataMismatchException { + GedcomVersion gv = new GedcomVersion(); + gv.setVersionNumber(SupportedVersion.V5_5); + g.getHeader().setGedcomVersion(gv); + + // Emails on the individual attribute and Gedcom 5.5 are not a valid combination + IndividualAttribute ia = new IndividualAttribute(); + ia.setType(IndividualAttributeType.FACT); + Individual i = new Individual(); + i.getAttributes(true).add(ia); + g.getIndividuals().put("@I1@", i); + + thrown.expect(GedcomWriterVersionDataMismatchException.class); + thrown.expectMessage("FACT"); + classUnderTest.checkVersionCompatibility55(); + } + + /** + * Test combining GEDCOM 5.5 and Emails on the individual + * + * @throws GedcomWriterVersionDataMismatchException + * if there's a version compatibility problem + */ + @Test + public void testGedcom55IndividualEmails() throws GedcomWriterVersionDataMismatchException { + GedcomVersion gv = new GedcomVersion(); + gv.setVersionNumber(SupportedVersion.V5_5); + g.getHeader().setGedcomVersion(gv); + + // Emails on the individual and Gedcom 5.5 are not a valid combination + Individual i = new Individual(); + i.getEmails(true).add(new StringWithCustomFacts("support@gedcom4j.org")); + g.getIndividuals().put("@I1@", i); + + thrown.expect(GedcomWriterVersionDataMismatchException.class); + thrown.expectMessage("email"); + classUnderTest.checkVersionCompatibility55(); + } + + /** + * Test combining GEDCOM 5.5 and emails on the individual event + * + * @throws GedcomWriterVersionDataMismatchException + * if there's a version compatibility problem + */ + @Test + public void testGedcom55IndividualEventEmails() throws GedcomWriterVersionDataMismatchException { + GedcomVersion gv = new GedcomVersion(); + gv.setVersionNumber(SupportedVersion.V5_5); + g.getHeader().setGedcomVersion(gv); + + // Emails on the individual event and Gedcom 5.5 are not a valid combination + IndividualEvent ie = new IndividualEvent(); + ie.getEmails(true).add(new StringWithCustomFacts("support@gedcom4j.org")); + Individual i = new Individual(); + i.getEvents(true).add(ie); + g.getIndividuals().put("@I1@", i); + + thrown.expect(GedcomWriterVersionDataMismatchException.class); + thrown.expectMessage("email"); + classUnderTest.checkVersionCompatibility55(); + } + + /** + * Test combining GEDCOM 5.5 and Fax Numbers on the individual event + * + * @throws GedcomWriterVersionDataMismatchException + * if there's a version compatibility problem + */ + @Test + public void testGedcom55IndividualEventFaxNumbers() throws GedcomWriterVersionDataMismatchException { + GedcomVersion gv = new GedcomVersion(); + gv.setVersionNumber(SupportedVersion.V5_5); + g.getHeader().setGedcomVersion(gv); + + // Fax Numbers on the individual event and Gedcom 5.5 are not a valid combination + IndividualEvent ie = new IndividualEvent(); + ie.getFaxNumbers(true).add(new StringWithCustomFacts("800-555-1212")); + Individual i = new Individual(); + i.getEvents(true).add(ie); + g.getIndividuals().put("@I1@", i); + + thrown.expect(GedcomWriterVersionDataMismatchException.class); + thrown.expectMessage("fax numbers"); + classUnderTest.checkVersionCompatibility55(); + } + + /** + * Test combining GEDCOM 5.5 and WWW URLs on the individual event + * + * @throws GedcomWriterVersionDataMismatchException + * if there's a version compatibility problem + */ + @Test + public void testGedcom55IndividualEventWwwUrls() throws GedcomWriterVersionDataMismatchException { + GedcomVersion gv = new GedcomVersion(); + gv.setVersionNumber(SupportedVersion.V5_5); + g.getHeader().setGedcomVersion(gv); + + // WWW URLs on the individual event and Gedcom 5.5 are not a valid combination + IndividualEvent ie = new IndividualEvent(); + ie.getWwwUrls(true).add(new StringWithCustomFacts("http://gedcom4j.org")); + Individual i = new Individual(); + i.getEvents(true).add(ie); + g.getIndividuals().put("@I1@", i); + + thrown.expect(GedcomWriterVersionDataMismatchException.class); + thrown.expectMessage("www urls"); + classUnderTest.checkVersionCompatibility55(); + } + + /** + * Test combining GEDCOM 5.5 and Fax Numbers on the individual + * + * @throws GedcomWriterVersionDataMismatchException + * if there's a version compatibility problem + */ + @Test + public void testGedcom55IndividualFaxNumbers() throws GedcomWriterVersionDataMismatchException { + GedcomVersion gv = new GedcomVersion(); + gv.setVersionNumber(SupportedVersion.V5_5); + g.getHeader().setGedcomVersion(gv); + + // Fax Numbers on the individual and Gedcom 5.5 are not a valid combination + Individual i = new Individual(); + i.getFaxNumbers(true).add(new StringWithCustomFacts("800-555-1212")); + g.getIndividuals().put("@I1@", i); + + thrown.expect(GedcomWriterVersionDataMismatchException.class); + thrown.expectMessage("fax numbers"); + classUnderTest.checkVersionCompatibility55(); + } + + /** + * Test combining GEDCOM 5.5 and WWW URLs on the individual + * + * @throws GedcomWriterVersionDataMismatchException + * if there's a version compatibility problem + */ + @Test + public void testGedcom55IndividualWwwUrls() throws GedcomWriterVersionDataMismatchException { + GedcomVersion gv = new GedcomVersion(); + gv.setVersionNumber(SupportedVersion.V5_5); + g.getHeader().setGedcomVersion(gv); + + // WWW URLs on the individual and Gedcom 5.5 are not a valid combination + Individual i = new Individual(); + i.getWwwUrls(true).add(new StringWithCustomFacts("http://gedcom4j.org")); + g.getIndividuals().put("@I1@", i); + + thrown.expect(GedcomWriterVersionDataMismatchException.class); + thrown.expectMessage("www urls"); + classUnderTest.checkVersionCompatibility55(); + } + + /** + * Test combining GEDCOM 5.5 and no character set + * + * @throws GedcomWriterVersionDataMismatchException + * if there's a version compatibility problem + */ + @Test + public void testGedcom55NoCharacterSet() throws GedcomWriterVersionDataMismatchException { + g.getHeader().setCharacterSet(null); + GedcomVersion gv = new GedcomVersion(); + gv.setVersionNumber(SupportedVersion.V5_5); + g.getHeader().setGedcomVersion(gv); + + classUnderTest.checkVersionCompatibility55(); + } + + /** + * Test combining GEDCOM 5.5 and no character set + * + * @throws GedcomWriterVersionDataMismatchException + * if there's a version compatibility problem + */ + @Test + public void testGedcom55NoCharacterSetName() throws GedcomWriterVersionDataMismatchException { + CharacterSet cs = new CharacterSet(); + cs.setCharacterSetName((String) null); + g.getHeader().setCharacterSet(cs); + + GedcomVersion gv = new GedcomVersion(); + gv.setVersionNumber(SupportedVersion.V5_5); + g.getHeader().setGedcomVersion(gv); + + classUnderTest.checkVersionCompatibility55(); + } + + /** + * Test combining GEDCOM 5.5 and Emails on the repository + * + * @throws GedcomWriterVersionDataMismatchException + * if there's a version compatibility problem + */ + @Test + public void testGedcom55RepositoryEmails() throws GedcomWriterVersionDataMismatchException { + GedcomVersion gv = new GedcomVersion(); + gv.setVersionNumber(SupportedVersion.V5_5); + g.getHeader().setGedcomVersion(gv); + + // Emails on the repository and Gedcom 5.5 are not a valid combination + Repository r = new Repository(); + r.getEmails(true).add(new StringWithCustomFacts("support@gedcom4j.org")); + g.getRepositories().put("@SUBM1@", r); + + thrown.expect(GedcomWriterVersionDataMismatchException.class); + thrown.expectMessage("email"); + classUnderTest.checkVersionCompatibility55(); + } + + /** + * Test combining GEDCOM 5.5 and Fax Numbers on the repository + * + * @throws GedcomWriterVersionDataMismatchException + * if there's a version compatibility problem + */ + @Test + public void testGedcom55RepositoryFaxNumbers() throws GedcomWriterVersionDataMismatchException { + GedcomVersion gv = new GedcomVersion(); + gv.setVersionNumber(SupportedVersion.V5_5); + g.getHeader().setGedcomVersion(gv); + + // Fax Numbers on the repository and Gedcom 5.5 are not a valid combination + Repository r = new Repository(); + r.getFaxNumbers(true).add(new StringWithCustomFacts("800-555-1212")); + g.getRepositories().put("@SUBM1@", r); + + thrown.expect(GedcomWriterVersionDataMismatchException.class); + thrown.expectMessage("fax numbers"); + classUnderTest.checkVersionCompatibility55(); + } + + /** + * Test combining GEDCOM 5.5 and WWW URLs on the repository + * + * @throws GedcomWriterVersionDataMismatchException + * if there's a version compatibility problem + */ + @Test + public void testGedcom55RepositoryWwwUrls() throws GedcomWriterVersionDataMismatchException { + GedcomVersion gv = new GedcomVersion(); + gv.setVersionNumber(SupportedVersion.V5_5); + g.getHeader().setGedcomVersion(gv); + + // WWW URLs on the repository and Gedcom 5.5 are not a valid combination + Repository r = new Repository(); + r.getWwwUrls(true).add(new StringWithCustomFacts("http://gedcom4j.org")); + g.getRepositories().put("@SUBM1@", r); + + thrown.expect(GedcomWriterVersionDataMismatchException.class); + thrown.expectMessage("www urls"); + classUnderTest.checkVersionCompatibility55(); + } + + /** + * Test combining GEDCOM 5.5 and emails on the submitter + * + * @throws GedcomWriterVersionDataMismatchException + * if there's a version compatibility problem + */ + @Test + public void testGedcom55SubmitterEmails() throws GedcomWriterVersionDataMismatchException { + GedcomVersion gv = new GedcomVersion(); + gv.setVersionNumber(SupportedVersion.V5_5); + g.getHeader().setGedcomVersion(gv); + + // Emails on the submitter and Gedcom 5.5 are not a valid combination + Submitter s = new Submitter(); + s.getEmails(true).add(new StringWithCustomFacts("support@gedcom4j.org")); + g.getSubmitters().put("@SUBM1@", s); + + thrown.expect(GedcomWriterVersionDataMismatchException.class); + thrown.expectMessage("email"); + classUnderTest.checkVersionCompatibility55(); + } + + /** + * Test combining GEDCOM 5.5 and Fax Numbers on the submitter + * + * @throws GedcomWriterVersionDataMismatchException + * if there's a version compatibility problem + */ + @Test + public void testGedcom55SubmitterFaxNumbers() throws GedcomWriterVersionDataMismatchException { + GedcomVersion gv = new GedcomVersion(); + gv.setVersionNumber(SupportedVersion.V5_5); + g.getHeader().setGedcomVersion(gv); + + // Fax Numbers on the submitter and Gedcom 5.5 are not a valid combination + Submitter s = new Submitter(); + s.getFaxNumbers(true).add(new StringWithCustomFacts("800-555-1212")); + g.getSubmitters().put("@SUBM1@", s); + + thrown.expect(GedcomWriterVersionDataMismatchException.class); + thrown.expectMessage("fax numbers"); + classUnderTest.checkVersionCompatibility55(); + } + + /** + * Test combining GEDCOM 5.5 and WWW URLs on the submitter + * + * @throws GedcomWriterVersionDataMismatchException + * if there's a version compatibility problem + */ + @Test + public void testGedcom55SubmitterWwwUrls() throws GedcomWriterVersionDataMismatchException { + GedcomVersion gv = new GedcomVersion(); + gv.setVersionNumber(SupportedVersion.V5_5); + g.getHeader().setGedcomVersion(gv); + + // WWW URLs on the submitter and Gedcom 5.5 are not a valid combination + Submitter s = new Submitter(); + s.getWwwUrls(true).add(new StringWithCustomFacts("http://gedcom4j.org")); + g.getSubmitters().put("@SUBM1@", s); + + thrown.expect(GedcomWriterVersionDataMismatchException.class); + thrown.expectMessage("www urls"); + classUnderTest.checkVersionCompatibility55(); + } + + /** + * Test combining GEDCOM 5.5 and UTF-8 + * + * @throws GedcomWriterVersionDataMismatchException + * if there's a version compatibility problem + */ + @Test + public void testGedcom55Utf8() throws GedcomWriterVersionDataMismatchException { + GedcomVersion gv = new GedcomVersion(); + gv.setVersionNumber(SupportedVersion.V5_5); + g.getHeader().setGedcomVersion(gv); + + // UTF-8 and Gedcom 5.5 are not a valid combination + CharacterSet cs = new CharacterSet(); + cs.setCharacterSetName("UTF-8"); + g.getHeader().setCharacterSet(cs); + + thrown.expect(GedcomWriterVersionDataMismatchException.class); + thrown.expectMessage("UTF-8"); + classUnderTest.checkVersionCompatibility55(); + } + +}