diff --git a/src/test/java/com/hubspot/jinjava/FilterOverrideTest.java b/src/test/java/com/hubspot/jinjava/FilterOverrideTest.java index dd9bb2815..e49556552 100644 --- a/src/test/java/com/hubspot/jinjava/FilterOverrideTest.java +++ b/src/test/java/com/hubspot/jinjava/FilterOverrideTest.java @@ -2,8 +2,7 @@ import static org.assertj.core.api.Assertions.assertThat; -import com.hubspot.jinjava.interpret.JinjavaInterpreter; -import com.hubspot.jinjava.lib.filter.Filter; +import com.hubspot.jinjava.testobjects.FilterOverrideTestObjects; import java.util.HashMap; import org.junit.Test; @@ -16,26 +15,9 @@ public void itAllowsUsersToOverrideBuiltInFilters() { assertThat(jinjava.render(template, new HashMap<>())).isEqualTo("11"); - jinjava.getGlobalContext().registerClasses(DescriptiveAddFilter.class); + jinjava + .getGlobalContext() + .registerClasses(FilterOverrideTestObjects.DescriptiveAddFilter.class); assertThat(jinjava.render(template, new HashMap<>())).isEqualTo("5 + 6 = 11"); } - - public static class DescriptiveAddFilter implements Filter { - - @Override - public String getName() { - return "add"; - } - - @Override - public Object filter(Object var, JinjavaInterpreter interpreter, String... args) { - return ( - var + - " + " + - args[0] + - " = " + - (Integer.parseInt(var.toString()) + Integer.parseInt(args[0])) - ); - } - } } diff --git a/src/test/java/com/hubspot/jinjava/el/ExpressionResolverTest.java b/src/test/java/com/hubspot/jinjava/el/ExpressionResolverTest.java index 9d8852bf6..fb270721c 100644 --- a/src/test/java/com/hubspot/jinjava/el/ExpressionResolverTest.java +++ b/src/test/java/com/hubspot/jinjava/el/ExpressionResolverTest.java @@ -3,7 +3,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; -import com.google.common.collect.ForwardingList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; @@ -18,10 +17,9 @@ import com.hubspot.jinjava.interpret.TemplateError; import com.hubspot.jinjava.interpret.TemplateError.ErrorItem; import com.hubspot.jinjava.interpret.TemplateError.ErrorReason; -import com.hubspot.jinjava.objects.PyWrapper; import com.hubspot.jinjava.objects.date.PyishDate; +import com.hubspot.jinjava.testobjects.ExpressionResolverTestObjects; import java.math.BigDecimal; -import java.util.Collection; import java.util.Date; import java.util.List; import java.util.Map; @@ -163,7 +161,8 @@ public void itResolvesDictValWithDotParam() { @Test public void itResolvesMapValOnCustomObject() { - MyCustomMap dict = new MyCustomMap(); + ExpressionResolverTestObjects.MyCustomMap dict = + new ExpressionResolverTestObjects.MyCustomMap(); context.put("thedict", dict); Object val = interpreter.resolveELExpression("thedict['foo']", -1); @@ -177,7 +176,8 @@ public void itResolvesMapValOnCustomObject() { @Test public void itResolvesOtherMethodsOnCustomMapObject() { - MyCustomMap dict = new MyCustomMap(); + ExpressionResolverTestObjects.MyCustomMap dict = + new ExpressionResolverTestObjects.MyCustomMap(); context.put("thedict", dict); Object val = interpreter.resolveELExpression("thedict.size", -1); @@ -190,67 +190,6 @@ public void itResolvesOtherMethodsOnCustomMapObject() { assertThat(val2.toString()).isEqualTo("[foo=bar, two=2, size=777]"); } - public static final class MyCustomMap implements Map { - - Map data = ImmutableMap.of("foo", "bar", "two", "2", "size", "777"); - - @Override - public int size() { - return data.size(); - } - - @Override - public boolean isEmpty() { - return data.isEmpty(); - } - - @Override - public boolean containsKey(Object key) { - return data.containsKey(key); - } - - @Override - public boolean containsValue(Object value) { - return data.containsValue(value); - } - - @Override - public String get(Object key) { - return data.get(key); - } - - @Override - public String put(String key, String value) { - return null; - } - - @Override - public String remove(Object key) { - return null; - } - - @Override - public void putAll(Map m) {} - - @Override - public void clear() {} - - @Override - public Set keySet() { - return data.keySet(); - } - - @Override - public Collection values() { - return data.values(); - } - - @Override - public Set> entrySet() { - return data.entrySet(); - } - } - @Test public void itResolvesInnerDictVal() { Map dict = Maps.newHashMap(); @@ -274,24 +213,6 @@ public void itResolvesInnerListVal() { assertThat(val).isEqualTo("val"); } - public static class MyCustomList extends ForwardingList implements PyWrapper { - - private final List list; - - public MyCustomList(List list) { - this.list = list; - } - - @Override - protected List delegate() { - return list; - } - - public int getTotalCount() { - return list.size(); - } - } - @Test public void itRecordsFilterNames() { Object val = interpreter.resolveELExpression("2.3 | round", -1); @@ -301,7 +222,9 @@ public void itRecordsFilterNames() { @Test public void callCustomListProperty() { - List myList = new MyCustomList<>(Lists.newArrayList(1, 2, 3, 4)); + List myList = new ExpressionResolverTestObjects.MyCustomList<>( + Lists.newArrayList(1, 2, 3, 4) + ); context.put("mylist", myList); Object val = interpreter.resolveELExpression("mylist.total_count", -1); @@ -353,7 +276,7 @@ public void syntaxError() { @Test public void itWrapsDates() { - context.put("myobj", new MyClass(new Date(0))); + context.put("myobj", new ExpressionResolverTestObjects.MyClass(new Date(0))); Object result = interpreter.resolveELExpression("myobj.date", -1); assertThat(result).isInstanceOf(PyishDate.class); assertThat(result.toString()).isEqualTo("1970-01-01 00:00:00"); @@ -361,7 +284,7 @@ public void itWrapsDates() { @Test public void blackListedProperties() { - context.put("myobj", new MyClass(new Date(0))); + context.put("myobj", new ExpressionResolverTestObjects.MyClass(new Date(0))); interpreter.resolveELExpression("myobj.class.methods[0]", -1); assertThat(interpreter.getErrorsCopy()).isNotEmpty(); @@ -373,14 +296,14 @@ public void blackListedProperties() { @Test public void itWillNotReturnClassObjectProperties() { - context.put("myobj", new MyClass(new Date(0))); + context.put("myobj", new ExpressionResolverTestObjects.MyClass(new Date(0))); Object clazz = interpreter.resolveELExpression("myobj.clazz", -1); assertThat(clazz).isNull(); } @Test public void blackListedMethods() { - context.put("myobj", new MyClass(new Date(0))); + context.put("myobj", new ExpressionResolverTestObjects.MyClass(new Date(0))); interpreter.resolveELExpression("myobj.wait()", -1); assertThat(interpreter.getErrorsCopy()).isNotEmpty(); @@ -390,7 +313,7 @@ public void blackListedMethods() { @Test public void itWillNotReturnClassObjects() { - context.put("myobj", new MyClass(new Date(0))); + context.put("myobj", new ExpressionResolverTestObjects.MyClass(new Date(0))); interpreter.resolveELExpression("myobj.getClass()", -1); assertThat(interpreter.getErrorsCopy()).isNotEmpty(); @@ -517,21 +440,27 @@ public void itStoresResolvedFunctions() { @Test public void presentOptionalProperty() { - context.put("myobj", new OptionalProperty(null, "foo")); + context.put("myobj", new ExpressionResolverTestObjects.OptionalProperty(null, "foo")); assertThat(interpreter.resolveELExpression("myobj.val", -1)).isEqualTo("foo"); assertThat(interpreter.getErrorsCopy()).isEmpty(); } @Test public void emptyOptionalProperty() { - context.put("myobj", new OptionalProperty(null, null)); + context.put("myobj", new ExpressionResolverTestObjects.OptionalProperty(null, null)); assertThat(interpreter.resolveELExpression("myobj.val", -1)).isNull(); assertThat(interpreter.getErrorsCopy()).isEmpty(); } @Test public void presentNestedOptionalProperty() { - context.put("myobj", new OptionalProperty(new MyClass(new Date(0)), "foo")); + context.put( + "myobj", + new ExpressionResolverTestObjects.OptionalProperty( + new ExpressionResolverTestObjects.MyClass(new Date(0)), + "foo" + ) + ); assertThat(Objects.toString(interpreter.resolveELExpression("myobj.nested.date", -1))) .isEqualTo("1970-01-01 00:00:00"); assertThat(interpreter.getErrorsCopy()).isEmpty(); @@ -539,7 +468,7 @@ public void presentNestedOptionalProperty() { @Test public void emptyNestedOptionalProperty() { - context.put("myobj", new OptionalProperty(null, null)); + context.put("myobj", new ExpressionResolverTestObjects.OptionalProperty(null, null)); assertThat(interpreter.resolveELExpression("myobj.nested.date", -1)).isNull(); assertThat(interpreter.getErrorsCopy()).isEmpty(); } @@ -548,7 +477,12 @@ public void emptyNestedOptionalProperty() { public void presentNestedNestedOptionalProperty() { context.put( "myobj", - new NestedOptionalProperty(new OptionalProperty(new MyClass(new Date(0)), "foo")) + new ExpressionResolverTestObjects.NestedOptionalProperty( + new ExpressionResolverTestObjects.OptionalProperty( + new ExpressionResolverTestObjects.MyClass(new Date(0)), + "foo" + ) + ) ); assertThat( Objects.toString(interpreter.resolveELExpression("myobj.nested.nested.date", -1)) @@ -559,7 +493,8 @@ public void presentNestedNestedOptionalProperty() { @Test public void itResolvesLazyExpressionsToTheirUnderlyingValue() { - TestClass testClass = new TestClass(); + ExpressionResolverTestObjects.TestClass testClass = + new ExpressionResolverTestObjects.TestClass(); Supplier lazyString = () -> result("hallelujah", testClass); context.put("myobj", ImmutableMap.of("test", LazyExpression.of(lazyString, ""))); @@ -580,7 +515,8 @@ public void itResolvesNullLazyExpressions() { @Test public void itResolvesSuppliersOnlyIfResolved() { - TestClass testClass = new TestClass(); + ExpressionResolverTestObjects.TestClass testClass = + new ExpressionResolverTestObjects.TestClass(); Supplier lazyString = () -> result("hallelujah", testClass); context.put( @@ -596,7 +532,8 @@ public void itResolvesSuppliersOnlyIfResolved() { @Test public void itResolvesLazyExpressionsInNested() { - Supplier lazyObject = TestClass::new; + Supplier lazyObject = + ExpressionResolverTestObjects.TestClass::new; context.put("myobj", ImmutableMap.of("test", LazyExpression.of(lazyObject, ""))); @@ -675,75 +612,8 @@ public void itAddsInvalidInputErrorWhenArithmeticExceptionIsThrown() { .isEqualTo(ErrorReason.INVALID_INPUT); } - public String result(String value, TestClass testClass) { + public String result(String value, ExpressionResolverTestObjects.TestClass testClass) { testClass.touch(); return value; } - - public static class TestClass { - - private boolean touched = false; - private String name = "Amazing test class"; - - public boolean isTouched() { - return touched; - } - - public void touch() { - this.touched = true; - } - - public String getName() { - return name; - } - } - - public static final class MyClass { - - private Date date; - - MyClass(Date date) { - this.date = date; - } - - public Class getClazz() { - return this.getClass(); - } - - public Date getDate() { - return date; - } - } - - public static final class OptionalProperty { - - private MyClass nested; - private String val; - - OptionalProperty(MyClass nested, String val) { - this.nested = nested; - this.val = val; - } - - public Optional getNested() { - return Optional.ofNullable(nested); - } - - public Optional getVal() { - return Optional.ofNullable(val); - } - } - - public static final class NestedOptionalProperty { - - private OptionalProperty nested; - - public NestedOptionalProperty(OptionalProperty nested) { - this.nested = nested; - } - - public Optional getNested() { - return Optional.ofNullable(nested); - } - } } diff --git a/src/test/java/com/hubspot/jinjava/el/ext/AstDictTest.java b/src/test/java/com/hubspot/jinjava/el/ext/AstDictTest.java index cdfbbf064..f0ebff5fd 100644 --- a/src/test/java/com/hubspot/jinjava/el/ext/AstDictTest.java +++ b/src/test/java/com/hubspot/jinjava/el/ext/AstDictTest.java @@ -6,7 +6,7 @@ import com.hubspot.jinjava.Jinjava; import com.hubspot.jinjava.interpret.JinjavaInterpreter; import com.hubspot.jinjava.interpret.TemplateError.ErrorType; -import java.util.Map; +import com.hubspot.jinjava.testobjects.AstDictTestObjects; import java.util.Set; import org.junit.Before; import org.junit.Test; @@ -34,20 +34,26 @@ public void itGetsDictValuesWithEnumKeys() { @Test public void itGetsDictValuesWithEnumKeysUsingToString() { - interpreter.getContext().put("foo", ImmutableMap.of(TestEnum.BAR, "test")); + interpreter + .getContext() + .put("foo", ImmutableMap.of(AstDictTestObjects.TestEnum.BAR, "test")); assertThat(interpreter.resolveELExpression("foo.barName", -1)).isEqualTo("test"); } @Test public void itDoesItemsMethodCall() { - interpreter.getContext().put("foo", ImmutableMap.of(TestEnum.BAR, "test")); + interpreter + .getContext() + .put("foo", ImmutableMap.of(AstDictTestObjects.TestEnum.BAR, "test")); assertThat(interpreter.resolveELExpression("foo.items()", -1)) .isInstanceOf(Set.class); } @Test public void itDoesKeysMethodCall() { - interpreter.getContext().put("foo", ImmutableMap.of(TestEnum.BAR, "test")); + interpreter + .getContext() + .put("foo", ImmutableMap.of(AstDictTestObjects.TestEnum.BAR, "test")); assertThat(interpreter.resolveELExpression("foo.keys()", -1)).isInstanceOf(Set.class); } @@ -62,37 +68,11 @@ public void itHandlesEmptyMaps() { public void itGetsDictValuesWithEnumKeysInObjects() { interpreter .getContext() - .put("test", new TestClass(ImmutableMap.of(ErrorType.FATAL, "test"))); + .put( + "test", + new AstDictTestObjects.TestClass(ImmutableMap.of(ErrorType.FATAL, "test")) + ); assertThat(interpreter.resolveELExpression("test.my_map.FATAL", -1)) .isEqualTo("test"); } - - public class TestClass { - - private Map myMap; - - public TestClass(Map myMap) { - this.myMap = myMap; - } - - public Map getMyMap() { - return myMap; - } - } - - public enum TestEnum { - FOO("fooName"), - BAR("barName"); - - private String name; - - TestEnum(String name) { - this.name = name; - } - - @Override - public String toString() { - return name; - } - } } diff --git a/src/test/java/com/hubspot/jinjava/el/ext/JinjavaBeanELResolverTest.java b/src/test/java/com/hubspot/jinjava/el/ext/JinjavaBeanELResolverTest.java index 8f7926f40..5a57abd58 100644 --- a/src/test/java/com/hubspot/jinjava/el/ext/JinjavaBeanELResolverTest.java +++ b/src/test/java/com/hubspot/jinjava/el/ext/JinjavaBeanELResolverTest.java @@ -11,6 +11,7 @@ import com.hubspot.jinjava.el.JinjavaELContext; import com.hubspot.jinjava.interpret.AutoCloseableSupplier; import com.hubspot.jinjava.interpret.JinjavaInterpreter; +import com.hubspot.jinjava.testobjects.JinjavaBeanELResolverTestObjects; import java.util.List; import javax.el.ELContext; import javax.el.MethodNotFoundException; @@ -59,25 +60,8 @@ public void itInvokesProperStringReplace() { @Test public void itInvokesBestMethodWithSingleParam() { - class Temp { - - public String getResult(int a) { - return "int"; - } - - public String getResult(String a) { - return "String"; - } - - public String getResult(Object a) { - return "Object"; - } - - public String getResult(CharSequence a) { - return "CharSequence"; - } - } - Temp var = new Temp(); + JinjavaBeanELResolverTestObjects.TempItInvokesBestMethodWithSingleParam var = + new JinjavaBeanELResolverTestObjects.TempItInvokesBestMethodWithSingleParam(); assertThat( jinjavaBeanELResolver.invoke(elContext, var, "getResult", null, new Object[] { 1 }) ) @@ -106,21 +90,8 @@ public String getResult(CharSequence a) { @Test public void itPrefersPrimitives() { - class Temp { - - public String getResult(int a, Integer b) { - return "int Integer"; - } - - public String getResult(int a, Object b) { - return "int Object"; - } - - public String getResult(Number a, int b) { - return "Number int"; - } - } - Temp var = new Temp(); + JinjavaBeanELResolverTestObjects.TempItPrefersPrimitives var = + new JinjavaBeanELResolverTestObjects.TempItPrefersPrimitives(); assertThat( jinjavaBeanELResolver.invoke( elContext, diff --git a/src/test/java/com/hubspot/jinjava/el/ext/eager/EagerAstDotTest.java b/src/test/java/com/hubspot/jinjava/el/ext/eager/EagerAstDotTest.java index 4e29ed580..faeee2622 100644 --- a/src/test/java/com/hubspot/jinjava/el/ext/eager/EagerAstDotTest.java +++ b/src/test/java/com/hubspot/jinjava/el/ext/eager/EagerAstDotTest.java @@ -8,11 +8,10 @@ import com.hubspot.jinjava.LegacyOverrides; import com.hubspot.jinjava.interpret.Context; import com.hubspot.jinjava.interpret.DeferredValue; -import com.hubspot.jinjava.interpret.DeferredValueException; import com.hubspot.jinjava.interpret.JinjavaInterpreter; -import com.hubspot.jinjava.interpret.PartiallyDeferredValue; import com.hubspot.jinjava.mode.EagerExecutionMode; import com.hubspot.jinjava.random.RandomNumberGeneratorStrategy; +import com.hubspot.jinjava.testobjects.EagerAstDotTestObjects.Foo; import org.junit.Before; import org.junit.Test; @@ -66,20 +65,4 @@ public void itDefersNodeWhenNestedDeferredMapDotThrowsDeferredValueException() { .isEqualTo("{{ foo_map.bar.deferred }}"); assertThat(interpreter.getContext().getDeferredNodes()).isNotEmpty(); } - - public static class Foo implements PartiallyDeferredValue { - - public String getDeferred() { - throw new DeferredValueException("foo.deferred is deferred"); - } - - public String getResolved() { - return "resolved"; - } - - @Override - public Object getOriginalValue() { - return null; - } - } } diff --git a/src/test/java/com/hubspot/jinjava/el/ext/eager/EagerAstMethodTest.java b/src/test/java/com/hubspot/jinjava/el/ext/eager/EagerAstMethodTest.java index 7a24f9e5b..1b1945383 100644 --- a/src/test/java/com/hubspot/jinjava/el/ext/eager/EagerAstMethodTest.java +++ b/src/test/java/com/hubspot/jinjava/el/ext/eager/EagerAstMethodTest.java @@ -7,7 +7,6 @@ import com.hubspot.jinjava.JinjavaConfig; import com.hubspot.jinjava.LegacyOverrides; import com.hubspot.jinjava.el.ext.DeferredParsingException; -import com.hubspot.jinjava.el.ext.eager.EagerAstDotTest.Foo; import com.hubspot.jinjava.interpret.Context; import com.hubspot.jinjava.interpret.DeferredValue; import com.hubspot.jinjava.interpret.JinjavaInterpreter; @@ -15,6 +14,7 @@ import com.hubspot.jinjava.objects.collections.PyList; import com.hubspot.jinjava.objects.collections.PyMap; import com.hubspot.jinjava.random.RandomNumberGeneratorStrategy; +import com.hubspot.jinjava.testobjects.EagerAstDotTestObjects; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -225,7 +225,7 @@ public void itPreservesAstTuple() { @Test public void itPreservesUnresolvable() { - interpreter.getContext().put("foo_object", new Foo()); + interpreter.getContext().put("foo_object", new EagerAstDotTestObjects.Foo()); interpreter.getContext().addMetaContextVariables(Collections.singleton("foo_object")); try { interpreter.resolveELExpression("foo_object.deferred|upper", -1); diff --git a/src/test/java/com/hubspot/jinjava/interpret/JinjavaInterpreterTest.java b/src/test/java/com/hubspot/jinjava/interpret/JinjavaInterpreterTest.java index eeb8c53e9..1ae20aede 100644 --- a/src/test/java/com/hubspot/jinjava/interpret/JinjavaInterpreterTest.java +++ b/src/test/java/com/hubspot/jinjava/interpret/JinjavaInterpreterTest.java @@ -3,7 +3,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import com.fasterxml.jackson.annotation.JsonIgnore; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; import com.hubspot.jinjava.Jinjava; @@ -19,6 +18,7 @@ import com.hubspot.jinjava.mode.PreserveRawExecutionMode; import com.hubspot.jinjava.objects.date.FormattedDate; import com.hubspot.jinjava.objects.date.StrftimeFormatter; +import com.hubspot.jinjava.testobjects.JinjavaInterpreterTestObjects; import com.hubspot.jinjava.tree.TextNode; import com.hubspot.jinjava.tree.output.BlockInfo; import com.hubspot.jinjava.tree.output.OutputList; @@ -103,55 +103,44 @@ public void resolveBlockStubsWithCycle() { // Ex VariableChain stuff - static class Foo { - - private String bar; - - public Foo(String bar) { - this.bar = bar; - } - - public String getBar() { - return bar; - } - - public String getBarFoo() { - return bar; - } - - public String getBarFoo1() { - return bar; - } - - @JsonIgnore - public String getBarHidden() { - return bar; - } - } - @Test public void singleWordProperty() { - assertThat(interpreter.resolveProperty(new Foo("a"), "bar")).isEqualTo("a"); + assertThat( + interpreter.resolveProperty(new JinjavaInterpreterTestObjects.Foo("a"), "bar") + ) + .isEqualTo("a"); } @Test public void multiWordCamelCase() { - assertThat(interpreter.resolveProperty(new Foo("a"), "barFoo")).isEqualTo("a"); + assertThat( + interpreter.resolveProperty(new JinjavaInterpreterTestObjects.Foo("a"), "barFoo") + ) + .isEqualTo("a"); } @Test public void multiWordSnakeCase() { - assertThat(interpreter.resolveProperty(new Foo("a"), "bar_foo")).isEqualTo("a"); + assertThat( + interpreter.resolveProperty(new JinjavaInterpreterTestObjects.Foo("a"), "bar_foo") + ) + .isEqualTo("a"); } @Test public void multiWordNumberSnakeCase() { - assertThat(interpreter.resolveProperty(new Foo("a"), "bar_foo_1")).isEqualTo("a"); + assertThat( + interpreter.resolveProperty(new JinjavaInterpreterTestObjects.Foo("a"), "bar_foo_1") + ) + .isEqualTo("a"); } @Test public void jsonIgnore() { - assertThat(interpreter.resolveProperty(new Foo("a"), "barHidden")).isEqualTo("a"); + assertThat( + interpreter.resolveProperty(new JinjavaInterpreterTestObjects.Foo("a"), "barHidden") + ) + .isEqualTo("a"); } @Test diff --git a/src/test/java/com/hubspot/jinjava/interpret/PartiallyDeferredValueTest.java b/src/test/java/com/hubspot/jinjava/interpret/PartiallyDeferredValueTest.java index e781a7a9f..dec3f9153 100644 --- a/src/test/java/com/hubspot/jinjava/interpret/PartiallyDeferredValueTest.java +++ b/src/test/java/com/hubspot/jinjava/interpret/PartiallyDeferredValueTest.java @@ -8,12 +8,8 @@ import com.hubspot.jinjava.LegacyOverrides; import com.hubspot.jinjava.mode.EagerExecutionMode; import com.hubspot.jinjava.objects.collections.PyMap; -import com.hubspot.jinjava.objects.serialization.PyishSerializable; import com.hubspot.jinjava.random.RandomNumberGeneratorStrategy; -import java.io.IOException; -import java.util.Map; -import java.util.Set; -import javax.annotation.CheckForNull; +import com.hubspot.jinjava.testobjects.PartiallyDeferredValueTestObjects; import org.junit.Before; import org.junit.Test; @@ -44,7 +40,9 @@ public void setup() { @Test public void itDefersNodeWhenCannotSerializePartiallyDeferredValue() { - interpreter.getContext().put("foo", new BadSerialization()); + interpreter + .getContext() + .put("foo", new PartiallyDeferredValueTestObjects.BadSerialization()); assertThat(interpreter.render("{% set bar = foo %}{{ bar.resolved }}")) .isEqualTo("resolved"); assertThat(interpreter.render("{% set bar = foo %}{{ bar.deferred }}")) @@ -56,7 +54,12 @@ public void itDefersNodeWhenCannotSerializePartiallyDeferredValue() { public void itDefersNodeWhenCannotCallPartiallyDeferredMapEntrySet() { interpreter .getContext() - .put("foo", new BadEntrySet(ImmutableMap.of("resolved", "resolved"))); + .put( + "foo", + new PartiallyDeferredValueTestObjects.BadEntrySet( + ImmutableMap.of("resolved", "resolved") + ) + ); assertThat(interpreter.render("{% set bar = foo %}{{ bar.resolved }}")) .isEqualTo("resolved"); assertThat(interpreter.render("{% set bar = foo %}{{ bar.deferred }}")) @@ -66,7 +69,9 @@ public void itDefersNodeWhenCannotCallPartiallyDeferredMapEntrySet() { @Test public void itDefersNodeWhenPyishSerializationFails() { - interpreter.getContext().put("foo", new BadPyishSerializable()); + interpreter + .getContext() + .put("foo", new PartiallyDeferredValueTestObjects.BadPyishSerializable()); assertThat(interpreter.render("{% set bar = foo %}{{ bar.resolved }}")) .isEqualTo("resolved"); assertThat(interpreter.render("{% set bar = foo %}{{ bar.deferred }}")) @@ -76,7 +81,9 @@ public void itDefersNodeWhenPyishSerializationFails() { @Test public void itSerializesWhenPyishSerializationIsGood() { - interpreter.getContext().put("foo", new GoodPyishSerializable()); + interpreter + .getContext() + .put("foo", new PartiallyDeferredValueTestObjects.GoodPyishSerializable()); assertThat(interpreter.render("{% set bar = foo %}{{ bar.resolved }}")) .isEqualTo("resolved"); assertThat(interpreter.render("{% set bar = foo %}{{ bar.deferred }}")) @@ -90,7 +97,9 @@ public void itSerializesWhenEntrySetIsBadButItIsPyishSerializable() { .getContext() .put( "foo", - new BadEntrySetButPyishSerializable(ImmutableMap.of("resolved", "resolved")) + new PartiallyDeferredValueTestObjects.BadEntrySetButPyishSerializable( + ImmutableMap.of("resolved", "resolved") + ) ); assertThat(interpreter.render("{% set bar = foo %}{{ bar.resolved }}")) .isEqualTo("resolved"); @@ -103,7 +112,15 @@ public void itSerializesWhenEntrySetIsBadButItIsPyishSerializable() { public void itSerializesPartiallyDeferredValueIsInsideAMap() { interpreter .getContext() - .put("foo_map", new PyMap(ImmutableMap.of("foo", new GoodPyishSerializable()))); + .put( + "foo_map", + new PyMap( + ImmutableMap.of( + "foo", + new PartiallyDeferredValueTestObjects.GoodPyishSerializable() + ) + ) + ); assertThat(interpreter.render("{% set bar = foo_map %}{{ bar.foo.resolved }}")) .isEqualTo("resolved"); assertThat(interpreter.render("{% set bar = foo_map.foo %}{{ bar.resolved }}")) @@ -117,7 +134,9 @@ public void itSerializesPartiallyDeferredValueIsInsideAMap() { @Test public void itSerializesPartiallyDeferredValueIsPutInsideAMap() { - interpreter.getContext().put("foo", new GoodPyishSerializable()); + interpreter + .getContext() + .put("foo", new PartiallyDeferredValueTestObjects.GoodPyishSerializable()); assertThat( interpreter.render("{% set bar = {'my_key': foo} %}{% print bar.my_key.resolved %}") ) @@ -131,7 +150,9 @@ public void itSerializesPartiallyDeferredValueIsPutInsideAMap() { @Test public void itSerializesPartiallyDeferredValueIsPutInsideAMapInComplexExpression() { - interpreter.getContext().put("foo", new GoodPyishSerializable()); + interpreter + .getContext() + .put("foo", new PartiallyDeferredValueTestObjects.GoodPyishSerializable()); assertThat( interpreter.render( "{% set bar = {'my_key': foo} %}{% print (1 + 1 == 3 || bar.my_key.resolved) ~ '.' %}" @@ -149,7 +170,9 @@ public void itSerializesPartiallyDeferredValueIsPutInsideAMapInComplexExpression @Test public void itSerializesPartiallyDeferredValueInsteadOfPreservingOriginalIdentifier() { - interpreter.getContext().put("foo", new GoodPyishSerializable()); + interpreter + .getContext() + .put("foo", new PartiallyDeferredValueTestObjects.GoodPyishSerializable()); assertThat( interpreter.render( "{% set list = [] %}{% set bar = foo %}{% do list.append(bar['resolved']) %}{% print list %}" @@ -166,126 +189,4 @@ public void itSerializesPartiallyDeferredValueInsteadOfPreservingOriginalIdentif ); assertThat(interpreter.getContext().getDeferredNodes()).isEmpty(); } - - public static class BadSerialization implements PartiallyDeferredValue { - - public String getDeferred() { - throw new DeferredValueException("foo.deferred is deferred"); - } - - public String getResolved() { - return "resolved"; - } - - @Override - public Object getOriginalValue() { - return null; - } - } - - public static class BadEntrySet extends PyMap implements PartiallyDeferredValue { - - public BadEntrySet(Map map) { - super(map); - } - - @Override - public Set> entrySet() { - throw new DeferredValueException("entries are deferred"); - } - - @CheckForNull - @Override - public Object get(@CheckForNull Object key) { - if ("deferred".equals(key)) { - throw new DeferredValueException("deferred key"); - } - return super.get(key); - } - - @Override - public Object getOriginalValue() { - return null; - } - } - - public static class BadPyishSerializable - implements PartiallyDeferredValue, PyishSerializable { - - public String getDeferred() { - throw new DeferredValueException("foo.deferred is deferred"); - } - - public String getResolved() { - return "resolved"; - } - - @Override - public Object getOriginalValue() { - return null; - } - - @Override - public T appendPyishString(T appendable) - throws IOException { - throw new DeferredValueException("I'm bad"); - } - } - - public static class GoodPyishSerializable - implements PartiallyDeferredValue, PyishSerializable { - - public String getDeferred() { - throw new DeferredValueException("foo.deferred is deferred"); - } - - public String getResolved() { - return "resolved"; - } - - @Override - public Object getOriginalValue() { - return null; - } - - @Override - public T appendPyishString(T appendable) - throws IOException { - return (T) appendable.append("good"); - } - } - - public static class BadEntrySetButPyishSerializable - extends PyMap - implements PartiallyDeferredValue, PyishSerializable { - - public BadEntrySetButPyishSerializable(Map map) { - super(map); - } - - @Override - public Set> entrySet() { - throw new DeferredValueException("entries are deferred"); - } - - @CheckForNull - @Override - public Object get(@CheckForNull Object key) { - if ("deferred".equals(key)) { - throw new DeferredValueException("deferred key"); - } - return super.get(key); - } - - @Override - public Object getOriginalValue() { - return null; - } - - @Override - public T appendPyishString(T appendable) - throws IOException { - return (T) appendable.append("hello"); - } - } } diff --git a/src/test/java/com/hubspot/jinjava/lib/filter/SortFilterTest.java b/src/test/java/com/hubspot/jinjava/lib/filter/SortFilterTest.java index b258a0563..f58a979c5 100644 --- a/src/test/java/com/hubspot/jinjava/lib/filter/SortFilterTest.java +++ b/src/test/java/com/hubspot/jinjava/lib/filter/SortFilterTest.java @@ -5,8 +5,7 @@ import com.hubspot.jinjava.BaseJinjavaTest; import com.hubspot.jinjava.interpret.RenderResult; import com.hubspot.jinjava.interpret.TemplateError.ErrorType; -import com.hubspot.jinjava.objects.serialization.PyishSerializable; -import java.io.IOException; +import com.hubspot.jinjava.testobjects.SortFilterTestObjects; import java.util.Date; import java.util.HashMap; import java.util.Map; @@ -35,9 +34,11 @@ public void sortWithNamedAttributes() throws Exception { assertThat( render( "(reverse=false, case_sensitive=false, attribute='foo.date')", - new MyBar(new MyFoo(new Date(250L))), - new MyBar(new MyFoo(new Date(0L))), - new MyBar(new MyFoo(new Date(100000000L))) + new SortFilterTestObjects.MyBar(new SortFilterTestObjects.MyFoo(new Date(250L))), + new SortFilterTestObjects.MyBar(new SortFilterTestObjects.MyFoo(new Date(0L))), + new SortFilterTestObjects.MyBar( + new SortFilterTestObjects.MyFoo(new Date(100000000L)) + ) ) ) .isEqualTo("0250100000000"); @@ -53,9 +54,9 @@ public void sortWithAttr() { assertThat( render( "(false, false, 'date')", - new MyFoo(new Date(250L)), - new MyFoo(new Date(0L)), - new MyFoo(new Date(100000000L)) + new SortFilterTestObjects.MyFoo(new Date(250L)), + new SortFilterTestObjects.MyFoo(new Date(0L)), + new SortFilterTestObjects.MyFoo(new Date(100000000L)) ) ) .isEqualTo("0250100000000"); @@ -66,9 +67,11 @@ public void sortWithNestedAttr() { assertThat( render( "(false, false, 'foo.date')", - new MyBar(new MyFoo(new Date(250L))), - new MyBar(new MyFoo(new Date(0L))), - new MyBar(new MyFoo(new Date(100000000L))) + new SortFilterTestObjects.MyBar(new SortFilterTestObjects.MyFoo(new Date(250L))), + new SortFilterTestObjects.MyBar(new SortFilterTestObjects.MyFoo(new Date(0L))), + new SortFilterTestObjects.MyBar( + new SortFilterTestObjects.MyFoo(new Date(100000000L)) + ) ) ) .isEqualTo("0250100000000"); @@ -78,9 +81,9 @@ public void sortWithNestedAttr() { public void itThrowsInvalidArgumentExceptionOnNullAttribute() { RenderResult result = renderForResult( "(false, false, null)", - new MyFoo(new Date(250L)), - new MyFoo(new Date(0L)), - new MyFoo(new Date(100000000L)) + new SortFilterTestObjects.MyFoo(new Date(250L)), + new SortFilterTestObjects.MyFoo(new Date(0L)), + new SortFilterTestObjects.MyFoo(new Date(100000000L)) ); assertThat(result.getOutput()).isEmpty(); assertThat(result.getErrors()).hasSize(1); @@ -92,9 +95,9 @@ public void itThrowsInvalidArgumentExceptionOnNullAttribute() { public void itThrowsInvalidArgumentWhenObjectAttributeIsNull() { RenderResult result = renderForResult( "(false, false, 'doesNotResolve')", - new MyFoo(new Date(250L)), - new MyFoo(new Date(0L)), - new MyFoo(new Date(100000000L)) + new SortFilterTestObjects.MyFoo(new Date(250L)), + new SortFilterTestObjects.MyFoo(new Date(0L)), + new SortFilterTestObjects.MyFoo(new Date(100000000L)) ); assertThat(result.getOutput()).isEmpty(); assertThat(result.getErrors()).hasSize(2); @@ -107,10 +110,10 @@ public void itThrowsInvalidArgumentWhenObjectAttributeIsNull() { public void itThrowsInvalidInputWhenListContainsNull() { RenderResult result = renderForResult( "(false, false)", - new MyFoo(new Date(250L)), - new MyFoo(new Date(0L)), + new SortFilterTestObjects.MyFoo(new Date(250L)), + new SortFilterTestObjects.MyFoo(new Date(0L)), null, - new MyFoo(new Date(100000000L)) + new SortFilterTestObjects.MyFoo(new Date(100000000L)) ); assertThat(result.getOutput()).isEmpty(); assertThat(result.getErrors()).hasSize(1); @@ -136,54 +139,4 @@ RenderResult renderForResult(String sortExtra, Object... items) { context ); } - - public static class MyFoo implements PyishSerializable { - - private Date date; - - MyFoo(Date date) { - this.date = date; - } - - public Date getDate() { - return date; - } - - @Override - public String toString() { - return "" + date.getTime(); - } - - @Override - @SuppressWarnings("unchecked") - public T appendPyishString(T appendable) - throws IOException { - return (T) appendable.append(toString()); - } - } - - public static class MyBar implements PyishSerializable { - - private MyFoo foo; - - MyBar(MyFoo foo) { - this.foo = foo; - } - - public MyFoo getFoo() { - return foo; - } - - @Override - public String toString() { - return foo.toString(); - } - - @Override - @SuppressWarnings("unchecked") - public T appendPyishString(T appendable) - throws IOException { - return (T) appendable.append(toString()); - } - } } diff --git a/src/test/java/com/hubspot/jinjava/lib/filter/UniqueFilterTest.java b/src/test/java/com/hubspot/jinjava/lib/filter/UniqueFilterTest.java index 9183d431e..ef924bc3f 100644 --- a/src/test/java/com/hubspot/jinjava/lib/filter/UniqueFilterTest.java +++ b/src/test/java/com/hubspot/jinjava/lib/filter/UniqueFilterTest.java @@ -3,8 +3,7 @@ import static org.assertj.core.api.Assertions.assertThat; import com.hubspot.jinjava.BaseJinjavaTest; -import com.hubspot.jinjava.objects.serialization.PyishSerializable; -import java.io.IOException; +import com.hubspot.jinjava.testobjects.UniqueFilterTestObjects; import java.util.HashMap; import java.util.Map; import org.apache.commons.lang3.StringUtils; @@ -27,10 +26,10 @@ public void itFiltersDuplicatesFromSeqByAttr() { assertThat( render( "name", - new MyClass("a"), - new MyClass("b"), - new MyClass("a"), - new MyClass("c") + new UniqueFilterTestObjects.MyClass("a"), + new UniqueFilterTestObjects.MyClass("b"), + new UniqueFilterTestObjects.MyClass("a"), + new UniqueFilterTestObjects.MyClass("c") ) ) .isEqualTo("[Name:a][Name:b][Name:c]"); @@ -54,29 +53,4 @@ String render(String attr, Object... items) { context ); } - - public static class MyClass implements PyishSerializable { - - private final String name; - - public MyClass(String name) { - this.name = name; - } - - public String getName() { - return name; - } - - @Override - public String toString() { - return "[Name:" + name + "]"; - } - - @Override - @SuppressWarnings("unchecked") - public T appendPyishString(T appendable) - throws IOException { - return (T) appendable.append(toString()); - } - } } diff --git a/src/test/java/com/hubspot/jinjava/lib/tag/IfTagTest.java b/src/test/java/com/hubspot/jinjava/lib/tag/IfTagTest.java index 91b039f87..31c589efa 100644 --- a/src/test/java/com/hubspot/jinjava/lib/tag/IfTagTest.java +++ b/src/test/java/com/hubspot/jinjava/lib/tag/IfTagTest.java @@ -5,9 +5,9 @@ import com.google.common.collect.Lists; import com.google.common.io.Resources; import com.hubspot.jinjava.BaseInterpretingTest; +import com.hubspot.jinjava.testobjects.IfTagTestObjects; import com.hubspot.jinjava.tree.TagNode; import com.hubspot.jinjava.tree.TreeParser; -import com.hubspot.jinjava.util.HasObjectTruthValue; import com.hubspot.jinjava.util.ObjectTruthValueTest; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -39,11 +39,11 @@ public void itDoesntEvalChildrenWhenExprIsFalse() { @Test public void itChecksObjectTruthValue() { - context.put("foo", new TestObject().setObjectTruthValue(true)); + context.put("foo", new IfTagTestObjects.Foo().setObjectTruthValue(true)); TagNode n = fixture("if-object"); assertThat(tag.interpret(n, interpreter).trim()).isEqualTo("ifblock"); - context.put("foo", new TestObject().setObjectTruthValue(false)); + context.put("foo", new IfTagTestObjects.Foo().setObjectTruthValue(false)); n = fixture("if-object"); assertThat(tag.interpret(n, interpreter).trim()).isEqualTo(""); } @@ -131,19 +131,4 @@ private TagNode fixture(String name) { throw new RuntimeException(e); } } - - private class TestObject implements HasObjectTruthValue { - - private boolean objectTruthValue = false; - - public TestObject setObjectTruthValue(boolean objectTruthValue) { - this.objectTruthValue = objectTruthValue; - return this; - } - - @Override - public boolean getObjectTruthValue() { - return objectTruthValue; - } - } } diff --git a/src/test/java/com/hubspot/jinjava/lib/tag/ImportTagTest.java b/src/test/java/com/hubspot/jinjava/lib/tag/ImportTagTest.java index 722bc0aa2..1e26bb0d6 100644 --- a/src/test/java/com/hubspot/jinjava/lib/tag/ImportTagTest.java +++ b/src/test/java/com/hubspot/jinjava/lib/tag/ImportTagTest.java @@ -10,10 +10,10 @@ import com.hubspot.jinjava.interpret.JinjavaInterpreter; import com.hubspot.jinjava.interpret.RenderResult; import com.hubspot.jinjava.lib.fn.MacroFunction; -import com.hubspot.jinjava.lib.tag.eager.EagerImportTagTest.PrintPathFilter; import com.hubspot.jinjava.loader.LocationResolver; import com.hubspot.jinjava.loader.RelativePathResolver; import com.hubspot.jinjava.loader.ResourceLocator; +import com.hubspot.jinjava.testobjects.EagerImportTagTestObjects; import com.hubspot.jinjava.tree.Node; import java.io.IOException; import java.nio.charset.Charset; @@ -31,7 +31,7 @@ public class ImportTagTest extends BaseInterpretingTest { @Before public void setup() { context.put("padding", 42); - context.registerFilter(new PrintPathFilter()); + context.registerFilter(new EagerImportTagTestObjects.PrintPathFilter()); } @Test diff --git a/src/test/java/com/hubspot/jinjava/lib/tag/ValidationModeTest.java b/src/test/java/com/hubspot/jinjava/lib/tag/ValidationModeTest.java index bce403426..67b2c7e18 100644 --- a/src/test/java/com/hubspot/jinjava/lib/tag/ValidationModeTest.java +++ b/src/test/java/com/hubspot/jinjava/lib/tag/ValidationModeTest.java @@ -8,9 +8,9 @@ import com.hubspot.jinjava.LegacyOverrides; import com.hubspot.jinjava.interpret.Context; import com.hubspot.jinjava.interpret.JinjavaInterpreter; -import com.hubspot.jinjava.lib.filter.Filter; import com.hubspot.jinjava.lib.fn.ELFunctionDefinition; import com.hubspot.jinjava.lib.fn.MacroFunction; +import com.hubspot.jinjava.testobjects.ValidationModeTestObjects; import com.hubspot.jinjava.tree.Node; import com.hubspot.jinjava.tree.TextNode; import com.hubspot.jinjava.tree.parse.DefaultTokenScannerSymbols; @@ -32,27 +32,7 @@ public class ValidationModeTest { Jinjava jinjava; private Context context; - ValidationFilter validationFilter; - - class ValidationFilter implements Filter { - - private int executionCount = 0; - - @Override - public Object filter(Object var, JinjavaInterpreter interpreter, String... args) { - executionCount++; - return var; - } - - public int getExecutionCount() { - return executionCount; - } - - @Override - public String getName() { - return "validation_filter"; - } - } + ValidationModeTestObjects.ValidationFilter validationFilter; private static int functionExecutionCount = 0; @@ -62,7 +42,7 @@ public static int validationTestFunction() { @Before public void setup() { - validationFilter = new ValidationFilter(); + validationFilter = new ValidationModeTestObjects.ValidationFilter(); ELFunctionDefinition validationFunction = new ELFunctionDefinition( "", diff --git a/src/test/java/com/hubspot/jinjava/lib/tag/eager/EagerImportTagTest.java b/src/test/java/com/hubspot/jinjava/lib/tag/eager/EagerImportTagTest.java index e1d578f95..ea20333bf 100644 --- a/src/test/java/com/hubspot/jinjava/lib/tag/eager/EagerImportTagTest.java +++ b/src/test/java/com/hubspot/jinjava/lib/tag/eager/EagerImportTagTest.java @@ -10,7 +10,6 @@ import com.hubspot.jinjava.interpret.DeferredValue; import com.hubspot.jinjava.interpret.JinjavaInterpreter; import com.hubspot.jinjava.interpret.RenderResult; -import com.hubspot.jinjava.lib.filter.Filter; import com.hubspot.jinjava.lib.tag.ImportTag; import com.hubspot.jinjava.lib.tag.ImportTagTest; import com.hubspot.jinjava.lib.tag.Tag; @@ -23,6 +22,7 @@ import com.hubspot.jinjava.loader.RelativePathResolver; import com.hubspot.jinjava.loader.ResourceLocator; import com.hubspot.jinjava.mode.EagerExecutionMode; +import com.hubspot.jinjava.testobjects.EagerImportTagTestObjects; import com.hubspot.jinjava.tree.parse.DefaultTokenScannerSymbols; import com.hubspot.jinjava.tree.parse.TagToken; import java.io.IOException; @@ -48,7 +48,7 @@ public class EagerImportTagTest extends ImportTagTest { @Before public void eagerSetup() throws Exception { context.put("padding", 42); - context.registerFilter(new PrintPathFilter()); + context.registerFilter(new EagerImportTagTestObjects.PrintPathFilter()); interpreter = new JinjavaInterpreter( jinjava, @@ -767,19 +767,6 @@ public Optional getLocationResolver() { ); } - public static class PrintPathFilter implements Filter { - - @Override - public Object filter(Object var, JinjavaInterpreter interpreter, String... args) { - return interpreter.getContext().getCurrentPathStack().peek().orElse("/"); - } - - @Override - public String getName() { - return "print_path"; - } - } - @Test @Ignore @Override diff --git a/src/test/java/com/hubspot/jinjava/lib/tag/eager/EagerTagDecoratorTest.java b/src/test/java/com/hubspot/jinjava/lib/tag/eager/EagerTagDecoratorTest.java index 6383457cd..9c26ea35b 100644 --- a/src/test/java/com/hubspot/jinjava/lib/tag/eager/EagerTagDecoratorTest.java +++ b/src/test/java/com/hubspot/jinjava/lib/tag/eager/EagerTagDecoratorTest.java @@ -15,11 +15,9 @@ import com.hubspot.jinjava.lib.fn.ELFunctionDefinition; import com.hubspot.jinjava.lib.tag.Tag; import com.hubspot.jinjava.mode.EagerExecutionMode; -import com.hubspot.jinjava.objects.collections.PyList; -import com.hubspot.jinjava.objects.serialization.PyishSerializable; +import com.hubspot.jinjava.testobjects.EagerTagDecoratorTestObjects; import com.hubspot.jinjava.tree.TagNode; import com.hubspot.jinjava.tree.parse.TagToken; -import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.junit.After; @@ -158,22 +156,11 @@ public static void modifyContext(String key, Object value) { ((List) JinjavaInterpreter.getCurrent().getContext().get(key)).add(value); } - static class TooBig extends PyList implements PyishSerializable { - - public TooBig(List list) { - super(list); - } - - @Override - public T appendPyishString(T appendable) - throws IOException { - throw new OutputTooBigException(1, 1); - } - } - @Test public void itDefersNodeWhenOutputTooBigIsThrownWithinInnerInterpret() { - TooBig tooBig = new TooBig(new ArrayList<>()); + EagerTagDecoratorTestObjects.TooBig tooBig = new EagerTagDecoratorTestObjects.TooBig( + new ArrayList<>() + ); interpreter = new JinjavaInterpreter( jinjava, diff --git a/src/test/java/com/hubspot/jinjava/objects/serialization/PyishObjectMapperTest.java b/src/test/java/com/hubspot/jinjava/objects/serialization/PyishObjectMapperTest.java index 1f68b62c3..f3e1aca67 100644 --- a/src/test/java/com/hubspot/jinjava/objects/serialization/PyishObjectMapperTest.java +++ b/src/test/java/com/hubspot/jinjava/objects/serialization/PyishObjectMapperTest.java @@ -11,6 +11,7 @@ import com.hubspot.jinjava.interpret.JinjavaInterpreter; import com.hubspot.jinjava.interpret.OutputTooBigException; import com.hubspot.jinjava.objects.collections.SizeLimitingPyMap; +import com.hubspot.jinjava.testobjects.PyishObjectMapperTestObjects; import java.util.AbstractMap; import java.util.ArrayList; import java.util.HashMap; @@ -116,7 +117,9 @@ public void itLimitsOutputSize() { @Test public void itSerializesToSnakeCaseAccessibleMap() { - assertThat(PyishObjectMapper.getAsPyishString(new Foo("bar"))) + assertThat( + PyishObjectMapper.getAsPyishString(new PyishObjectMapperTestObjects.Foo("bar")) + ) .isEqualTo("{'fooBar': 'bar'} |allow_snake_case"); } @@ -124,7 +127,10 @@ public void itSerializesToSnakeCaseAccessibleMap() { public void itSerializesToSnakeCaseAccessibleMapWhenInMapEntry() { assertThat( PyishObjectMapper.getAsPyishString( - new AbstractMap.SimpleImmutableEntry<>("foo", new Foo("bar")) + new AbstractMap.SimpleImmutableEntry<>( + "foo", + new PyishObjectMapperTestObjects.Foo("bar") + ) ) ) .isEqualTo("fn:map_entry('foo', {'fooBar': 'bar'} |allow_snake_case)"); @@ -141,7 +147,7 @@ public void itDoesNotConvertToSnakeCaseMapWhenResultIsForOutput() { .build() ); JinjavaInterpreter interpreter = jinjava.newInterpreter(); - interpreter.getContext().put("foo", new Foo("bar")); + interpreter.getContext().put("foo", new PyishObjectMapperTestObjects.Foo("bar")); assertThat(interpreter.render("{{ foo }}")).isEqualTo("{'fooBar': 'bar'}"); } @@ -162,7 +168,7 @@ public void itSerializesToSnakeCaseWhenLegacyOverrideIsSet() { JinjavaInterpreter interpreter = jinjava.newInterpreter(); try { JinjavaInterpreter.pushCurrent(interpreter); - interpreter.getContext().put("foo", new Foo("bar")); + interpreter.getContext().put("foo", new PyishObjectMapperTestObjects.Foo("bar")); assertThat(interpreter.render("{{ foo }}")).isEqualTo("{'foo_bar': 'bar'}"); } finally { JinjavaInterpreter.popCurrent(); @@ -173,17 +179,4 @@ public void itSerializesToSnakeCaseWhenLegacyOverrideIsSet() { public void itSerializesOptional() { assertThat(PyishObjectMapper.getAsPyishString(Optional.of("foo"))).isEqualTo("'foo'"); } - - static class Foo { - - private final String bar; - - public Foo(String bar) { - this.bar = bar; - } - - public String getFooBar() { - return bar; - } - } } diff --git a/src/test/java/com/hubspot/jinjava/testobjects/AstDictTestObjects.java b/src/test/java/com/hubspot/jinjava/testobjects/AstDictTestObjects.java new file mode 100644 index 000000000..68c81e37e --- /dev/null +++ b/src/test/java/com/hubspot/jinjava/testobjects/AstDictTestObjects.java @@ -0,0 +1,36 @@ +package com.hubspot.jinjava.testobjects; + +import com.hubspot.jinjava.interpret.TemplateError; +import java.util.Map; + +public class AstDictTestObjects { + + public static class TestClass { + + private Map myMap; + + public TestClass(Map myMap) { + this.myMap = myMap; + } + + public Map getMyMap() { + return myMap; + } + } + + public static enum TestEnum { + FOO("fooName"), + BAR("barName"); + + private String name; + + TestEnum(String name) { + this.name = name; + } + + @Override + public String toString() { + return name; + } + } +} diff --git a/src/test/java/com/hubspot/jinjava/testobjects/EagerAstDotTestObjects.java b/src/test/java/com/hubspot/jinjava/testobjects/EagerAstDotTestObjects.java new file mode 100644 index 000000000..68619a042 --- /dev/null +++ b/src/test/java/com/hubspot/jinjava/testobjects/EagerAstDotTestObjects.java @@ -0,0 +1,23 @@ +package com.hubspot.jinjava.testobjects; + +import com.hubspot.jinjava.interpret.DeferredValueException; +import com.hubspot.jinjava.interpret.PartiallyDeferredValue; + +public class EagerAstDotTestObjects { + + public static class Foo implements PartiallyDeferredValue { + + public String getDeferred() { + throw new DeferredValueException("foo.deferred is deferred"); + } + + public String getResolved() { + return "resolved"; + } + + @Override + public Object getOriginalValue() { + return null; + } + } +} diff --git a/src/test/java/com/hubspot/jinjava/testobjects/EagerExpressionResolverTestObjects.java b/src/test/java/com/hubspot/jinjava/testobjects/EagerExpressionResolverTestObjects.java new file mode 100644 index 000000000..d51006361 --- /dev/null +++ b/src/test/java/com/hubspot/jinjava/testobjects/EagerExpressionResolverTestObjects.java @@ -0,0 +1,58 @@ +package com.hubspot.jinjava.testobjects; + +import com.hubspot.jinjava.interpret.DeferredValueException; +import com.hubspot.jinjava.objects.serialization.PyishSerializable; +import java.io.IOException; + +public class EagerExpressionResolverTestObjects { + + public static class Foo { + + private final String bar; + + public Foo(String bar) { + this.bar = bar; + } + + public String bar() { + return bar; + } + + public String echo(String toEcho) { + return toEcho; + } + } + + public static class SomethingExceptionallyPyish implements PyishSerializable { + + private String name; + + public SomethingExceptionallyPyish(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + @Override + @SuppressWarnings("unchecked") + public T appendPyishString(T appendable) + throws IOException { + throw new DeferredValueException("Can't serialize"); + } + } + + public static class SomethingPyish implements PyishSerializable { + + private String name; + + public SomethingPyish(String name) { + this.name = name; + } + + public String getName() { + return name; + } + } +} diff --git a/src/test/java/com/hubspot/jinjava/testobjects/EagerImportTagTestObjects.java b/src/test/java/com/hubspot/jinjava/testobjects/EagerImportTagTestObjects.java new file mode 100644 index 000000000..4610c493e --- /dev/null +++ b/src/test/java/com/hubspot/jinjava/testobjects/EagerImportTagTestObjects.java @@ -0,0 +1,20 @@ +package com.hubspot.jinjava.testobjects; + +import com.hubspot.jinjava.interpret.JinjavaInterpreter; +import com.hubspot.jinjava.lib.filter.Filter; + +public class EagerImportTagTestObjects { + + public static class PrintPathFilter implements Filter { + + @Override + public Object filter(Object var, JinjavaInterpreter interpreter, String... args) { + return interpreter.getContext().getCurrentPathStack().peek().orElse("/"); + } + + @Override + public String getName() { + return "print_path"; + } + } +} diff --git a/src/test/java/com/hubspot/jinjava/testobjects/EagerTagDecoratorTestObjects.java b/src/test/java/com/hubspot/jinjava/testobjects/EagerTagDecoratorTestObjects.java new file mode 100644 index 000000000..e6b675c78 --- /dev/null +++ b/src/test/java/com/hubspot/jinjava/testobjects/EagerTagDecoratorTestObjects.java @@ -0,0 +1,23 @@ +package com.hubspot.jinjava.testobjects; + +import com.hubspot.jinjava.interpret.OutputTooBigException; +import com.hubspot.jinjava.objects.collections.PyList; +import com.hubspot.jinjava.objects.serialization.PyishSerializable; +import java.io.IOException; +import java.util.List; + +public class EagerTagDecoratorTestObjects { + + public static class TooBig extends PyList implements PyishSerializable { + + public TooBig(List list) { + super(list); + } + + @Override + public T appendPyishString(T appendable) + throws IOException { + throw new OutputTooBigException(1, 1); + } + } +} diff --git a/src/test/java/com/hubspot/jinjava/testobjects/ExpressionResolverTestObjects.java b/src/test/java/com/hubspot/jinjava/testobjects/ExpressionResolverTestObjects.java new file mode 100644 index 000000000..a9d030ee5 --- /dev/null +++ b/src/test/java/com/hubspot/jinjava/testobjects/ExpressionResolverTestObjects.java @@ -0,0 +1,160 @@ +package com.hubspot.jinjava.testobjects; + +import com.google.common.collect.ForwardingList; +import com.google.common.collect.ImmutableMap; +import com.hubspot.jinjava.objects.PyWrapper; +import java.util.Collection; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; + +public class ExpressionResolverTestObjects { + + public static class MyCustomList extends ForwardingList implements PyWrapper { + + private final List list; + + public MyCustomList(List list) { + this.list = list; + } + + @Override + protected List delegate() { + return list; + } + + public int getTotalCount() { + return list.size(); + } + } + + public static final class MyCustomMap implements Map { + + Map data = ImmutableMap.of("foo", "bar", "two", "2", "size", "777"); + + @Override + public int size() { + return data.size(); + } + + @Override + public boolean isEmpty() { + return data.isEmpty(); + } + + @Override + public boolean containsKey(Object key) { + return data.containsKey(key); + } + + @Override + public boolean containsValue(Object value) { + return data.containsValue(value); + } + + @Override + public String get(Object key) { + return data.get(key); + } + + @Override + public String put(String key, String value) { + return null; + } + + @Override + public String remove(Object key) { + return null; + } + + @Override + public void putAll(Map m) {} + + @Override + public void clear() {} + + @Override + public Set keySet() { + return data.keySet(); + } + + @Override + public Collection values() { + return data.values(); + } + + @Override + public Set> entrySet() { + return data.entrySet(); + } + } + + public static class TestClass { + + private boolean touched = false; + private String name = "Amazing test class"; + + public boolean isTouched() { + return touched; + } + + public void touch() { + this.touched = true; + } + + public String getName() { + return name; + } + } + + public static final class MyClass { + + private Date date; + + public MyClass(Date date) { + this.date = date; + } + + public Class getClazz() { + return this.getClass(); + } + + public Date getDate() { + return date; + } + } + + public static final class OptionalProperty { + + private MyClass nested; + private String val; + + public OptionalProperty(MyClass nested, String val) { + this.nested = nested; + this.val = val; + } + + public Optional getNested() { + return Optional.ofNullable(nested); + } + + public Optional getVal() { + return Optional.ofNullable(val); + } + } + + public static final class NestedOptionalProperty { + + private OptionalProperty nested; + + public NestedOptionalProperty(OptionalProperty nested) { + this.nested = nested; + } + + public Optional getNested() { + return Optional.ofNullable(nested); + } + } +} diff --git a/src/test/java/com/hubspot/jinjava/testobjects/FilterOverrideTestObjects.java b/src/test/java/com/hubspot/jinjava/testobjects/FilterOverrideTestObjects.java new file mode 100644 index 000000000..b235e2a95 --- /dev/null +++ b/src/test/java/com/hubspot/jinjava/testobjects/FilterOverrideTestObjects.java @@ -0,0 +1,26 @@ +package com.hubspot.jinjava.testobjects; + +import com.hubspot.jinjava.interpret.JinjavaInterpreter; +import com.hubspot.jinjava.lib.filter.Filter; + +public class FilterOverrideTestObjects { + + public static class DescriptiveAddFilter implements Filter { + + @Override + public String getName() { + return "add"; + } + + @Override + public Object filter(Object var, JinjavaInterpreter interpreter, String... args) { + return ( + var + + " + " + + args[0] + + " = " + + (Integer.parseInt(var.toString()) + Integer.parseInt(args[0])) + ); + } + } +} diff --git a/src/test/java/com/hubspot/jinjava/testobjects/IfTagTestObjects.java b/src/test/java/com/hubspot/jinjava/testobjects/IfTagTestObjects.java new file mode 100644 index 000000000..9bd2794db --- /dev/null +++ b/src/test/java/com/hubspot/jinjava/testobjects/IfTagTestObjects.java @@ -0,0 +1,21 @@ +package com.hubspot.jinjava.testobjects; + +import com.hubspot.jinjava.util.HasObjectTruthValue; + +public class IfTagTestObjects { + + public static class Foo implements HasObjectTruthValue { + + private boolean objectTruthValue = false; + + public Foo setObjectTruthValue(boolean objectTruthValue) { + this.objectTruthValue = objectTruthValue; + return this; + } + + @Override + public boolean getObjectTruthValue() { + return objectTruthValue; + } + } +} diff --git a/src/test/java/com/hubspot/jinjava/testobjects/JinjavaBeanELResolverTestObjects.java b/src/test/java/com/hubspot/jinjava/testobjects/JinjavaBeanELResolverTestObjects.java new file mode 100644 index 000000000..9d10e6cd7 --- /dev/null +++ b/src/test/java/com/hubspot/jinjava/testobjects/JinjavaBeanELResolverTestObjects.java @@ -0,0 +1,38 @@ +package com.hubspot.jinjava.testobjects; + +public class JinjavaBeanELResolverTestObjects { + + public static class TempItInvokesBestMethodWithSingleParam { + + public String getResult(int a) { + return "int"; + } + + public String getResult(String a) { + return "String"; + } + + public String getResult(Object a) { + return "Object"; + } + + public String getResult(CharSequence a) { + return "CharSequence"; + } + } + + public static class TempItPrefersPrimitives { + + public String getResult(int a, Integer b) { + return "int Integer"; + } + + public String getResult(int a, Object b) { + return "int Object"; + } + + public String getResult(Number a, int b) { + return "Number int"; + } + } +} diff --git a/src/test/java/com/hubspot/jinjava/testobjects/JinjavaInterpreterTestObjects.java b/src/test/java/com/hubspot/jinjava/testobjects/JinjavaInterpreterTestObjects.java new file mode 100644 index 000000000..2bd11365a --- /dev/null +++ b/src/test/java/com/hubspot/jinjava/testobjects/JinjavaInterpreterTestObjects.java @@ -0,0 +1,32 @@ +package com.hubspot.jinjava.testobjects; + +import com.fasterxml.jackson.annotation.JsonIgnore; + +public class JinjavaInterpreterTestObjects { + + public static class Foo { + + private String bar; + + public Foo(String bar) { + this.bar = bar; + } + + public String getBar() { + return bar; + } + + public String getBarFoo() { + return bar; + } + + public String getBarFoo1() { + return bar; + } + + @JsonIgnore + public String getBarHidden() { + return bar; + } + } +} diff --git a/src/test/java/com/hubspot/jinjava/testobjects/PartiallyDeferredValueTestObjects.java b/src/test/java/com/hubspot/jinjava/testobjects/PartiallyDeferredValueTestObjects.java new file mode 100644 index 000000000..c7c579412 --- /dev/null +++ b/src/test/java/com/hubspot/jinjava/testobjects/PartiallyDeferredValueTestObjects.java @@ -0,0 +1,135 @@ +package com.hubspot.jinjava.testobjects; + +import com.hubspot.jinjava.interpret.DeferredValueException; +import com.hubspot.jinjava.interpret.PartiallyDeferredValue; +import com.hubspot.jinjava.objects.collections.PyMap; +import com.hubspot.jinjava.objects.serialization.PyishSerializable; +import java.io.IOException; +import java.util.Map; +import java.util.Set; +import javax.annotation.CheckForNull; + +public class PartiallyDeferredValueTestObjects { + + public static class BadSerialization implements PartiallyDeferredValue { + + public String getDeferred() { + throw new DeferredValueException("foo.deferred is deferred"); + } + + public String getResolved() { + return "resolved"; + } + + @Override + public Object getOriginalValue() { + return null; + } + } + + public static class BadEntrySet extends PyMap implements PartiallyDeferredValue { + + public BadEntrySet(Map map) { + super(map); + } + + @Override + public Set> entrySet() { + throw new DeferredValueException("entries are deferred"); + } + + @CheckForNull + @Override + public Object get(@CheckForNull Object key) { + if ("deferred".equals(key)) { + throw new DeferredValueException("deferred key"); + } + return super.get(key); + } + + @Override + public Object getOriginalValue() { + return null; + } + } + + public static class BadPyishSerializable + implements PartiallyDeferredValue, PyishSerializable { + + public String getDeferred() { + throw new DeferredValueException("foo.deferred is deferred"); + } + + public String getResolved() { + return "resolved"; + } + + @Override + public Object getOriginalValue() { + return null; + } + + @Override + public T appendPyishString(T appendable) + throws IOException { + throw new DeferredValueException("I'm bad"); + } + } + + public static class GoodPyishSerializable + implements PartiallyDeferredValue, PyishSerializable { + + public String getDeferred() { + throw new DeferredValueException("foo.deferred is deferred"); + } + + public String getResolved() { + return "resolved"; + } + + @Override + public Object getOriginalValue() { + return null; + } + + @Override + public T appendPyishString(T appendable) + throws IOException { + return (T) appendable.append("good"); + } + } + + public static class BadEntrySetButPyishSerializable + extends PyMap + implements PartiallyDeferredValue, PyishSerializable { + + public BadEntrySetButPyishSerializable(Map map) { + super(map); + } + + @Override + public Set> entrySet() { + throw new DeferredValueException("entries are deferred"); + } + + @CheckForNull + @Override + public Object get(@CheckForNull Object key) { + if ("deferred".equals(key)) { + throw new DeferredValueException("deferred key"); + } + return super.get(key); + } + + @Override + public Object getOriginalValue() { + return null; + } + + @Override + public T appendPyishString(T appendable) + throws IOException { + return (T) appendable.append("hello"); + } + } +} diff --git a/src/test/java/com/hubspot/jinjava/testobjects/PyishObjectMapperTestObjects.java b/src/test/java/com/hubspot/jinjava/testobjects/PyishObjectMapperTestObjects.java new file mode 100644 index 000000000..c08c994d4 --- /dev/null +++ b/src/test/java/com/hubspot/jinjava/testobjects/PyishObjectMapperTestObjects.java @@ -0,0 +1,17 @@ +package com.hubspot.jinjava.testobjects; + +public class PyishObjectMapperTestObjects { + + public static class Foo { + + private final String bar; + + public Foo(String bar) { + this.bar = bar; + } + + public String getFooBar() { + return bar; + } + } +} diff --git a/src/test/java/com/hubspot/jinjava/testobjects/SortFilterTestObjects.java b/src/test/java/com/hubspot/jinjava/testobjects/SortFilterTestObjects.java new file mode 100644 index 000000000..cc985cda0 --- /dev/null +++ b/src/test/java/com/hubspot/jinjava/testobjects/SortFilterTestObjects.java @@ -0,0 +1,58 @@ +package com.hubspot.jinjava.testobjects; + +import com.hubspot.jinjava.objects.serialization.PyishSerializable; +import java.io.IOException; +import java.util.Date; + +public class SortFilterTestObjects { + + public static class MyFoo implements PyishSerializable { + + private Date date; + + public MyFoo(Date date) { + this.date = date; + } + + public Date getDate() { + return date; + } + + @Override + public String toString() { + return "" + date.getTime(); + } + + @Override + @SuppressWarnings("unchecked") + public T appendPyishString(T appendable) + throws IOException { + return (T) appendable.append(toString()); + } + } + + public static class MyBar implements PyishSerializable { + + private MyFoo foo; + + public MyBar(MyFoo foo) { + this.foo = foo; + } + + public MyFoo getFoo() { + return foo; + } + + @Override + public String toString() { + return foo.toString(); + } + + @Override + @SuppressWarnings("unchecked") + public T appendPyishString(T appendable) + throws IOException { + return (T) appendable.append(toString()); + } + } +} diff --git a/src/test/java/com/hubspot/jinjava/testobjects/UniqueFilterTestObjects.java b/src/test/java/com/hubspot/jinjava/testobjects/UniqueFilterTestObjects.java new file mode 100644 index 000000000..034804fc3 --- /dev/null +++ b/src/test/java/com/hubspot/jinjava/testobjects/UniqueFilterTestObjects.java @@ -0,0 +1,32 @@ +package com.hubspot.jinjava.testobjects; + +import com.hubspot.jinjava.objects.serialization.PyishSerializable; +import java.io.IOException; + +public class UniqueFilterTestObjects { + + public static class MyClass implements PyishSerializable { + + private final String name; + + public MyClass(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + @Override + public String toString() { + return "[Name:" + name + "]"; + } + + @Override + @SuppressWarnings("unchecked") + public T appendPyishString(T appendable) + throws IOException { + return (T) appendable.append(toString()); + } + } +} diff --git a/src/test/java/com/hubspot/jinjava/testobjects/ValidationModeTestObjects.java b/src/test/java/com/hubspot/jinjava/testobjects/ValidationModeTestObjects.java new file mode 100644 index 000000000..3aaa9306b --- /dev/null +++ b/src/test/java/com/hubspot/jinjava/testobjects/ValidationModeTestObjects.java @@ -0,0 +1,27 @@ +package com.hubspot.jinjava.testobjects; + +import com.hubspot.jinjava.interpret.JinjavaInterpreter; +import com.hubspot.jinjava.lib.filter.Filter; + +public class ValidationModeTestObjects { + + public static class ValidationFilter implements Filter { + + private int executionCount = 0; + + @Override + public Object filter(Object var, JinjavaInterpreter interpreter, String... args) { + executionCount++; + return var; + } + + public int getExecutionCount() { + return executionCount; + } + + @Override + public String getName() { + return "validation_filter"; + } + } +} diff --git a/src/test/java/com/hubspot/jinjava/util/EagerExpressionResolverTest.java b/src/test/java/com/hubspot/jinjava/util/EagerExpressionResolverTest.java index 2e1d962cf..bc8a211ad 100644 --- a/src/test/java/com/hubspot/jinjava/util/EagerExpressionResolverTest.java +++ b/src/test/java/com/hubspot/jinjava/util/EagerExpressionResolverTest.java @@ -18,8 +18,8 @@ import com.hubspot.jinjava.objects.collections.PyMap; import com.hubspot.jinjava.objects.date.PyishDate; import com.hubspot.jinjava.objects.serialization.PyishObjectMapper; -import com.hubspot.jinjava.objects.serialization.PyishSerializable; import com.hubspot.jinjava.random.RandomNumberGeneratorStrategy; +import com.hubspot.jinjava.testobjects.EagerExpressionResolverTestObjects; import com.hubspot.jinjava.tree.parse.DefaultTokenScannerSymbols; import com.hubspot.jinjava.tree.parse.TagToken; import com.hubspot.jinjava.tree.parse.TokenScannerSymbols; @@ -449,15 +449,17 @@ public void itDoesntSplitOnBar() { public void itDoesntResolveNonPyishSerializable() { PyMap dict = new PyMap(new HashMap<>()); context.put("dict", dict); - context.put("foo", new Foo("bar")); + context.put("foo", new EagerExpressionResolverTestObjects.Foo("bar")); context.put("mark", "!"); EagerExpressionResult eagerExpressionResult = eagerResolveExpression( "dict.update({'foo': foo})" ); assertThat(WhitespaceUtils.unquoteAndUnescape(eagerExpressionResult.toString())) .isEqualTo(""); - assertThat(dict.get("foo")).isInstanceOf(Foo.class); - assertThat(((Foo) dict.get("foo")).bar()).isEqualTo("bar"); + assertThat(dict.get("foo")) + .isInstanceOf(EagerExpressionResolverTestObjects.Foo.class); + assertThat(((EagerExpressionResolverTestObjects.Foo) dict.get("foo")).bar()) + .isEqualTo("bar"); } @Test @@ -597,7 +599,7 @@ public void itHandlesNegativeZero() { @Test public void itHandlesPyishSerializable() { - context.put("foo", new SomethingPyish("yes")); + context.put("foo", new EagerExpressionResolverTestObjects.SomethingPyish("yes")); assertThat( interpreter.render( String.format("{{ %s.name }}", eagerResolveExpression("foo").toString()) @@ -608,7 +610,10 @@ public void itHandlesPyishSerializable() { @Test public void itHandlesPyishSerializableWithProcessingException() { - context.put("foo", new SomethingExceptionallyPyish("yes")); + context.put( + "foo", + new EagerExpressionResolverTestObjects.SomethingExceptionallyPyish("yes") + ); context.addMetaContextVariables(Collections.singleton("foo")); assertThat(interpreter.render("{{ deferred && (1 == 2 || foo) }}")) .isEqualTo("{{ deferred && (false || foo) }}"); @@ -908,56 +913,6 @@ public static Optional optionally(boolean hasValue) { return Optional.of(hasValue).filter(Boolean::booleanValue).map(ignored -> "1"); } - private static class Foo { - - private final String bar; - - Foo(String bar) { - this.bar = bar; - } - - String bar() { - return bar; - } - - String echo(String toEcho) { - return toEcho; - } - } - - public class SomethingPyish implements PyishSerializable { - - private String name; - - public SomethingPyish(String name) { - this.name = name; - } - - public String getName() { - return name; - } - } - - public class SomethingExceptionallyPyish implements PyishSerializable { - - private String name; - - public SomethingExceptionallyPyish(String name) { - this.name = name; - } - - public String getName() { - return name; - } - - @Override - @SuppressWarnings("unchecked") - public T appendPyishString(T appendable) - throws IOException { - throw new DeferredValueException("Can't serialize"); - } - } - @Test public void itCountsBigDecimalAsPrimitive() { assertThat(EagerExpressionResolver.isResolvableObject(new BigDecimal("2.1E7")))