From odf-commits-return-809-apmail-incubator-odf-commits-archive=incubator.apache.org@incubator.apache.org Fri Dec 14 07:27:20 2012 Return-Path: X-Original-To: apmail-incubator-odf-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-odf-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 88DECE6B7 for ; Fri, 14 Dec 2012 07:27:20 +0000 (UTC) Received: (qmail 65983 invoked by uid 500); 14 Dec 2012 07:27:20 -0000 Delivered-To: apmail-incubator-odf-commits-archive@incubator.apache.org Received: (qmail 65819 invoked by uid 500); 14 Dec 2012 07:27:15 -0000 Mailing-List: contact odf-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: odf-dev@incubator.apache.org Delivered-To: mailing list odf-commits@incubator.apache.org Received: (qmail 65781 invoked by uid 99); 14 Dec 2012 07:27:13 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 14 Dec 2012 07:27:13 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 14 Dec 2012 07:27:10 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id DB6692388AA6; Fri, 14 Dec 2012 07:26:48 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1421701 - /incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/meta/OfficeMetaTest.java Date: Fri, 14 Dec 2012 07:26:48 -0000 To: odf-commits@incubator.apache.org From: fhopf@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20121214072648.DB6692388AA6@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: fhopf Date: Fri Dec 14 07:26:47 2012 New Revision: 1421701 URL: http://svn.apache.org/viewvc?rev=1421701&view=rev Log: ODFTOOLKIT-342 fixed depending on ordering of test methods Modified: incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/meta/OfficeMetaTest.java Modified: incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/meta/OfficeMetaTest.java URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/meta/OfficeMetaTest.java?rev=1421701&r1=1421700&r2=1421701&view=diff ============================================================================== --- incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/meta/OfficeMetaTest.java (original) +++ incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/meta/OfficeMetaTest.java Fri Dec 14 07:26:47 2012 @@ -19,6 +19,8 @@ under the License. package org.odftoolkit.simple.meta; +import java.io.File; +import java.io.IOException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; @@ -61,50 +63,31 @@ public class OfficeMetaTest { fMetadata = new Meta(metadom); } - @After - public void tearDown() throws Exception { - doc.save(ResourceUtilities.getAbsolutePath(filename)); - doc = null; - metadom = null; - } - @Test - public void testSetGenerator() { + public void testGetGenerator() throws Exception { fMetadata.setGenerator(generator); - } - - @Test - public void testGetGenerator() { + writeAndReload(); Assert.assertEquals(generator, fMetadata.getGenerator()); } @Test - public void testSetDcTitle() { + public void testGetDcTitle() throws Exception { fMetadata.setTitle(dctitle); - } - - @Test - public void testGetDcTitle() { + writeAndReload(); Assert.assertEquals(dctitle, fMetadata.getTitle()); } @Test - public void testSetDcDescription() { + public void testGetDcDescription() throws Exception { fMetadata.setDescription(dcdescription); - } - - @Test - public void testGetDcDescription() { + writeAndReload(); Assert.assertEquals(dcdescription, fMetadata.getDescription()); } @Test - public void testSetSubject() { + public void testGetSubject() throws Exception { fMetadata.setSubject(subject); - } - - @Test - public void testGetSubject() { + writeAndReload(); Assert.assertEquals(subject, fMetadata.getSubject()); } @@ -114,38 +97,28 @@ public class OfficeMetaTest { keywords.add("computer3"); keywords.add("think center"); fMetadata.setKeywords(keywords); - tearDown(); - setUp(); + writeAndReload(); Assert.assertEquals(keywords, fMetadata.getKeywords()); } @Test - public void testSetInitialCreator() { + public void testGetInitialCreator() throws Exception { fMetadata.setInitialCreator(initialCreator); - } - - @Test - public void testGetInitialCreator() { + writeAndReload(); Assert.assertEquals(initialCreator, fMetadata.getInitialCreator()); } @Test - public void testSetDcCreator() { + public void testGetDcCreator() throws Exception { fMetadata.setCreator(dccreator); - } - - @Test - public void testGetDcCreator() { + writeAndReload(); Assert.assertEquals(dccreator, fMetadata.getCreator()); } @Test - public void testSetPrintedBy() { + public void testGetPrintedBy() throws Exception { fMetadata.setPrintedBy(printedBy); - } - - @Test - public void testGetPrintedBy() { + writeAndReload(); Assert.assertEquals(printedBy, fMetadata.getPrintedBy()); } @@ -153,8 +126,7 @@ public class OfficeMetaTest { public void testSetAndGetCreationDate() throws Exception { Calendar creationDate = Calendar.getInstance(); fMetadata.setCreationDate(creationDate); - tearDown(); - setUp(); + writeAndReload(); // //the millisecond lost while changing calendar to string // creationDate.clear(Calendar.MILLISECOND); // fMetadata.getCreationDate().clear(Calendar.MILLISECOND); @@ -169,8 +141,7 @@ public class OfficeMetaTest { public void testSetDcDate() throws Exception { Calendar dcDate = Calendar.getInstance(); fMetadata.setDcdate(dcDate); - tearDown(); - setUp(); + writeAndReload(); // dcDate.clear(Calendar.MILLISECOND); // fMetadata.getDcdate().clear(Calendar.MILLISECOND); // Assert.assertEquals(0,dcDate.compareTo(fMetadata.getDcdate())); @@ -183,8 +154,7 @@ public class OfficeMetaTest { public void testSetPrintDate() throws Exception { Calendar printDate = Calendar.getInstance(); fMetadata.setPrintDate(printDate); - tearDown(); - setUp(); + writeAndReload(); // printDate.clear(Calendar.MILLISECOND); // fMetadata.getPrintDate().clear(Calendar.MILLISECOND); // Assert.assertEquals(0,printDate.compareTo(fMetadata.getPrintDate())); @@ -194,32 +164,23 @@ public class OfficeMetaTest { } @Test - public void testSetLanguage() { + public void testGetLanguage() throws Exception { fMetadata.setLanguage(language); - } - - @Test - public void testGetLanguage() { + writeAndReload(); Assert.assertEquals(language, fMetadata.getLanguage()); } @Test - public void testSetEditingCycles() { + public void testGetEditingCycles() throws Exception { fMetadata.setEditingCycles(editingCycles); - } - - @Test - public void testGetEditingCycles() { + writeAndReload(); Assert.assertNotNull(fMetadata.getEditingCycles()); } @Test - public void testSetEditingDuration() { + public void testGetEditingDuration() throws Exception { fMetadata.setEditingDuration(editingDuration); - } - - @Test - public void testGetEditingDuration() { + writeAndReload(); Assert.assertNotNull(fMetadata.getEditingDuration()); } @@ -227,8 +188,7 @@ public class OfficeMetaTest { public void testEmptyKeyword() throws Exception { List emptyKeyword = new ArrayList(); fMetadata.setKeywords(emptyKeyword); - tearDown(); - setUp(); + writeAndReload(); Assert.assertNull(fMetadata.getKeywords()); } @@ -236,8 +196,7 @@ public class OfficeMetaTest { public void testAddKeyword() throws Exception { String newKeyword = "hello"; fMetadata.addKeyword(newKeyword); - tearDown(); - setUp(); + writeAndReload(); Assert.assertEquals(true, fMetadata.getKeywords().contains(newKeyword)); } @@ -264,9 +223,8 @@ public class OfficeMetaTest { "happy"); fMetadata.setUserDefinedData(names.get(2), Value.BOOLEAN.toString(), "false"); - tearDown(); - - setUp(); + writeAndReload(); + // test get Assert.assertEquals(names, fMetadata.getUserDefinedDataNames()); Assert.assertEquals(Value.STRING.toString(), fMetadata.getUserDefinedDataType(names.get(0))); @@ -276,21 +234,16 @@ public class OfficeMetaTest { fMetadata.setUserDefinedDataType(names.get(1), Value.BOOLEAN.toString()); fMetadata.setUserDefinedData(names.get(2), Value.STRING.toString(), "no"); - tearDown(); - - setUp(); + writeAndReload(); // update Assert.assertEquals("false", fMetadata.getUserDefinedDataValue(names.get(1))); Assert.assertEquals(Value.BOOLEAN.toString(), fMetadata.getUserDefinedDataType(names.get(1))); Assert.assertEquals("no", fMetadata.getUserDefinedDataValue(names.get(2))); Assert.assertEquals(Value.STRING.toString(), fMetadata.getUserDefinedDataType(names.get(2))); - tearDown(); - - setUp(); + writeAndReload(); // remove fMetadata.removeUserDefinedDataByName(names.get(0)); - tearDown(); - setUp(); + writeAndReload(); Assert.assertEquals(2, fMetadata.getUserDefinedDataNames().size()); } @@ -335,4 +288,14 @@ public class OfficeMetaTest { Assert.assertNotNull(meta.getLanguage()); textDoc.close(); } + + private void writeAndReload() throws Exception { + File persistedDocument = File.createTempFile(getClass().getName(), ".odt"); + persistedDocument.deleteOnExit(); + doc.save(persistedDocument); + doc = (TextDocument) TextDocument.loadDocument(persistedDocument); + metadom = doc.getMetaDom(); + fMetadata = new Meta(metadom); + } + }