|
|
@@ -17,19 +17,24 @@ |
|
|
|
|
|
|
|
package org.apache.poi.ss.formula.eval.forked; |
|
|
|
|
|
|
|
import junit.framework.AssertionFailedError; |
|
|
|
import junit.framework.TestCase; |
|
|
|
import static org.junit.Assert.assertEquals; |
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
|
|
|
|
import org.apache.poi.ss.formula.eval.NumberEval; |
|
|
|
import org.apache.poi.hssf.usermodel.HSSFRow; |
|
|
|
import org.apache.poi.hssf.usermodel.HSSFSheet; |
|
|
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
|
|
|
import org.apache.poi.ss.formula.IStabilityClassifier; |
|
|
|
|
|
|
|
/** |
|
|
|
* @author Josh Micich |
|
|
|
*/ |
|
|
|
public final class TestForkedEvaluator extends TestCase { |
|
|
|
import org.apache.poi.ss.formula.eval.NumberEval; |
|
|
|
import org.junit.Rule; |
|
|
|
import org.junit.Test; |
|
|
|
import org.junit.rules.ExpectedException; |
|
|
|
|
|
|
|
public final class TestForkedEvaluator { |
|
|
|
|
|
|
|
@Rule |
|
|
|
public ExpectedException expectedEx = ExpectedException.none(); |
|
|
|
|
|
|
|
/** |
|
|
|
* set up a calculation workbook with input cells nicely segregated on a |
|
|
|
* sheet called "Inputs" |
|
|
@@ -53,7 +58,8 @@ public final class TestForkedEvaluator extends TestCase { |
|
|
|
/** |
|
|
|
* Shows a basic use-case for {@link ForkedEvaluator} |
|
|
|
*/ |
|
|
|
public void testBasic() { |
|
|
|
@Test |
|
|
|
public void testBasic() throws IOException { |
|
|
|
HSSFWorkbook wb = createWorkbook(); |
|
|
|
|
|
|
|
// The stability classifier is useful to reduce memory consumption of caching logic |
|
|
@@ -78,6 +84,8 @@ public final class TestForkedEvaluator extends TestCase { |
|
|
|
assertEquals(4.0, ((NumberEval) fe2.evaluate("Calculations", 0, 0)).getNumberValue(), 0.0); |
|
|
|
fe1.updateCell("Inputs", 0, 0, new NumberEval(3.0)); |
|
|
|
assertEquals(13.9, ((NumberEval) fe1.evaluate("Calculations", 0, 0)).getNumberValue(), 0.0); |
|
|
|
|
|
|
|
wb.close(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@@ -90,29 +98,19 @@ public final class TestForkedEvaluator extends TestCase { |
|
|
|
* was considered less desirable because so far, the underlying 'master' workbook is strictly |
|
|
|
* <i>read-only</i> with respect to the ForkedEvaluator. |
|
|
|
*/ |
|
|
|
public void testMissingInputCell() { |
|
|
|
@Test |
|
|
|
public void testMissingInputCell() throws IOException { |
|
|
|
expectedEx.expect(UnsupportedOperationException.class); |
|
|
|
expectedEx.expectMessage("Underlying cell 'A2' is missing in master sheet."); |
|
|
|
|
|
|
|
HSSFWorkbook wb = createWorkbook(); |
|
|
|
|
|
|
|
ForkedEvaluator fe = ForkedEvaluator.create(wb, null, null); |
|
|
|
|
|
|
|
// attempt update input at cell A2 (which is missing) |
|
|
|
try { |
|
|
|
fe.updateCell("Inputs", 1, 0, new NumberEval(4.0)); |
|
|
|
throw new AssertionFailedError( |
|
|
|
"Expected exception to be thrown due to missing input cell"); |
|
|
|
} catch (NullPointerException e) { |
|
|
|
StackTraceElement[] stes = e.getStackTrace(); |
|
|
|
if (stes[0].getMethodName().equals("getIdentityKey")) { |
|
|
|
throw new AssertionFailedError("Identified bug with update of missing input cell"); |
|
|
|
} |
|
|
|
throw e; |
|
|
|
} catch (UnsupportedOperationException e) { |
|
|
|
if (e.getMessage().equals( |
|
|
|
"Underlying cell 'A2' is missing in master sheet.")) { |
|
|
|
// expected during successful test |
|
|
|
} else { |
|
|
|
throw e; |
|
|
|
} |
|
|
|
ForkedEvaluator fe = ForkedEvaluator.create(wb, null, null); |
|
|
|
// attempt update input at cell A2 (which is missing) |
|
|
|
fe.updateCell("Inputs", 1, 0, new NumberEval(4.0)); |
|
|
|
} finally { |
|
|
|
wb.close(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |