diff --git a/freemarker-jython25/src/test/java/freemarker/test/templatesuite/TemplateTestCase.java b/freemarker-jython25/src/test/java/freemarker/test/templatesuite/TemplateTestCase.java index 5e179a258..a4a6553bf 100644 --- a/freemarker-jython25/src/test/java/freemarker/test/templatesuite/TemplateTestCase.java +++ b/freemarker-jython25/src/test/java/freemarker/test/templatesuite/TemplateTestCase.java @@ -56,7 +56,6 @@ import freemarker.ext.beans.BeansWrapper; import freemarker.ext.beans.BeansWrapperBuilder; import freemarker.ext.beans.BooleanModel; -import freemarker.ext.beans.Java7MembersOnlyBeansWrapper; import freemarker.ext.beans.ResourceBundleModel; import freemarker.ext.dom.NodeModel; import freemarker.template.Configuration; @@ -208,13 +207,13 @@ public void setUp() throws Exception { dataModel.put("set", ImmutableSet.of("a", "b", "c")); dataModel.put("s", "test"); } else if (simpleTestName.equals("bean-maps")) { - BeansWrapper w1 = new Java7MembersOnlyBeansWrapper(); - BeansWrapper w2 = new Java7MembersOnlyBeansWrapper(); - BeansWrapper w3 = new Java7MembersOnlyBeansWrapper(); - BeansWrapper w4 = new Java7MembersOnlyBeansWrapper(); - BeansWrapper w5 = new Java7MembersOnlyBeansWrapper(); - BeansWrapper w6 = new Java7MembersOnlyBeansWrapper(); - BeansWrapper w7 = new Java7MembersOnlyBeansWrapper(); + BeansWrapper w1 = new BeansWrapper(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS); + BeansWrapper w2 = new BeansWrapper(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS); + BeansWrapper w3 = new BeansWrapper(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS); + BeansWrapper w4 = new BeansWrapper(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS); + BeansWrapper w5 = new BeansWrapper(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS); + BeansWrapper w6 = new BeansWrapper(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS); + BeansWrapper w7 = new BeansWrapper(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS); w1.setExposureLevel(BeansWrapper.EXPOSE_PROPERTIES_ONLY); w2.setExposureLevel(BeansWrapper.EXPOSE_PROPERTIES_ONLY); diff --git a/freemarker-jython25/src/test/resources/freemarker/test/templatesuite/expected/bean-maps.txt b/freemarker-jython25/src/test/resources/freemarker/test/templatesuite/expected/bean-maps.txt index 3f7dad542..60850de8e 100644 --- a/freemarker-jython25/src/test/resources/freemarker/test/templatesuite/expected/bean-maps.txt +++ b/freemarker-jython25/src/test/resources/freemarker/test/templatesuite/expected/bean-maps.txt @@ -42,61 +42,79 @@ nothing (3): location : San Francisco name : Chris -all, shadow (28): +all, shadow (37): age : 27 class : class freemarker.test.templatesuite.TemplateTestCase$TestMapBean clear : UNKNOWN clone : UNKNOWN + compute : UNKNOWN + computeIfAbsent : UNKNOWN + computeIfPresent : UNKNOWN containsKey : UNKNOWN containsValue : UNKNOWN empty : false entrySet : UNKNOWN equals : UNKNOWN + forEach : UNKNOWN get : UNKNOWN getClass : UNKNOWN getLuckyNumber : UNKNOWN getName : UNKNOWN + getOrDefault : UNKNOWN hashCode : UNKNOWN isEmpty : UNKNOWN keySet : UNKNOWN location : San Francisco luckyNumber : 7 + merge : UNKNOWN name : Christopher notify : UNKNOWN notifyAll : UNKNOWN put : UNKNOWN putAll : UNKNOWN + putIfAbsent : UNKNOWN remove : UNKNOWN + replace : UNKNOWN + replaceAll : UNKNOWN size : UNKNOWN toString : UNKNOWN values : UNKNOWN wait : UNKNOWN -all (28): +all (37): age : 27 class : class freemarker.test.templatesuite.TemplateTestCase$TestMapBean clear : UNKNOWN clone : UNKNOWN + compute : UNKNOWN + computeIfAbsent : UNKNOWN + computeIfPresent : UNKNOWN containsKey : UNKNOWN containsValue : UNKNOWN empty : false entrySet : UNKNOWN equals : UNKNOWN + forEach : UNKNOWN get : UNKNOWN getClass : UNKNOWN getLuckyNumber : UNKNOWN getName : UNKNOWN + getOrDefault : UNKNOWN hashCode : UNKNOWN isEmpty : UNKNOWN keySet : UNKNOWN location : San Francisco luckyNumber : 7 + merge : UNKNOWN name : Chris notify : UNKNOWN notifyAll : UNKNOWN put : UNKNOWN putAll : UNKNOWN + putIfAbsent : UNKNOWN remove : UNKNOWN + replace : UNKNOWN + replaceAll : UNKNOWN size : UNKNOWN toString : UNKNOWN values : UNKNOWN diff --git a/freemarker-test-utils/src/main/java/freemarker/ext/beans/Java7MembersOnlyBeansWrapper.java b/freemarker-test-utils/src/main/java/freemarker/ext/beans/Java7MembersOnlyBeansWrapper.java deleted file mode 100644 index f303e34b2..000000000 --- a/freemarker-test-utils/src/main/java/freemarker/ext/beans/Java7MembersOnlyBeansWrapper.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package freemarker.ext.beans; - -import java.lang.reflect.Method; -import java.util.Collection; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import freemarker.template.Configuration; -import freemarker.template.Version; - -/** - * A hack to keep some unit tests producing exactly the same results on Java 8 as on Java 5-7, by hiding members - * added after Java 7. - */ -public class Java7MembersOnlyBeansWrapper extends BeansWrapper { - - private static final Set POST_JAVA_7_MAP_METHODS = newHashSet( - "compute", "computeIfAbsent", "computeIfPresent", - "forEach", "getOrDefault", "merge", "putIfAbsent", "replace", "replaceAll"); - - private static final Set POST_JAVA_7_ITERABLE_METHODS = newHashSet("forEach"); - private static final Set POST_JAVA_7_COLLECTION_METHODS = newHashSet("parallelStream", "removeIf", "stream"); - private static final Set POST_JAVA_7_LIST_METHODS = newHashSet("sort", "spliterator"); - - MethodAppearanceFineTuner POST_JAVA_7_FILTER = new MethodAppearanceFineTuner() { - - public void process(MethodAppearanceDecisionInput in, MethodAppearanceDecision out) { - Method m = in.getMethod(); - Class declCl = m.getDeclaringClass(); - if (Map.class.isAssignableFrom(declCl)) { - if (POST_JAVA_7_MAP_METHODS.contains(m.getName())) { - hideMember(out); - return; - } - } - if (Iterable.class.isAssignableFrom(declCl)) { - if (POST_JAVA_7_ITERABLE_METHODS.contains(m.getName())) { - hideMember(out); - return; - } - } - if (Collection.class.isAssignableFrom(declCl)) { - if (POST_JAVA_7_COLLECTION_METHODS.contains(m.getName())) { - hideMember(out); - return; - } - } - if (List.class.isAssignableFrom(declCl)) { - if (POST_JAVA_7_LIST_METHODS.contains(m.getName())) { - hideMember(out); - return; - } - } - } - - private void hideMember(MethodAppearanceDecision out) { - out.setExposeMethodAs(null); - out.setExposeAsProperty(null); - } - - }; - - public Java7MembersOnlyBeansWrapper(Version version) { - super(version); - setMethodAppearanceFineTuner(POST_JAVA_7_FILTER); - } - - private static Set newHashSet(T... items) { - HashSet r = new HashSet<>(); - for (T item : items) { - r.add(item); - } - return r; - } - - public Java7MembersOnlyBeansWrapper() { - this(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS); - } - -}