Skip to content

Commit

Permalink
BasicExpressionEvaluationContextTest.testReferenceWithCycle
Browse files Browse the repository at this point in the history
  • Loading branch information
mP1 committed Feb 5, 2025
1 parent 255401b commit 815aaca
Showing 1 changed file with 49 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ public final class BasicExpressionEvaluationContextTest implements ClassTesting2

private final static String REFERENCE_NOT_FOUND_MESSAGE = "CustomMessage123";

private final static Function<ExpressionReference, ExpressionEvaluationException> REFERENCE_NOT_FOUND =
(r) ->
new ExpressionEvaluationReferenceException(
REFERENCE_NOT_FOUND_MESSAGE,
r
);

private final static CaseSensitivity CASE_SENSITIVITY = CaseSensitivity.SENSITIVE;

private final static Function<RuntimeException, Object> EXCEPTION_HANDLER = (r) -> {
Expand Down Expand Up @@ -480,14 +487,7 @@ private void isPureAndCheck2(final boolean pure) {
);
}

@Test
public void testReferences() {
this.referenceAndCheck(
this.createContext(),
REFERENCE,
REFERENCE_VALUE
);
}
// referencesNotFound...............................................................................................

@Test
public void testReferenceNotFound() {
Expand All @@ -503,6 +503,30 @@ public void testReferenceNotFound() {
);
}

// reference........................................................................................................

@Test
public void testReference() {
this.referenceAndCheck(
this.createContext(),
REFERENCE,
REFERENCE_VALUE
);
}

@Test
public void testReferenceCycle() {
this.referenceAndCheck(
this.createContext(
(r) -> Optional.of(
Optional.of(r)
)
),
REFERENCE,
REFERENCE
);
}

// enterScope.......................................................................................................

@Test
Expand Down Expand Up @@ -622,7 +646,7 @@ private BasicExpressionEvaluationContext createContext(final boolean pure,
this.functions(pure),
EXCEPTION_HANDLER,
this.references(),
(r) -> new ExpressionEvaluationReferenceException(REFERENCE_NOT_FOUND_MESSAGE, r),
REFERENCE_NOT_FOUND,
caseSensitivity,
this.converterContext()
);
Expand Down Expand Up @@ -701,6 +725,20 @@ private Function<ExpressionReference, Optional<Optional<Object>>> references() {
});
}

private BasicExpressionEvaluationContext createContext(final Function<ExpressionReference, Optional<Optional<Object>>> references) {
return BasicExpressionEvaluationContext.with(
KIND,
(n) -> {
throw new UnsupportedOperationException();
},
EXCEPTION_HANDLER,
references,
REFERENCE_NOT_FOUND,
CASE_SENSITIVITY,
ConverterContexts.fake()
);
}

private ConverterContext converterContext() {
return ConverterContexts.basic(
Converters.JAVA_EPOCH_OFFSET, // dateOffset
Expand All @@ -715,6 +753,8 @@ private ConverterContext converterContext() {
);
}

// DecimalNumberContext.............................................................................................

@Override
public String currencySymbol() {
return this.decimalNumberContext().currencySymbol();
Expand Down

0 comments on commit 815aaca

Please sign in to comment.