aboutsummaryrefslogtreecommitdiffstats
path: root/src/excelant/testcases/org/apache
diff options
context:
space:
mode:
authorAndreas Beeker <kiwiwings@apache.org>2019-12-27 23:00:13 +0000
committerAndreas Beeker <kiwiwings@apache.org>2019-12-27 23:00:13 +0000
commitc66575c1e7059ed403b74b76e699200fdee507b4 (patch)
tree0fe96421471b53e9f72a2370ce76d61b49a659bc /src/excelant/testcases/org/apache
parent37282aae8f25970b157c40ae0888684f974ba666 (diff)
downloadpoi-c66575c1e7059ed403b74b76e699200fdee507b4.tar.gz
poi-c66575c1e7059ed403b74b76e699200fdee507b4.zip
Migrate all junit tests to Junit 4
get rid of references to junit.framework don't throw AssertionFailedErrors, but use Assert.fail instead add try-with-resources where it was missing git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1872041 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/excelant/testcases/org/apache')
-rw-r--r--src/excelant/testcases/org/apache/poi/ss/examples/formula/TestExcelAntUserDefinedFunction.java32
-rw-r--r--src/excelant/testcases/org/apache/poi/ss/excelant/BuildFileTest.java593
-rw-r--r--src/excelant/testcases/org/apache/poi/ss/excelant/TestBuildFile.java331
-rw-r--r--src/excelant/testcases/org/apache/poi/ss/excelant/TestExcelAntPrecision.java30
-rw-r--r--src/excelant/testcases/org/apache/poi/ss/excelant/TestExcelAntSet.java40
-rw-r--r--src/excelant/testcases/org/apache/poi/ss/excelant/TestExcelAntSetDoubleCell.java40
-rw-r--r--src/excelant/testcases/org/apache/poi/ss/excelant/util/TestExcelAntWorkbookUtil.java212
-rw-r--r--src/excelant/testcases/org/apache/poi/ss/excelant/util/TestExcelAntWorkbookUtilFactory.java28
8 files changed, 519 insertions, 787 deletions
diff --git a/src/excelant/testcases/org/apache/poi/ss/examples/formula/TestExcelAntUserDefinedFunction.java b/src/excelant/testcases/org/apache/poi/ss/examples/formula/TestExcelAntUserDefinedFunction.java
index ad9851ae8f..0606a8bd89 100644
--- a/src/excelant/testcases/org/apache/poi/ss/examples/formula/TestExcelAntUserDefinedFunction.java
+++ b/src/excelant/testcases/org/apache/poi/ss/examples/formula/TestExcelAntUserDefinedFunction.java
@@ -16,36 +16,42 @@
==================================================================== */
package org.apache.poi.ss.examples.formula;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestExcelAntUserDefinedFunction {
-public class TestExcelAntUserDefinedFunction extends TestCase {
-
private ExcelAntUserDefinedFunctionTestHelper fixture ;
-
- @Override
+
+ @Before
public void setUp() {
fixture = new ExcelAntUserDefinedFunctionTestHelper() ;
}
-
+
+ @Test
public void testSetClassName() {
String className = "simple.class.name" ;
-
+
fixture.setClassName( className ) ;
String value = fixture.getClassName() ;
-
+
assertNotNull( value ) ;
assertEquals( className, value ) ;
}
-
+
+ @Test
public void testSetFunction() {
String functionAlias = "alias" ;
-
+
fixture.setFunctionAlias( functionAlias ) ;
-
+
String alias = fixture.getFunctionAlias() ;
-
+
assertNotNull( alias ) ;
assertEquals( functionAlias, alias ) ;
}
-
+
}
diff --git a/src/excelant/testcases/org/apache/poi/ss/excelant/BuildFileTest.java b/src/excelant/testcases/org/apache/poi/ss/excelant/BuildFileTest.java
deleted file mode 100644
index a582a45ab3..0000000000
--- a/src/excelant/testcases/org/apache/poi/ss/excelant/BuildFileTest.java
+++ /dev/null
@@ -1,593 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.poi.ss.excelant;
-
-import static org.apache.poi.POITestCase.assertContains;
-import static org.apache.poi.POITestCase.assertNotContained;
-
-import java.io.File;
-import java.io.PrintStream;
-import java.net.URL;
-
-import junit.framework.TestCase;
-
-import org.apache.poi.POIDataSamples;
-import org.apache.tools.ant.BuildEvent;
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.BuildListener;
-import org.apache.tools.ant.Project;
-import org.apache.tools.ant.ProjectHelper;
-
-/**
- * A BuildFileTest is a TestCase which executes targets from an Ant buildfile
- * for testing.
- * <p>
- * This class provides a number of utility methods for particular build file
- * tests which extend this class.
- *
- * @see <a href="http://svn.apache.org/repos/asf/ant/core/trunk/src/tests/junit/org/apache/tools/ant/BuildFileTest.java">
- * http://svn.apache.org/repos/asf/ant/core/trunk/src/tests/junit/org/apache/tools/ant/BuildFileTest.java</a>
- */
-public abstract class BuildFileTest extends TestCase {
-
- protected Project project;
-
- private StringBuilder logBuffer;
- private StringBuilder fullLogBuffer;
- private StringBuilder outBuffer;
- private StringBuilder errBuffer;
- private BuildException buildException;
-
- /**
- * Default constructor for the BuildFileTest object.
- */
- public BuildFileTest() {
- super();
- }
-
- /**
- * Constructor for the BuildFileTest object.
- *
- * @param name string to pass up to TestCase constructor
- */
- public BuildFileTest(String name) {
- super(name);
- }
-
- /**
- * Automatically calls the target called "tearDown"
- * from the build file tested if it exits.
- * <p>
- * This allows to use Ant tasks directly in the build file
- * to clean up after each test. Note that no "setUp" target
- * is automatically called, since it's trivial to have a
- * test target depend on it.
- */
- @Override
- protected void tearDown() throws Exception {
- if (project == null) {
- /*
- * Maybe the BuildFileTest was subclassed and there is
- * no initialized project. So we could avoid getting a
- * NPE.
- * If there is an initialized project getTargets() does
- * not return null as it is initialized by an empty
- * HashSet.
- */
- return;
- }
- final String tearDown = "tearDown";
- if (project.getTargets().containsKey(tearDown)) {
- project.executeTarget(tearDown);
- }
- }
-
- /**
- * run a target, expect for any build exception
- *
- * @param target target to run
- * @param cause information string to reader of report
- */
- public void expectBuildException(String target, String cause) {
- expectSpecificBuildException(target, cause, null);
- }
-
- /**
- * Assert that only the given message has been logged with a
- * priority &lt;= INFO when running the given target.
- */
- public void expectLog(String target, String log) {
- executeTarget(target);
- String realLog = getLog();
- assertEquals(log, realLog);
- }
-
- /**
- * Assert that the given substring is in the log messages.
- */
- public void assertLogContaining(String substring) {
- assertContains(getLog(), substring);
- }
-
- /**
- * Assert that the given substring is not in the log messages.
- */
- public void assertLogNotContaining(String substring) {
- assertNotContained(getLog(), substring);
- }
-
- /**
- * Assert that the given substring is in the output messages.
- *
- * @since Ant1.7
- */
- public void assertOutputContaining(String substring) {
- assertOutputContaining(null, substring);
- }
-
- /**
- * Assert that the given substring is in the output messages.
- *
- * @param message Print this message if the test fails. Defaults to
- * a meaningful text if <tt>null</tt> is passed.
- * @since Ant1.7
- */
- public void assertOutputContaining(String message, String substring) {
- assertContains("output: " + message, getOutput(), substring);
- }
-
- /**
- * Assert that the given substring is not in the output messages.
- *
- * @param message Print this message if the test fails. Defaults to
- * a meaningful text if <tt>null</tt> is passed.
- * @since Ant1.7
- */
- public void assertOutputNotContaining(String message, String substring) {
- assertNotContained(getOutput(), substring);
- }
-
- /**
- * Assert that the given message has been logged with a priority &lt;= INFO when running the
- * given target.
- */
- public void expectLogContaining(String target, String log) {
- executeTarget(target);
- assertLogContaining(log);
- }
-
- /**
- * Assert that the given message has not been logged with a
- * priority &lt;= INFO when running the given target.
- */
- public void expectLogNotContaining(String target, String log) {
- executeTarget(target);
- assertLogNotContaining(log);
- }
-
- /**
- * Gets the log the BuildFileTest object.
- * Only valid if configureProject() has been called.
- *
- * @return The log value
- * @pre logBuffer!=null
- */
- public String getLog() {
- return logBuffer.toString();
- }
-
- /**
- * Assert that the given message has been logged with a priority
- * &gt;= VERBOSE when running the given target.
- */
- public void expectDebuglog(String target, String log) {
- executeTarget(target);
- String realLog = getFullLog();
- assertEquals(log, realLog);
- }
-
- /**
- * Assert that the given substring is in the log messages.
- */
- public void assertDebuglogContaining(String substring) {
- String realLog = getFullLog();
- assertContains("expecting debug log to contain \"" + substring
- + "\" log was \""
- + realLog + "\"",
- realLog, substring);
- }
-
- /**
- * Gets the log the BuildFileTest object.
- * <p>
- * Only valid if configureProject() has been called.
- *
- * @return The log value
- * @pre fullLogBuffer!=null
- */
- public String getFullLog() {
- return fullLogBuffer.toString();
- }
-
- /**
- * execute the target, verify output matches expectations
- *
- * @param target target to execute
- * @param output output to look for
- */
- public void expectOutput(String target, String output) {
- executeTarget(target);
- String realOutput = getOutput();
- assertEquals(output, realOutput.trim());
- }
-
- /**
- * Executes the target, verify output matches expectations
- * and that we got the named error at the end
- *
- * @param target target to execute
- * @param output output to look for
- * @param error Description of Parameter
- */
- public void expectOutputAndError(String target, String output, String error) {
- executeTarget(target);
- String realOutput = getOutput();
- assertEquals(output, realOutput);
- String realError = getError();
- assertEquals(error, realError);
- }
-
- public String getOutput() {
- return cleanBuffer(outBuffer);
- }
-
- public String getError() {
- return cleanBuffer(errBuffer);
- }
-
- public BuildException getBuildException() {
- return buildException;
- }
-
- private String cleanBuffer(StringBuilder buffer) {
- StringBuilder cleanedBuffer = new StringBuilder();
- for (int i = 0; i < buffer.length(); i++) {
- char ch = buffer.charAt(i);
- if (ch != '\r') {
- cleanedBuffer.append(ch);
- }
- }
- return cleanedBuffer.toString();
- }
-
- /**
- * Sets up to run the named project
- *
- * @param filename name of project file to run
- */
- public void configureProject(String filename) throws BuildException {
- configureProject(filename, Project.MSG_DEBUG);
- }
-
- /**
- * Sets up to run the named project
- *
- * @param filename name of project file to run
- */
- public void configureProject(String filename, int logLevel)
- throws BuildException {
- logBuffer = new StringBuilder();
- fullLogBuffer = new StringBuilder();
- project = new Project();
- project.init();
- project.setNewProperty("data.dir.name", getDataDir());
- File antFile = new File(System.getProperty("root"), filename);
- project.setUserProperty("ant.file", antFile.getAbsolutePath());
- project.addBuildListener(new AntTestListener(logLevel));
- ProjectHelper.configureProject(project, antFile);
- }
-
- /**
- * Executes a target we have set up
- *
- * @param targetName target to run
- * @pre configureProject has been called
- */
- public void executeTarget(String targetName) {
- PrintStream sysOut = System.out;
- PrintStream sysErr = System.err;
- try {
- sysOut.flush();
- sysErr.flush();
- outBuffer = new StringBuilder();
- PrintStream out = new PrintStream(new AntOutputStream(outBuffer));
- System.setOut(out);
- errBuffer = new StringBuilder();
- PrintStream err = new PrintStream(new AntOutputStream(errBuffer));
- System.setErr(err);
- logBuffer = new StringBuilder();
- fullLogBuffer = new StringBuilder();
- buildException = null;
- project.executeTarget(targetName);
- } finally {
- System.setOut(sysOut);
- System.setErr(sysErr);
- }
-
- }
-
- /**
- * Get the project which has been configured for a test.
- *
- * @return the Project instance for this test.
- */
- public Project getProject() {
- return project;
- }
-
- /**
- * Gets the directory of the project.
- *
- * @return the base dir of the project
- */
- public File getProjectDir() {
- return project.getBaseDir();
- }
-
- /**
- * Runs a target, wait for a build exception.
- *
- * @param target target to run
- * @param cause information string to reader of report
- * @param msg the message value of the build exception we are waiting
- * for set to null for any build exception to be valid
- */
- public void expectSpecificBuildException(String target, String cause, String msg) {
- try {
- executeTarget(target);
- } catch (org.apache.tools.ant.BuildException ex) {
- buildException = ex;
- if ((null != msg) && (!ex.getMessage().equals(msg))) {
- fail("Should throw BuildException because '" + cause
- + "' with message '" + msg
- + "' (actual message '" + ex.getMessage() + "' instead)");
- }
- return;
- }
- fail("Should throw BuildException because: " + cause);
- }
-
- /**
- * run a target, expect an exception string
- * containing the substring we look for (case sensitive match)
- *
- * @param target target to run
- * @param cause information string to reader of report
- * @param contains substring of the build exception to look for
- */
- public void expectBuildExceptionContaining(String target, String cause, String contains) {
- try {
- executeTarget(target);
- } catch (org.apache.tools.ant.BuildException ex) {
- buildException = ex;
- if ((null != contains) && (!ex.getMessage().contains(contains))) {
- fail("Should throw BuildException because '" + cause + "' with message containing '" + contains + "' (actual message '" + ex.getMessage() + "' instead)");
- }
- return;
- }
- fail("Should throw BuildException because: " + cause);
- }
-
- /**
- * call a target, verify property is as expected
- *
- * @param target build file target
- * @param property property name
- * @param value expected value
- */
- public void expectPropertySet(String target, String property, String value) {
- executeTarget(target);
- assertPropertyEquals(property, value);
- }
-
- /**
- * assert that a property equals a value; comparison is case sensitive.
- *
- * @param property property name
- * @param value expected value
- */
- public void assertPropertyEquals(String property, String value) {
- String result = project.getProperty(property);
- assertEquals("property " + property, value, result);
- }
-
- /**
- * assert that a property equals "true".
- *
- * @param property property name
- */
- public void assertPropertySet(String property) {
- assertPropertyEquals(property, "true");
- }
-
- /**
- * assert that a property is null.
- *
- * @param property property name
- */
- public void assertPropertyUnset(String property) {
- String result = project.getProperty(property);
- if (result != null) {
- fail("Expected property " + property
- + " to be unset, but it is set to the value: " + result);
- }
- }
-
- /**
- * call a target, verify named property is "true".
- *
- * @param target build file target
- * @param property property name
- */
- public void expectPropertySet(String target, String property) {
- expectPropertySet(target, property, "true");
- }
-
- /**
- * Call a target, verify property is null.
- *
- * @param target build file target
- * @param property property name
- */
- public void expectPropertyUnset(String target, String property) {
- expectPropertySet(target, property, null);
- }
-
- /**
- * Retrieve a resource from the caller classloader to avoid
- * assuming a vm working directory. The resource path must be
- * relative to the package name or absolute from the root path.
- *
- * @param resource the resource to retrieve its url.
- * @throws junit.framework.AssertionFailedError
- * if the resource is not found.
- */
- public URL getResource(String resource) {
- URL url = getClass().getResource(resource);
- assertNotNull("Could not find resource :" + resource, url);
- return url;
- }
-
- public static String getDataDir() {
- String dataDirName = System.getProperty(POIDataSamples.TEST_PROPERTY);
- return dataDirName == null ? "test-data" : dataDirName;
- }
-
- /**
- * an output stream which saves stuff to our buffer.
- */
- protected static class AntOutputStream extends java.io.OutputStream {
- private StringBuilder buffer;
-
- public AntOutputStream(StringBuilder buffer) {
- this.buffer = buffer;
- }
-
- @Override
- public void write(int b) {
- buffer.append((char) b);
- }
- }
-
- /**
- * Our own personal build listener.
- */
- private class AntTestListener implements BuildListener {
- private int logLevel;
-
- /**
- * Constructs a test listener which will ignore log events
- * above the given level.
- */
- public AntTestListener(int logLevel) {
- this.logLevel = logLevel;
- }
-
- /**
- * Fired before any targets are started.
- */
- @Override
- public void buildStarted(BuildEvent event) {
- }
-
- /**
- * Fired after the last target has finished. This event
- * will still be thrown if an error occurred during the build.
- *
- * @see BuildEvent#getException()
- */
- @Override
- public void buildFinished(BuildEvent event) {
- }
-
- /**
- * Fired when a target is started.
- *
- * @see BuildEvent#getTarget()
- */
- @Override
- public void targetStarted(BuildEvent event) {
- //System.out.println("targetStarted " + event.getTarget().getName());
- }
-
- /**
- * Fired when a target has finished. This event will
- * still be thrown if an error occurred during the build.
- *
- * @see BuildEvent#getException()
- */
- @Override
- public void targetFinished(BuildEvent event) {
- //System.out.println("targetFinished " + event.getTarget().getName());
- }
-
- /**
- * Fired when a task is started.
- *
- * @see BuildEvent#getTask()
- */
- @Override
- public void taskStarted(BuildEvent event) {
- //System.out.println("taskStarted " + event.getTask().getTaskName());
- }
-
- /**
- * Fired when a task has finished. This event will still
- * be throw if an error occurred during the build.
- *
- * @see BuildEvent#getException()
- */
- @Override
- public void taskFinished(BuildEvent event) {
- //System.out.println("taskFinished " + event.getTask().getTaskName());
- }
-
- /**
- * Fired whenever a message is logged.
- *
- * @see BuildEvent#getMessage()
- * @see BuildEvent#getPriority()
- */
- @Override
- public void messageLogged(BuildEvent event) {
- if (event.getPriority() > logLevel) {
- // ignore event
- return;
- }
-
- if (event.getPriority() == Project.MSG_INFO ||
- event.getPriority() == Project.MSG_WARN ||
- event.getPriority() == Project.MSG_ERR) {
- logBuffer.append(event.getMessage());
- }
- fullLogBuffer.append(event.getMessage());
- }
- }
-
-}
diff --git a/src/excelant/testcases/org/apache/poi/ss/excelant/TestBuildFile.java b/src/excelant/testcases/org/apache/poi/ss/excelant/TestBuildFile.java
index 7d55c52767..af9e317a42 100644
--- a/src/excelant/testcases/org/apache/poi/ss/excelant/TestBuildFile.java
+++ b/src/excelant/testcases/org/apache/poi/ss/excelant/TestBuildFile.java
@@ -15,105 +15,384 @@
* limitations under the License.
*
*/
+
package org.apache.poi.ss.excelant;
+import static org.apache.poi.POITestCase.assertContains;
+import static org.apache.poi.POITestCase.assertNotContained;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.io.PrintStream;
+
+import org.apache.poi.POIDataSamples;
+import org.apache.tools.ant.BuildEvent;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.BuildListener;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.ProjectHelper;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
/**
* JUnit test for the ExcelAnt tasks.
* Leverages Ant's test framework.
- *
- * @see <a href="http://svn.apache.org/repos/asf/ant/core/trunk/src/tests/junit/org/apache/tools/ant/BuildFileTest.java">
- * http://svn.apache.org/repos/asf/ant/core/trunk/src/tests/junit/org/apache/tools/ant/BuildFileTest.java</a>
*/
-public class TestBuildFile extends BuildFileTest {
+public class TestBuildFile {
+
+ protected Project project;
+
+ private StringBuilder logBuffer;
+ private StringBuilder fullLogBuffer;
+ private BuildException buildException;
+
- @Override
+ @Before
public void setUp() {
- configureProject(BuildFileTest.getDataDir() + "/../src/excelant/testcases/org/apache/poi/ss/excelant/tests.xml");
+ String filename = TestBuildFile.getDataDir() + "/../src/excelant/testcases/org/apache/poi/ss/excelant/tests.xml";
+ int logLevel = Project.MSG_DEBUG;
+
+ logBuffer = new StringBuilder();
+ fullLogBuffer = new StringBuilder();
+ project = new Project();
+ project.init();
+ project.setNewProperty("data.dir.name", getDataDir());
+ File antFile = new File(System.getProperty("root"), filename);
+ project.setUserProperty("ant.file", antFile.getAbsolutePath());
+ project.addBuildListener(new AntTestListener(logLevel));
+ ProjectHelper.configureProject(project, antFile);
+
+ }
+
+ /**
+ * Automatically calls the target called "tearDown"
+ * from the build file tested if it exits.
+ * <p>
+ * This allows to use Ant tasks directly in the build file
+ * to clean up after each test. Note that no "setUp" target
+ * is automatically called, since it's trivial to have a
+ * test target depend on it.
+ */
+ @After
+ public void tearDown() {
+ if (project == null) {
+ /*
+ * Maybe the BuildFileTest was subclassed and there is
+ * no initialized project. So we could avoid getting a
+ * NPE.
+ * If there is an initialized project getTargets() does
+ * not return null as it is initialized by an empty
+ * HashSet.
+ */
+ return;
+ }
+ final String tearDown = "tearDown";
+ if (project.getTargets().containsKey(tearDown)) {
+ project.executeTarget(tearDown);
+ }
+ }
+
+ /**
+ * run a target, expect for any build exception
+ *
+ * @param target target to run
+ * @param cause information string to reader of report
+ */
+ public void expectBuildException(String target, String cause) {
+ expectSpecificBuildException(target, cause, null);
}
+ /**
+ * Assert that the given substring is in the log messages.
+ */
+ public void assertLogContaining(String substring) {
+ assertContains(getLog(), substring);
+ }
+
+ /**
+ * Assert that the given substring is not in the log messages.
+ */
+ public void assertLogNotContaining(String substring) {
+ assertNotContained(getLog(), substring);
+ }
+
+ /**
+ * Gets the log the BuildFileTest object.
+ * Only valid if configureProject() has been called.
+ *
+ * @return The log value
+ */
+ public String getLog() {
+ return logBuffer.toString();
+ }
+
+ /**
+ * Executes a target we have set up
+ *
+ * @param targetName target to run
+ */
+ public void executeTarget(String targetName) {
+ PrintStream sysOut = System.out;
+ PrintStream sysErr = System.err;
+ try {
+ sysOut.flush();
+ sysErr.flush();
+ StringBuilder outBuffer = new StringBuilder();
+ PrintStream out = new PrintStream(new AntOutputStream(outBuffer));
+ System.setOut(out);
+ StringBuilder errBuffer = new StringBuilder();
+ PrintStream err = new PrintStream(new AntOutputStream(errBuffer));
+ System.setErr(err);
+ logBuffer = new StringBuilder();
+ fullLogBuffer = new StringBuilder();
+ buildException = null;
+ project.executeTarget(targetName);
+ } finally {
+ System.setOut(sysOut);
+ System.setErr(sysErr);
+ }
+
+ }
+
+ /**
+ * Runs a target, wait for a build exception.
+ *
+ * @param target target to run
+ * @param cause information string to reader of report
+ * @param msg the message value of the build exception we are waiting
+ * for set to null for any build exception to be valid
+ */
+ public void expectSpecificBuildException(String target, String cause, String msg) {
+ try {
+ executeTarget(target);
+ } catch (org.apache.tools.ant.BuildException ex) {
+ buildException = ex;
+ if ((null != msg) && (!ex.getMessage().equals(msg))) {
+ fail("Should throw BuildException because '" + cause
+ + "' with message '" + msg
+ + "' (actual message '" + ex.getMessage() + "' instead)");
+ }
+ return;
+ }
+ fail("Should throw BuildException because: " + cause);
+ }
+
+ public static String getDataDir() {
+ String dataDirName = System.getProperty(POIDataSamples.TEST_PROPERTY);
+ return dataDirName == null ? "test-data" : dataDirName;
+ }
+
+ /**
+ * an output stream which saves stuff to our buffer.
+ */
+ protected static class AntOutputStream extends java.io.OutputStream {
+ private StringBuilder buffer;
+
+ public AntOutputStream(StringBuilder buffer) {
+ this.buffer = buffer;
+ }
+
+ @Override
+ public void write(int b) {
+ buffer.append((char) b);
+ }
+ }
+
+ /**
+ * Our own personal build listener.
+ */
+ private class AntTestListener implements BuildListener {
+ private int logLevel;
+
+ /**
+ * Constructs a test listener which will ignore log events
+ * above the given level.
+ */
+ public AntTestListener(int logLevel) {
+ this.logLevel = logLevel;
+ }
+
+ /**
+ * Fired before any targets are started.
+ */
+ @Override
+ public void buildStarted(BuildEvent event) {
+ }
+
+ /**
+ * Fired after the last target has finished. This event
+ * will still be thrown if an error occurred during the build.
+ *
+ * @see BuildEvent#getException()
+ */
+ @Override
+ public void buildFinished(BuildEvent event) {
+ }
+
+ /**
+ * Fired when a target is started.
+ *
+ * @see BuildEvent#getTarget()
+ */
+ @Override
+ public void targetStarted(BuildEvent event) {
+ //System.out.println("targetStarted " + event.getTarget().getName());
+ }
+
+ /**
+ * Fired when a target has finished. This event will
+ * still be thrown if an error occurred during the build.
+ *
+ * @see BuildEvent#getException()
+ */
+ @Override
+ public void targetFinished(BuildEvent event) {
+ //System.out.println("targetFinished " + event.getTarget().getName());
+ }
+
+ /**
+ * Fired when a task is started.
+ *
+ * @see BuildEvent#getTask()
+ */
+ @Override
+ public void taskStarted(BuildEvent event) {
+ //System.out.println("taskStarted " + event.getTask().getTaskName());
+ }
+
+ /**
+ * Fired when a task has finished. This event will still
+ * be throw if an error occurred during the build.
+ *
+ * @see BuildEvent#getException()
+ */
+ @Override
+ public void taskFinished(BuildEvent event) {
+ //System.out.println("taskFinished " + event.getTask().getTaskName());
+ }
+
+ /**
+ * Fired whenever a message is logged.
+ *
+ * @see BuildEvent#getMessage()
+ * @see BuildEvent#getPriority()
+ */
+ @Override
+ public void messageLogged(BuildEvent event) {
+ if (event.getPriority() > logLevel) {
+ // ignore event
+ return;
+ }
+
+ if (event.getPriority() == Project.MSG_INFO ||
+ event.getPriority() == Project.MSG_WARN ||
+ event.getPriority() == Project.MSG_ERR) {
+ logBuffer.append(event.getMessage());
+ }
+ fullLogBuffer.append(event.getMessage());
+ }
+ }
+
+ @Test
public void testMissingFilename() {
expectSpecificBuildException("test-nofile", "required argument not specified",
- "fileName attribute must be set!");
- }
+ "fileName attribute must be set!");
+ }
+ @Test
public void testFileNotFound() {
expectSpecificBuildException("test-filenotfound", "required argument not specified",
- "Cannot load file invalid.xls. Make sure the path and file permissions are correct.");
- }
+ "Cannot load file invalid.xls. Make sure the path and file permissions are correct.");
+ }
+ @Test
public void testEvaluate() {
executeTarget("test-evaluate");
- assertLogContaining("Using input file: " + BuildFileTest.getDataDir() + "/spreadsheet/excelant.xls");
+ assertLogContaining("Using input file: " + TestBuildFile.getDataDir() + "/spreadsheet/excelant.xls");
assertLogContaining("Succeeded when evaluating 'MortgageCalculator'!$B$4.");
}
+ @Test
public void testEvaluateNoDetails() {
executeTarget("test-evaluate-nodetails");
- assertLogContaining("Using input file: " + BuildFileTest.getDataDir() + "/spreadsheet/excelant.xls");
+ assertLogContaining("Using input file: " + TestBuildFile.getDataDir() + "/spreadsheet/excelant.xls");
assertLogNotContaining("Succeeded when evaluating 'MortgageCalculator'!$B$4.");
}
+ @Test
public void testPrecision() {
executeTarget("test-precision");
- assertLogContaining("Using input file: " + BuildFileTest.getDataDir() + "/spreadsheet/excelant.xls");
+ assertLogContaining("Using input file: " + TestBuildFile.getDataDir() + "/spreadsheet/excelant.xls");
assertLogContaining("Succeeded when evaluating 'MortgageCalculator'!$B$4. " +
- "It evaluated to 2285.5761494145563 when the value of 2285.576149 with precision of 1.0E-4");
+ "It evaluated to 2285.5761494145563 when the value of 2285.576149 with precision of 1.0E-4");
assertLogContaining("Succeeded when evaluating 'MortgageCalculator'!$B$4. " +
- "It evaluated to 2285.5761494145563 when the value of 2285.576149 with precision of 1.0E-5");
+ "It evaluated to 2285.5761494145563 when the value of 2285.576149 with precision of 1.0E-5");
assertLogContaining("Failed to evaluate cell 'MortgageCalculator'!$B$4. " +
- "It evaluated to 2285.5761494145563 when the value of 2285.576149 with precision of 1.0E-10 was expected.");
+ "It evaluated to 2285.5761494145563 when the value of 2285.576149 with precision of 1.0E-10 was expected.");
assertLogContaining("2/3 tests passed");
}
+ @Test
public void testPrecisionFail() {
expectSpecificBuildException("test-precision-fails", "precision not matched",
- "\tFailed to evaluate cell 'MortgageCalculator'!$B$4. It evaluated to 2285.5761494145563 when the value of 2285.576149 with precision of 1.0E-10 was expected.");
+ "\tFailed to evaluate cell 'MortgageCalculator'!$B$4. It evaluated to 2285.5761494145563 when the value of 2285.576149 with precision of 1.0E-10 was expected.");
}
+ @Test
public void testPassOnError() {
executeTarget("test-passonerror");
}
+ @Test
public void testFailOnError() {
expectBuildException("test-failonerror", "fail on error");
- assertLogContaining("Using input file: " + BuildFileTest.getDataDir() + "/spreadsheet/excelant.xls");
+ assertLogContaining("Using input file: " + TestBuildFile.getDataDir() + "/spreadsheet/excelant.xls");
assertLogNotContaining("failed because 1 of 0 evaluations failed to evaluate correctly. Failed to evaluate cell 'MortageCalculatorFunction'!$D$3");
}
+ @Test
public void testFailOnErrorNoDetails() {
expectBuildException("test-failonerror-nodetails", "fail on error");
- assertLogNotContaining("Using input file: " + BuildFileTest.getDataDir() + "/spreadsheet/excelant.xls");
+ assertLogNotContaining("Using input file: " + TestBuildFile.getDataDir() + "/spreadsheet/excelant.xls");
assertLogNotContaining("failed because 1 of 0 evaluations failed to evaluate correctly. Failed to evaluate cell 'MortageCalculatorFunction'!$D$3");
}
+ @Test
public void testUdf() {
executeTarget("test-udf");
assertLogContaining("1/1 tests passed");
}
-
+
+ @Test
public void testSetText() {
executeTarget("test-settext");
assertLogContaining("1/1 tests passed");
}
-
+
+ @Test
public void testAddHandler() {
executeTarget("test-addhandler");
- assertLogContaining("Using input file: " + BuildFileTest.getDataDir() + "/spreadsheet/excelant.xls");
+ assertLogContaining("Using input file: " + TestBuildFile.getDataDir() + "/spreadsheet/excelant.xls");
assertLogContaining("Succeeded when evaluating 'MortgageCalculator'!$B$4.");
-
+
assertNotNull("The workbook should have been passed to the handler", MockExcelAntWorkbookHandler.workbook);
assertTrue("The handler should have been executed", MockExcelAntWorkbookHandler.executed);
}
-
+
+ @Test
public void testAddHandlerWrongClass() {
executeTarget("test-addhandler-wrongclass");
- assertLogContaining("Using input file: " + BuildFileTest.getDataDir() + "/spreadsheet/excelant.xls");
+ assertLogContaining("Using input file: " + TestBuildFile.getDataDir() + "/spreadsheet/excelant.xls");
assertLogContaining("Succeeded when evaluating 'MortgageCalculator'!$B$4.");
}
-
+
+ @Test
public void testAddHandlerFails() {
expectSpecificBuildException("test-addhandler-fails", "NullPointException", null);
}
+
}
diff --git a/src/excelant/testcases/org/apache/poi/ss/excelant/TestExcelAntPrecision.java b/src/excelant/testcases/org/apache/poi/ss/excelant/TestExcelAntPrecision.java
index 0c6f9cbf83..d815bcf161 100644
--- a/src/excelant/testcases/org/apache/poi/ss/excelant/TestExcelAntPrecision.java
+++ b/src/excelant/testcases/org/apache/poi/ss/excelant/TestExcelAntPrecision.java
@@ -16,32 +16,38 @@
==================================================================== */
package org.apache.poi.ss.excelant;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestExcelAntPrecision {
-public class TestExcelAntPrecision extends TestCase {
-
private ExcelAntPrecision fixture ;
- @Override
+ @Before
public void setUp() {
fixture = new ExcelAntPrecision() ;
}
-
- @Override
+
+ @After
public void tearDown() {
fixture = null ;
}
-
+
+ @Test
public void testVerifyPrecision() {
-
+
double value = 1.0E-1 ;
-
+
fixture.setValue( value ) ;
-
+
double result = fixture.getValue() ;
-
+
assertTrue( result > 0 ) ;
-
+
assertEquals( value, result, 0.0 ) ;
}
diff --git a/src/excelant/testcases/org/apache/poi/ss/excelant/TestExcelAntSet.java b/src/excelant/testcases/org/apache/poi/ss/excelant/TestExcelAntSet.java
index b59c886ae9..abf3a799ed 100644
--- a/src/excelant/testcases/org/apache/poi/ss/excelant/TestExcelAntSet.java
+++ b/src/excelant/testcases/org/apache/poi/ss/excelant/TestExcelAntSet.java
@@ -16,48 +16,54 @@
==================================================================== */
package org.apache.poi.ss.excelant;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import org.apache.poi.ss.excelant.util.ExcelAntWorkbookUtil;
import org.apache.poi.ss.excelant.util.ExcelAntWorkbookUtilFactory;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
-public class TestExcelAntSet extends TestCase {
+public class TestExcelAntSet {
-
- // This is abstract in nature, so we'll use a
+
+ // This is abstract in nature, so we'll use a
// concrete instance to test the set methods.
private ExcelAntSet fixture ;
-
+
private static final String mortgageCalculatorFileName =
- BuildFileTest.getDataDir() + "/spreadsheet/mortgage-calculation.xls" ;
-
- @Override
+ TestBuildFile.getDataDir() + "/spreadsheet/mortgage-calculation.xls" ;
+
+ @Before
public void setUp() {
fixture = new ExcelAntSetDoubleCell() ;
}
-
- @Override
+
+ @After
public void tearDown() {
fixture = null ;
}
-
+
+ @Test
public void testSetter() {
String cell = "simpleCellRef!$F$1" ;
-
+
fixture.setCell( cell ) ;
-
+
String cellStr = fixture.getCell() ;
-
+
assertNotNull( cellStr ) ;
assertEquals( cell, cellStr ) ;
}
-
+
+ @Test
public void testSetWorkbookUtil() {
ExcelAntWorkbookUtil util = ExcelAntWorkbookUtilFactory.getInstance(
mortgageCalculatorFileName ) ;
-
+
assertNotNull( util ) ;
-
+
fixture.setWorkbookUtil( util ) ;
}
}
diff --git a/src/excelant/testcases/org/apache/poi/ss/excelant/TestExcelAntSetDoubleCell.java b/src/excelant/testcases/org/apache/poi/ss/excelant/TestExcelAntSetDoubleCell.java
index 3d5b11ef49..be30f7a64e 100644
--- a/src/excelant/testcases/org/apache/poi/ss/excelant/TestExcelAntSetDoubleCell.java
+++ b/src/excelant/testcases/org/apache/poi/ss/excelant/TestExcelAntSetDoubleCell.java
@@ -16,51 +16,55 @@
==================================================================== */
package org.apache.poi.ss.excelant;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import org.apache.poi.ss.excelant.util.ExcelAntWorkbookUtil;
import org.apache.poi.ss.excelant.util.ExcelAntWorkbookUtilFactory;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestExcelAntSetDoubleCell {
-public class TestExcelAntSetDoubleCell extends TestCase {
-
private ExcelAntSetDoubleCell fixture ;
-
+
private ExcelAntWorkbookUtil util ;
private static final String mortgageCalculatorFileName =
- BuildFileTest.getDataDir() + "/spreadsheet/mortgage-calculation.xls" ;
+ TestBuildFile.getDataDir() + "/spreadsheet/mortgage-calculation.xls" ;
- @Override
+ @Before
public void setUp() {
fixture = new ExcelAntSetDoubleCell() ;
- util = ExcelAntWorkbookUtilFactory.getInstance(
- mortgageCalculatorFileName ) ;
+ util = ExcelAntWorkbookUtilFactory.getInstance(mortgageCalculatorFileName ) ;
fixture.setWorkbookUtil( util ) ;
}
-
- @Override
+
+ @After
public void tearDown() {
fixture = null ;
}
-
+
+ @Test
public void testSetDouble() {
String cellId = "'Sheet3'!$A$1" ;
double testValue = 1.1 ;
-
+
fixture.setCell( cellId ) ;
fixture.setValue( testValue ) ;
-
+
double value = fixture.getCellValue() ;
-
+
assertTrue( value > 0 ) ;
assertEquals( testValue, value, 0.0 ) ;
-
+
fixture.execute() ;
-
+
double setValue = util.getCellAsDouble( cellId ) ;
-
+
assertEquals( setValue, testValue, 0.0 ) ;
}
-
+
}
diff --git a/src/excelant/testcases/org/apache/poi/ss/excelant/util/TestExcelAntWorkbookUtil.java b/src/excelant/testcases/org/apache/poi/ss/excelant/util/TestExcelAntWorkbookUtil.java
index 6f25cb3d3b..3771405cb6 100644
--- a/src/excelant/testcases/org/apache/poi/ss/excelant/util/TestExcelAntWorkbookUtil.java
+++ b/src/excelant/testcases/org/apache/poi/ss/excelant/util/TestExcelAntWorkbookUtil.java
@@ -16,6 +16,13 @@
==================================================================== */
package org.apache.poi.ss.excelant.util;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
@@ -23,166 +30,178 @@ import java.util.Date;
import java.util.List;
import org.apache.poi.ss.examples.formula.CalculateMortgageFunction;
-import org.apache.poi.ss.excelant.BuildFileTest;
+import org.apache.poi.ss.excelant.TestBuildFile;
import org.apache.poi.ss.formula.udf.UDFFinder;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.apache.tools.ant.BuildException;
+import org.junit.After;
+import org.junit.Test;
-import junit.framework.TestCase;
+public class TestExcelAntWorkbookUtil {
-public class TestExcelAntWorkbookUtil extends TestCase {
-
private static final String mortgageCalculatorFileName =
- BuildFileTest.getDataDir() + "/spreadsheet/excelant.xls" ;
+ TestBuildFile.getDataDir() + "/spreadsheet/excelant.xls" ;
private ExcelAntWorkbookUtilTestHelper fixture ;
-
-
- @Override
+
+
+ @After
public void tearDown() {
fixture = null ;
}
+ @Test
public void testStringConstructor() {
- fixture = new ExcelAntWorkbookUtilTestHelper(
- mortgageCalculatorFileName);
-
+ fixture = new ExcelAntWorkbookUtilTestHelper(mortgageCalculatorFileName);
+
assertNotNull(fixture);
}
+ @Test
public void testLoadNotExistingFile() {
try {
new ExcelAntWorkbookUtilTestHelper("notexistingFile");
fail("Should catch exception here");
} catch (BuildException e) {
- assertTrue(e.getMessage().contains("notexistingFile"));
+ assertTrue(e.getMessage().contains("notexistingFile"));
}
}
-
+
+ @Test
public void testWorkbookConstructor() throws IOException {
File workbookFile = new File(mortgageCalculatorFileName);
FileInputStream fis = new FileInputStream(workbookFile);
Workbook workbook = WorkbookFactory.create(fis);
fixture = new ExcelAntWorkbookUtilTestHelper(workbook);
-
+
assertNotNull(fixture);
}
-
+
+ @Test
public void testAddFunction() {
fixture = new ExcelAntWorkbookUtilTestHelper(
mortgageCalculatorFileName);
assertNotNull(fixture);
-
+
fixture.addFunction("h2_ZFactor", new CalculateMortgageFunction());
-
+
UDFFinder functions = fixture.getFunctions();
-
+
assertNotNull(functions);
assertNotNull(functions.findFunction("h2_ZFactor"));
}
+ @Test
public void testAddFunctionClassName() throws Exception {
fixture = new ExcelAntWorkbookUtilTestHelper(
mortgageCalculatorFileName);
assertNotNull(fixture);
-
+
fixture.addFunction("h2_ZFactor", CalculateMortgageFunction.class.getName());
-
+
UDFFinder functions = fixture.getFunctions();
-
+
assertNotNull(functions);
assertNotNull(functions.findFunction("h2_ZFactor"));
}
+ @Test
public void testAddFunctionInvalidClassName() throws Exception {
fixture = new ExcelAntWorkbookUtilTestHelper(
mortgageCalculatorFileName);
assertNotNull(fixture);
-
+
fixture.addFunction("h2_ZFactor", String.class.getName());
-
+
UDFFinder functions = fixture.getFunctions();
-
+
assertNotNull(functions);
assertNull(functions.findFunction("h2_ZFactor"));
}
+ @Test
public void testGetWorkbook() {
fixture = new ExcelAntWorkbookUtilTestHelper(
mortgageCalculatorFileName);
-
+
assertNotNull(fixture);
-
+
Workbook workbook = fixture.getWorkbook();
-
+
assertNotNull(workbook);
}
-
+
+ @Test
public void testFileName() {
fixture = new ExcelAntWorkbookUtilTestHelper(
mortgageCalculatorFileName);
-
+
assertNotNull(fixture);
String fileName = fixture.getFileName();
-
+
assertNotNull(fileName);
-
+
assertEquals(mortgageCalculatorFileName, fileName);
-
+
}
-
+
+ @Test
public void testGetEvaluator() {
fixture = new ExcelAntWorkbookUtilTestHelper(
mortgageCalculatorFileName);
-
+
FormulaEvaluator evaluator = fixture.getEvaluator(
mortgageCalculatorFileName);
-
+
assertNotNull(evaluator);
}
+ @Test
public void testGetEvaluatorWithUDF() {
fixture = new ExcelAntWorkbookUtilTestHelper(
mortgageCalculatorFileName);
fixture.addFunction("h2_ZFactor", new CalculateMortgageFunction());
-
+
FormulaEvaluator evaluator = fixture.getEvaluator(
mortgageCalculatorFileName);
-
+
assertNotNull(evaluator);
}
-
+
+ @Test
public void testGetEvaluatorXLSX() {
fixture = new ExcelAntWorkbookUtilTestHelper(
- BuildFileTest.getDataDir() + "/spreadsheet/sample.xlsx");
-
+ TestBuildFile.getDataDir() + "/spreadsheet/sample.xlsx");
+
FormulaEvaluator evaluator = fixture.getEvaluator(
- BuildFileTest.getDataDir() + "/spreadsheet/sample.xlsx");
-
+ TestBuildFile.getDataDir() + "/spreadsheet/sample.xlsx");
+
assertNotNull(evaluator);
}
+ @Test
public void testGetEvaluatorXLSXWithFunction() {
fixture = new ExcelAntWorkbookUtilTestHelper(
- BuildFileTest.getDataDir() + "/spreadsheet/sample.xlsx");
-
+ TestBuildFile.getDataDir() + "/spreadsheet/sample.xlsx");
+
fixture.addFunction("h2_ZFactor", new CalculateMortgageFunction());
-
+
FormulaEvaluator evaluator = fixture.getEvaluator(
- BuildFileTest.getDataDir() + "/spreadsheet/sample.xlsx");
-
+ TestBuildFile.getDataDir() + "/spreadsheet/sample.xlsx");
+
assertNotNull(evaluator);
}
+ @Test
public void testEvaluateCell() {
String cell = "'MortgageCalculator'!B4" ;
double expectedValue = 790.79 ;
@@ -191,8 +210,8 @@ public class TestExcelAntWorkbookUtil extends TestCase {
fixture = new ExcelAntWorkbookUtilTestHelper(
mortgageCalculatorFileName);
- ExcelAntEvaluationResult result = fixture.evaluateCell(cell,
- expectedValue,
+ ExcelAntEvaluationResult result = fixture.evaluateCell(cell,
+ expectedValue,
precision);
//System.out.println(result);
@@ -204,7 +223,8 @@ public class TestExcelAntWorkbookUtil extends TestCase {
assertFalse(result.evaluationCompleteWithError());
assertTrue(result.didTestPass());
}
-
+
+ @Test
public void testEvaluateCellFailedPrecision() {
String cell = "'MortgageCalculator'!B4" ;
double expectedValue = 790.79 ;
@@ -213,8 +233,8 @@ public class TestExcelAntWorkbookUtil extends TestCase {
fixture = new ExcelAntWorkbookUtilTestHelper(
mortgageCalculatorFileName);
- ExcelAntEvaluationResult result = fixture.evaluateCell(cell,
- expectedValue,
+ ExcelAntEvaluationResult result = fixture.evaluateCell(cell,
+ expectedValue,
precision);
//System.out.println(result);
@@ -226,7 +246,8 @@ public class TestExcelAntWorkbookUtil extends TestCase {
assertFalse(result.evaluationCompleteWithError());
assertFalse(result.didTestPass());
}
-
+
+ @Test
public void testEvaluateCellWithError() {
String cell = "'ErrorCell'!A1" ;
double expectedValue = 790.79 ;
@@ -235,8 +256,8 @@ public class TestExcelAntWorkbookUtil extends TestCase {
fixture = new ExcelAntWorkbookUtilTestHelper(
mortgageCalculatorFileName);
- ExcelAntEvaluationResult result = fixture.evaluateCell(cell,
- expectedValue,
+ ExcelAntEvaluationResult result = fixture.evaluateCell(cell,
+ expectedValue,
precision);
System.out.println(result);
@@ -248,35 +269,38 @@ public class TestExcelAntWorkbookUtil extends TestCase {
assertTrue(result.evaluationCompleteWithError());
assertFalse(result.didTestPass());
}
-
+
+ @Test
public void testGetSheets() {
fixture = new ExcelAntWorkbookUtilTestHelper(
mortgageCalculatorFileName);
-
+
List<String> sheets = fixture.getSheets();
-
+
assertNotNull(sheets);
- assertEquals(sheets.size(), 3);
+ assertEquals(sheets.size(), 3);
}
-
+
+ @Test
public void testSetString() {
String cell = "'MortgageCalculator'!C14" ;
String cellValue = "testString" ;
-
+
fixture = new ExcelAntWorkbookUtilTestHelper(
mortgageCalculatorFileName);
-
+
fixture.setStringValue(cell, cellValue);
-
+
String value = fixture.getCellAsString(cell);
-
+
assertNotNull(value);
assertEquals(cellValue, value);
}
-
+
+ @Test
public void testSetNotExistingSheet() {
String cell = "'NotexistingSheet'!C14" ;
-
+
fixture = new ExcelAntWorkbookUtilTestHelper(
mortgageCalculatorFileName);
try {
@@ -287,68 +311,72 @@ public class TestExcelAntWorkbookUtil extends TestCase {
}
}
+ @Test
public void testSetFormula() {
String cell = "'MortgageCalculator'!C14" ;
String cellValue = "SUM(B14:B18)" ;
-
+
fixture = new ExcelAntWorkbookUtilTestHelper(
mortgageCalculatorFileName);
-
+
fixture.setFormulaValue(cell, cellValue);
-
+
double value = fixture.getCellAsDouble(cell);
-
- assertEquals(0.0, value);
+
+ assertEquals(0.0, value, 0);
}
-
+
+ @Test
public void testSetDoubleValue() {
String cell = "'MortgageCalculator'!C14" ;
double cellValue = 1.2;
-
+
fixture = new ExcelAntWorkbookUtilTestHelper(
mortgageCalculatorFileName);
-
+
fixture.setDoubleValue(cell, cellValue);
-
- Double value = fixture.getCellAsDouble(cell);
-
- assertNotNull(value);
- assertEquals(cellValue, value);
+
+ double value = fixture.getCellAsDouble(cell);
+
+ assertEquals(cellValue, value, 0);
}
-
+
+ @Test
public void testSetDate() {
String cell = "'MortgageCalculator'!C14" ;
Date cellValue = new Date();
-
+
fixture = new ExcelAntWorkbookUtilTestHelper(
mortgageCalculatorFileName);
-
+
fixture.setDateValue(cell, cellValue);
-
+
double value = fixture.getCellAsDouble(cell);
-
- assertEquals(DateUtil.getExcelDate(cellValue, false), value);
+
+ assertEquals(DateUtil.getExcelDate(cellValue, false), value, 0);
}
+ @Test
public void testGetNonexistingString() {
String cell = "'MortgageCalculator'!C33" ;
-
+
fixture = new ExcelAntWorkbookUtilTestHelper(
mortgageCalculatorFileName);
-
+
String value = fixture.getCellAsString(cell);
-
+
assertEquals("", value);
}
+ @Test
public void testGetNonexistingDouble() {
String cell = "'MortgageCalculator'!C33" ;
-
+
fixture = new ExcelAntWorkbookUtilTestHelper(
mortgageCalculatorFileName);
-
+
double value = fixture.getCellAsDouble(cell);
-
- assertEquals(0.0, value);
+
+ assertEquals(0.0, value, 0);
}
}
diff --git a/src/excelant/testcases/org/apache/poi/ss/excelant/util/TestExcelAntWorkbookUtilFactory.java b/src/excelant/testcases/org/apache/poi/ss/excelant/util/TestExcelAntWorkbookUtilFactory.java
index b69449a5f7..360334cbe1 100644
--- a/src/excelant/testcases/org/apache/poi/ss/excelant/util/TestExcelAntWorkbookUtilFactory.java
+++ b/src/excelant/testcases/org/apache/poi/ss/excelant/util/TestExcelAntWorkbookUtilFactory.java
@@ -19,23 +19,19 @@ package org.apache.poi.ss.excelant.util;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import org.apache.poi.ss.excelant.BuildFileTest;
+import org.apache.poi.ss.excelant.TestBuildFile;
import org.junit.Test;
/**
* Tests for the ExcelAntWorbookUtilFactory.
- *
- * @author Jon Svede (jon [at] loquatic [dot] com)
- * @author Brian Bush (brian [dot] bush [at] nrel [dot] gov)
- *
*/
public class TestExcelAntWorkbookUtilFactory {
private static final String mortgageCalculatorWorkbookFile =
- BuildFileTest.getDataDir() + "/spreadsheet/mortgage-calculation.xls" ;
-
-
+ TestBuildFile.getDataDir() + "/spreadsheet/mortgage-calculation.xls" ;
+
+
/**
* Simple test to determine if the factory properly returns an non-null
* instance of the ExcelAntWorkbookUtil class.
@@ -44,29 +40,29 @@ public class TestExcelAntWorkbookUtilFactory {
public void testGetNewWorkbookUtilInstance() {
ExcelAntWorkbookUtil util = ExcelAntWorkbookUtilFactory.getInstance(
mortgageCalculatorWorkbookFile) ;
-
+
assertNotNull(util) ;
}
-
-
+
+
/**
* Test whether or not the factory will properly return the same reference
* to an ExcelAnt WorkbookUtil when two different Strings, that point to
- * the same resource, are passed in.
+ * the same resource, are passed in.
*/
@Test
public void testVerifyEquivalence() {
- String sameFileName = BuildFileTest.getDataDir() + "/spreadsheet/mortgage-calculation.xls" ;
-
+ String sameFileName = TestBuildFile.getDataDir() + "/spreadsheet/mortgage-calculation.xls" ;
+
ExcelAntWorkbookUtil util = ExcelAntWorkbookUtilFactory.getInstance(
mortgageCalculatorWorkbookFile) ;
ExcelAntWorkbookUtil util2 = ExcelAntWorkbookUtilFactory.getInstance(
sameFileName) ;
-
+
assertNotNull(util) ;
assertNotNull(util2) ;
-
+
assertEquals(util, util2) ;
}
}