pjfanning commented on code in PR #802:
URL: https://github.com/apache/poi/pull/802#discussion_r2072220955


##########
poi/src/test/java/org/apache/poi/ss/formula/functions/TestSheet.java:
##########
@@ -0,0 +1,79 @@
+package org.apache.poi.ss.formula.functions;
+
+import org.apache.poi.ss.formula.OperationEvaluationContext;
+import org.apache.poi.ss.formula.eval.*;
+import org.apache.poi.ss.formula.ptg.RefPtg;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+
+final class TestSheet {
+
+    private static final OperationEvaluationContext ec = new 
OperationEvaluationContext(null, null, 2, 0, 2, null);
+
+    @Test
+    void testCurrentSheet() {
+        ValueEval result = Sheet.instance.evaluate(new ValueEval[]{}, ec);
+        assertInstanceOf(NumberEval.class, result);
+        assertEquals(3.0, ((NumberEval) result).getNumberValue());
+    }
+
+    @Test
+    void testRefEval() {
+        RefEval refEval = new MockRefEval(new RefPtg("A1"), NumberEval.ZERO, 
2);  // Sheet index 1 → Excel index 2
+        ValueEval result = Sheet.instance.evaluate(new ValueEval[]{refEval}, 
ec);
+        assertInstanceOf(NumberEval.class, result);
+        assertEquals(3.0, ((NumberEval) result).getNumberValue());
+    }
+
+    @Test
+    void testAreaEval() {
+        AreaEval areaEval = EvalFactory.createAreaEval("A3", new 
ValueEval[]{null});  // Sheet index 4 → Excel index 5
+        ValueEval result = Sheet.instance.evaluate(new ValueEval[]{areaEval}, 
ec);
+        assertInstanceOf(NumberEval.class, result);
+        assertEquals(0.0, ((NumberEval) result).getNumberValue());
+    }
+
+    @Test
+    void testInvalidArg() {
+        ValueEval result = Sheet.instance.evaluate(new ValueEval[]{new 
StringEval("invalid")}, ec);
+        assertInstanceOf(ErrorEval.class, result);
+        assertEquals(ErrorEval.VALUE_INVALID, result);
+    }
+
+    @Test
+    void testExceptionHandling() {
+        // deliberately pass a ValueEval that will throw inside evaluate
+        ValueEval brokenEval = new BrokenValueEval();
+        ValueEval result = Sheet.instance.evaluate(new 
ValueEval[]{brokenEval}, ec);
+        assertInstanceOf(ErrorEval.class, result);
+        assertEquals(ErrorEval.VALUE_INVALID, result);
+    }
+
+    private static final class MockRefEval extends RefEvalBase {
+        private final ValueEval _value;
+
+        public MockRefEval(RefPtg ptg, ValueEval value, int sheetIndex) {

Review Comment:
   * instead of mocking - could you create a real workbook instance, add some 
some sheets and test with that?
   * you can create the worksheet with POI code instead of providing us with an 
xlsx
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@poi.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@poi.apache.org
For additional commands, e-mail: dev-h...@poi.apache.org

Reply via email to