Skip to content

Commit 0ff8092

Browse files
committed
Let unimplemented evaluator functions throw UOE
As requested in #23.
1 parent 4880b55 commit 0ff8092

3 files changed

Lines changed: 24 additions & 41 deletions

File tree

src/main/java/org/scijava/parsington/eval/AbstractStandardEvaluator.java

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ public Object function(final Object a, final Object b) {
117117

118118
@Override
119119
public Object dot(final Object a, final Object b) {
120-
// NB: Unimplemented.
121-
return null;
120+
throw new UnsupportedOperationException();
122121
}
123122

124123
// -- groups --
@@ -143,14 +142,12 @@ public Object braces(final Object... args) {
143142

144143
@Override
145144
public Object transpose(final Object a) {
146-
// NB: Unimplemented.
147-
return null;
145+
throw new UnsupportedOperationException();
148146
}
149147

150148
@Override
151149
public Object dotTranspose(final Object a) {
152-
// NB: Unimplemented.
153-
return null;
150+
throw new UnsupportedOperationException();
154151
}
155152

156153
@Override
@@ -167,8 +164,7 @@ public Object pow(final Object a, final Object b) {
167164

168165
@Override
169166
public Object dotPow(final Object a, final Object b) {
170-
// NB: Unimplemented.
171-
return null;
167+
throw new UnsupportedOperationException();
172168
}
173169

174170
// -- unary --
@@ -289,26 +285,22 @@ public BigDecimal mod(final BigDecimal av, final BigDecimal bv) {
289285

290286
@Override
291287
public Object rightDiv(final Object a, final Object b) {
292-
// NB: Unimplemented.
293-
return null;
288+
throw new UnsupportedOperationException();
294289
}
295290

296291
@Override
297292
public Object dotMul(Object a, Object b) {
298-
// NB: Unimplemented.
299-
return null;
293+
throw new UnsupportedOperationException();
300294
}
301295

302296
@Override
303297
public Object dotDiv(final Object a, final Object b) {
304-
// NB: Unimplemented.
305-
return null;
298+
throw new UnsupportedOperationException();
306299
}
307300

308301
@Override
309302
public Object dotRightDiv(final Object a, final Object b) {
310-
// NB: Unimplemented.
311-
return null;
303+
throw new UnsupportedOperationException();
312304
}
313305

314306
// -- additive --
@@ -471,8 +463,7 @@ public <T> boolean greaterThanOrEqual(final Comparable<T> av, final T bv) {
471463

472464
@Override
473465
public Object instanceOf(final Object av, final Object bv) {
474-
// NB: Unimplemented.
475-
return null;
466+
throw new UnsupportedOperationException();
476467
}
477468

478469
// -- equality --
@@ -539,14 +530,12 @@ public Object logicalOr(final Object a, final Object b) {
539530

540531
@Override
541532
public Object question(final Object a, final Object b) {
542-
// NB: Unimplemented.
543-
return null;
533+
throw new UnsupportedOperationException();
544534
}
545535

546536
@Override
547537
public Object colon(Object a, Object b) {
548-
// NB: Unimplemented.
549-
return null;
538+
throw new UnsupportedOperationException();
550539
}
551540

552541
// -- Helper methods - type matching --

src/test/java/org/scijava/parsington/eval/AbstractStandardEvaluatorTest.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public void testFunction() {
117117
/** Tests {@link StandardEvaluator#dot(Object, Object)}. */
118118
@Test
119119
public void testDot() {
120-
assertNull(e.dot(o(0), o(1)));
120+
assertThrows(UnsupportedOperationException.class, () -> e.dot(o(0), o(1)));
121121
}
122122

123123
// -- groups --
@@ -160,13 +160,13 @@ public void testBraces() {
160160
/** Tests {@link StandardEvaluator#transpose(Object)}. */
161161
@Test
162162
public void testTranspose() {
163-
assertNull(e.transpose(o(0)));
163+
assertThrows(UnsupportedOperationException.class, () -> e.transpose(o(0)));
164164
}
165165

166166
/** Tests {@link StandardEvaluator#dotTranspose(Object)}. */
167167
@Test
168168
public void testDotTranspose() {
169-
assertNull(e.dotTranspose(o(0)));
169+
assertThrows(UnsupportedOperationException.class, () -> e.dotTranspose(o(0)));
170170
}
171171

172172
/** Tests {@link StandardEvaluator#pow(Object, Object)}. */
@@ -180,7 +180,7 @@ public void testPow() {
180180
/** Tests {@link StandardEvaluator#dotPow(Object, Object)}. */
181181
@Test
182182
public void testDotPow() {
183-
assertNull(e.dotPow(o(0), o(0)));
183+
assertThrows(UnsupportedOperationException.class, () -> e.dotPow(o(0), o(0)));
184184
}
185185

186186
// -- postfix --
@@ -319,19 +319,19 @@ public void testMod() {
319319
/** Tests {@link StandardEvaluator#rightDiv(Object, Object)}. */
320320
@Test
321321
public void testRightDiv() {
322-
assertNull(e.rightDiv(o(0), o(0)));
322+
assertThrows(UnsupportedOperationException.class, () -> e.rightDiv(o(0), o(0)));
323323
}
324324

325325
/** Tests {@link StandardEvaluator#dotDiv(Object, Object)}. */
326326
@Test
327327
public void testDotDiv() {
328-
assertNull(e.dotDiv(o(0), o(0)));
328+
assertThrows(UnsupportedOperationException.class, () -> e.dotDiv(o(0), o(0)));
329329
}
330330

331331
/** Tests {@link StandardEvaluator#dotRightDiv(Object, Object)}. */
332332
@Test
333333
public void testDotRightDiv() {
334-
assertNull(e.dotRightDiv(o(0), o(0)));
334+
assertThrows(UnsupportedOperationException.class, () -> e.dotRightDiv(o(0), o(0)));
335335
}
336336

337337
// -- additive --
@@ -533,7 +533,7 @@ public void testGreaterThanOrEqual() {
533533
/** Tests {@link StandardEvaluator#instanceOf(Object, Object)}. */
534534
@Test
535535
public void testInstanceOf() {
536-
assertNull(e.instanceOf(o(0), o(0)));
536+
assertThrows(UnsupportedOperationException.class, () -> e.instanceOf(o(0), o(0)));
537537
}
538538

539539
// -- equality --
@@ -653,13 +653,13 @@ public void testLogicalOr() {
653653
/** Tests {@link StandardEvaluator#question(Object, Object)}. */
654654
@Test
655655
public void testQuestion() {
656-
assertNull(e.question(o(0), o(0)));
656+
assertThrows(UnsupportedOperationException.class, () -> e.question(o(0), o(0)));
657657
}
658658

659659
/** Tests {@link StandardEvaluator#colon(Object, Object)}. */
660660
@Test
661661
public void testColon() {
662-
assertNull(e.colon(o(0), o(0)));
662+
assertThrows(UnsupportedOperationException.class, () -> e.colon(o(0), o(0)));
663663
}
664664

665665
// -- assignment --

src/test/java/org/scijava/parsington/eval/DefaultStackEvaluatorTest.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@
3131
package org.scijava.parsington.eval;
3232

3333
import static org.junit.jupiter.api.Assertions.assertEquals;
34-
import static org.junit.jupiter.api.Assertions.assertTrue;
35-
import static org.junit.jupiter.api.Assertions.fail;
34+
import static org.junit.jupiter.api.Assertions.assertThrows;
3635

3736
import java.util.List;
3837

@@ -68,13 +67,8 @@ public void testNonShortCircuitingOr() {
6867

6968
@Test
7069
public void testUnimplementedTernary() {
71-
try {
72-
e.evaluate("2 < 3 ? 'yes' : 'no'");
73-
fail("Evaluation of ternary expression erroneously succeeded");
74-
}
75-
catch (final IllegalArgumentException exc) {
76-
assertTrue(exc.getMessage().equals("Unsupported binary operator: :"));
77-
}
70+
assertThrows(UnsupportedOperationException.class,
71+
() -> e.evaluate("2 < 3 ? 'yes' : 'no'"));
7872
}
7973

8074
}

0 commit comments

Comments
 (0)