001package edu.pdx.cs.joy.family; 002 003import org.junit.jupiter.api.Test; 004 005import java.io.PrintWriter; 006import java.io.StringWriter; 007import java.util.Date; 008 009import static org.junit.jupiter.api.Assertions.fail; 010 011/** 012 * This is the abstract superclass that tests the conversion of a 013 * {@link FamilyTree} from one form to another. The test methods can 014 * be shared by subclasses. All the subclass has to do is override 015 the {@link #getStringFor} and {@link #getFamilyTreeFor} methods. 016 */ 017public abstract class FamilyTreeConversionTestCase 018 extends FamilyTestCase { 019 020 //////// Helper methods 021 022 /** 023 * Converts a <code>FamilyTree</code> to a <code>String</code> 024 */ 025 protected abstract String getStringFor(FamilyTree tree); 026 027 /** 028 * Converts a <code>String</code> to a <code>FamilyTree</code> 029 */ 030 protected abstract FamilyTree getFamilyTreeFor(String string); 031 032 //////// Test methods 033 034 @Test 035 public void testConformingData() { 036 Person father = new Person(1, Person.MALE); 037 father.setDateOfBirth(new Date()); 038 father.setDateOfDeath(new Date()); 039 040 Person mother = new Person(2, Person.FEMALE); 041 mother.setDateOfBirth(new Date()); 042 mother.setDateOfDeath(new Date()); 043 044 Person child = new Person(3, Person.FEMALE); 045 child.setFather(father); 046 child.setMother(mother); 047 048 Marriage m = new Marriage(father, mother); 049 m.setLocation("Here"); 050 m.setDate(new Date()); 051 052 father.addMarriage(m); 053 mother.addMarriage(m); 054 055 FamilyTree tree = new FamilyTree(); 056 tree.addPerson(father); 057 tree.addPerson(mother); 058 tree.addPerson(child); 059 060 String string = getStringFor(tree); 061 062 FamilyTree tree2 = null; 063 064 try { 065 tree2 = getFamilyTreeFor(string); 066 067 } catch (FamilyTreeException ex) { 068 StringWriter sw = new StringWriter(); 069 ex.printStackTrace(new PrintWriter(sw, true)); 070 fail(sw.toString()); 071 } 072 073 assertEquals(tree, tree2); 074 } 075 076 public void _testFatherNotMale() { 077 078 } 079 080 public void _testMotherNotFemale() { 081 082 } 083 084 public void _testPersonNotMale() { 085 // We expect the person to be male because he was previously 086 // somebody's father 087 } 088 089 public void _testPersonNotFemale() { 090 // We expect the person to be female because she was previously 091 // somebody's mother 092 } 093 094 095}