Repository: incubator-freemarker Updated Branches: refs/heads/3 87d905f0c -> e3e7f1e2d
(Some code cleanup in TemplateDirectiveModel and TemplateFunctionModel implementations.) Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/e3e7f1e2 Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/e3e7f1e2 Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/e3e7f1e2 Branch: refs/heads/3 Commit: e3e7f1e2d212f2cfa25d62d702db79dbfc18ba7f Parents: 87d905f Author: ddekany <ddek...@apache.org> Authored: Mon Aug 21 01:16:45 2017 +0200 Committer: ddekany <ddek...@apache.org> Committed: Mon Aug 21 01:16:45 2017 +0200 ---------------------------------------------------------------------- .../core/userpkg/TwoNamedParamsDirective.java | 12 ++--- .../core/userpkg/TwoNamedParamsFunction.java | 12 ++--- .../apache/freemarker/servlet/IncludePage.java | 14 +++--- .../test/templateutil/AssertDirective.java | 4 +- .../templateutil/AssertEqualsDirective.java | 14 +++--- .../test/templateutil/AssertFailsDirective.java | 46 ++++++++++---------- .../AssertationFailedInTemplateException.java | 46 -------------------- .../AssertionFailedInTemplateException.java | 46 ++++++++++++++++++++ 8 files changed, 95 insertions(+), 99 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/e3e7f1e2/freemarker-core-test/src/test/java/org/apache/freemarker/core/userpkg/TwoNamedParamsDirective.java ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/java/org/apache/freemarker/core/userpkg/TwoNamedParamsDirective.java b/freemarker-core-test/src/test/java/org/apache/freemarker/core/userpkg/TwoNamedParamsDirective.java index 3b3ed1c..2d02e07 100644 --- a/freemarker-core-test/src/test/java/org/apache/freemarker/core/userpkg/TwoNamedParamsDirective.java +++ b/freemarker-core-test/src/test/java/org/apache/freemarker/core/userpkg/TwoNamedParamsDirective.java @@ -40,13 +40,13 @@ public class TwoNamedParamsDirective extends TestTemplateCallableModel implement private static final String N1_ARG_NAME = "n1"; private static final String N2_ARG_NAME = "n2"; - private static final StringToIndexMap ARG_NAME_TO_IDX = StringToIndexMap.of( - N1_ARG_NAME, N1_ARG_IDX, - N2_ARG_NAME, N2_ARG_IDX); - private static final ArgumentArrayLayout ARGS_LAYOUT = ArgumentArrayLayout.create( - 0, false, - ARG_NAME_TO_IDX, false); + 0, + false, + StringToIndexMap.of( + N1_ARG_NAME, N1_ARG_IDX, + N2_ARG_NAME, N2_ARG_IDX), + false); private TwoNamedParamsDirective() { // http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/e3e7f1e2/freemarker-core-test/src/test/java/org/apache/freemarker/core/userpkg/TwoNamedParamsFunction.java ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/java/org/apache/freemarker/core/userpkg/TwoNamedParamsFunction.java b/freemarker-core-test/src/test/java/org/apache/freemarker/core/userpkg/TwoNamedParamsFunction.java index f4e4c3b..7ef1253 100644 --- a/freemarker-core-test/src/test/java/org/apache/freemarker/core/userpkg/TwoNamedParamsFunction.java +++ b/freemarker-core-test/src/test/java/org/apache/freemarker/core/userpkg/TwoNamedParamsFunction.java @@ -38,13 +38,13 @@ public class TwoNamedParamsFunction extends TestTemplateCallableModel implements private static final String N1_ARG_NAME = "n1"; private static final String N2_ARG_NAME = "n2"; - private static final StringToIndexMap ARG_NAME_TO_IDX = StringToIndexMap.of( - N1_ARG_NAME, N1_ARG_IDX, - N2_ARG_NAME, N2_ARG_IDX); - private static final ArgumentArrayLayout ARGS_LAYOUT = ArgumentArrayLayout.create( - 0, false, - ARG_NAME_TO_IDX, false); + 0, + false, + StringToIndexMap.of( + N1_ARG_NAME, N1_ARG_IDX, + N2_ARG_NAME, N2_ARG_IDX), + false); private TwoNamedParamsFunction() { // http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/e3e7f1e2/freemarker-servlet/src/main/java/org/apache/freemarker/servlet/IncludePage.java ---------------------------------------------------------------------- diff --git a/freemarker-servlet/src/main/java/org/apache/freemarker/servlet/IncludePage.java b/freemarker-servlet/src/main/java/org/apache/freemarker/servlet/IncludePage.java index 5e52043..ca13842 100644 --- a/freemarker-servlet/src/main/java/org/apache/freemarker/servlet/IncludePage.java +++ b/freemarker-servlet/src/main/java/org/apache/freemarker/servlet/IncludePage.java @@ -72,14 +72,14 @@ public class IncludePage implements TemplateDirectiveModel { private static final String INHERIT_PARAMS_PARAM_NAME = "inherit_params"; private static final String PARAMS_PARAM_NAME = "params"; - private static final StringToIndexMap NAME_TO_IDX_MAP = StringToIndexMap.of( - PATH_PARAM_NAME, PATH_PARAM_IDX, - INHERIT_PARAMS_PARAM_NAME, INHERIT_PARAMS_PARAM_IDX - ); - private static final ArgumentArrayLayout ARGS_LAYOUT = ArgumentArrayLayout.create( - 0, false, - NAME_TO_IDX_MAP, false + 0, + false, + StringToIndexMap.of( + PATH_PARAM_NAME, PATH_PARAM_IDX, + INHERIT_PARAMS_PARAM_NAME, INHERIT_PARAMS_PARAM_IDX + ), + false ); public IncludePage(HttpServletRequest request, HttpServletResponse response) { http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/e3e7f1e2/freemarker-test-utils/src/main/java/org/apache/freemarker/test/templateutil/AssertDirective.java ---------------------------------------------------------------------- diff --git a/freemarker-test-utils/src/main/java/org/apache/freemarker/test/templateutil/AssertDirective.java b/freemarker-test-utils/src/main/java/org/apache/freemarker/test/templateutil/AssertDirective.java index caccdc6..0b91482 100644 --- a/freemarker-test-utils/src/main/java/org/apache/freemarker/test/templateutil/AssertDirective.java +++ b/freemarker-test-utils/src/main/java/org/apache/freemarker/test/templateutil/AssertDirective.java @@ -39,9 +39,7 @@ public class AssertDirective implements TemplateDirectiveModel { public void execute(TemplateModel[] args, CallPlace callPlace, Writer out, Environment env) throws TemplateException, IOException { if (!CallableUtils.getBooleanArgument(args, 0, this)) { - throw new AssertationFailedInTemplateException("Assertion failed:\n" - + "the value was false.", - env); + throw new AssertionFailedInTemplateException("Assertion failed:\n" + "the value was false.", env); } } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/e3e7f1e2/freemarker-test-utils/src/main/java/org/apache/freemarker/test/templateutil/AssertEqualsDirective.java ---------------------------------------------------------------------- diff --git a/freemarker-test-utils/src/main/java/org/apache/freemarker/test/templateutil/AssertEqualsDirective.java b/freemarker-test-utils/src/main/java/org/apache/freemarker/test/templateutil/AssertEqualsDirective.java index 213dfbb..27c1ba2 100644 --- a/freemarker-test-utils/src/main/java/org/apache/freemarker/test/templateutil/AssertEqualsDirective.java +++ b/freemarker-test-utils/src/main/java/org/apache/freemarker/test/templateutil/AssertEqualsDirective.java @@ -43,13 +43,13 @@ public class AssertEqualsDirective implements TemplateDirectiveModel { private static final int ACTUAL_ARG_IDX = 0; private static final int EXPECTED_ARG_IDX = 1; - private static final StringToIndexMap ARG_NAME_TO_IDX = StringToIndexMap.of( - "actual", ACTUAL_ARG_IDX, - "expected", EXPECTED_ARG_IDX); - private static final ArgumentArrayLayout ARGS_LAYOUT = ArgumentArrayLayout.create( - 0, false, - ARG_NAME_TO_IDX, false); + 0, + false, + StringToIndexMap.of( + "actual", ACTUAL_ARG_IDX, + "expected", EXPECTED_ARG_IDX), + false); private AssertEqualsDirective() { } @@ -59,7 +59,7 @@ public class AssertEqualsDirective implements TemplateDirectiveModel { TemplateModel actual = CallableUtils.getArgument(args, ACTUAL_ARG_IDX, null, this); TemplateModel expected = CallableUtils.getArgument(args, ACTUAL_ARG_IDX, null, this); if (!env.applyEqualsOperatorLenient(actual, expected)) { - throw new AssertationFailedInTemplateException("Assertion failed:\n" + throw new AssertionFailedInTemplateException("Assertion failed:\n" + "Expected: " + tryUnwrap(expected) + "\n" + "Actual: " + tryUnwrap(actual), env); http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/e3e7f1e2/freemarker-test-utils/src/main/java/org/apache/freemarker/test/templateutil/AssertFailsDirective.java ---------------------------------------------------------------------- diff --git a/freemarker-test-utils/src/main/java/org/apache/freemarker/test/templateutil/AssertFailsDirective.java b/freemarker-test-utils/src/main/java/org/apache/freemarker/test/templateutil/AssertFailsDirective.java index 855eb55..84e22a0 100644 --- a/freemarker-test-utils/src/main/java/org/apache/freemarker/test/templateutil/AssertFailsDirective.java +++ b/freemarker-test-utils/src/main/java/org/apache/freemarker/test/templateutil/AssertFailsDirective.java @@ -43,15 +43,15 @@ public class AssertFailsDirective implements TemplateDirectiveModel { private static final int EXCEPTION_ARG_IDX = 2; private static final int CAUSE_NESTING_LEVEL_ARG_IDX = 3; - private static final StringToIndexMap ARG_NAME_TO_IDX = StringToIndexMap.of( - "message", MESSAGE_ARG_IDX, - "messageRegexp", MESSAGE_REGEXP_ARG_IDX, - "exception", EXCEPTION_ARG_IDX, - "causeNestingLevel", CAUSE_NESTING_LEVEL_ARG_IDX); - private static final ArgumentArrayLayout ARGS_LAYOUT = ArgumentArrayLayout.create( - 0, false, - ARG_NAME_TO_IDX, false); + 0, + false, + StringToIndexMap.of( + "message", MESSAGE_ARG_IDX, + "messageRegexp", MESSAGE_REGEXP_ARG_IDX, + "exception", EXCEPTION_ARG_IDX, + "causeNestingLevel", CAUSE_NESTING_LEVEL_ARG_IDX), + false); private AssertFailsDirective() { } @@ -84,7 +84,7 @@ public class AssertFailsDirective implements TemplateDirectiveModel { while (causeNestingLevelCountDown != 0) { e = e.getCause(); if (e == null) { - throw new AssertationFailedInTemplateException( + throw new AssertionFailedInTemplateException( "Failure is not like expected: The cause exception nesting dept was lower than " + causeNestingLevel + ".", env); @@ -94,7 +94,7 @@ public class AssertFailsDirective implements TemplateDirectiveModel { if (message != null || messageRegexp != null) { if (e.getMessage() == null) { - throw new AssertationFailedInTemplateException( + throw new AssertionFailedInTemplateException( "Failure is not like expected. The exception message was null, " + "and thus it doesn't contain:\n" + _StringUtils.jQuote(message) + ".", env); @@ -103,37 +103,35 @@ public class AssertFailsDirective implements TemplateDirectiveModel { String actualMessage = e instanceof TemplateException ? ((TemplateException) e).getMessageWithoutStackTop() : e.getMessage(); if (!actualMessage.toLowerCase().contains(message.toLowerCase())) { - throw new AssertationFailedInTemplateException( - "Failure is not like expected. The exception message:\n" + _StringUtils - .jQuote(actualMessage) + throw new AssertionFailedInTemplateException( + "Failure is not like expected. The exception message:\n" + + _StringUtils.jQuote(actualMessage) + "\ndoesn't contain:\n" + _StringUtils.jQuote(message) + ".", env); } } if (messageRegexp != null) { if (!messageRegexp.matcher(e.getMessage()).find()) { - throw new AssertationFailedInTemplateException( - "Failure is not like expected. The exception message:\n" + _StringUtils - .jQuote(e.getMessage()) - + "\ndoesn't match this regexp:\n" + _StringUtils - .jQuote(messageRegexp.toString()) + throw new AssertionFailedInTemplateException( + "Failure is not like expected. The exception message:\n" + + _StringUtils.jQuote(e.getMessage()) + + "\ndoesn't match this regexp:\n" + + _StringUtils.jQuote(messageRegexp.toString()) + ".", env); } } } if (exception != null && !e.getClass().getName().contains(exception)) { - throw new AssertationFailedInTemplateException( - "Failure is not like expected. The exception class name " + _StringUtils - .jQuote(e.getClass().getName()) + throw new AssertionFailedInTemplateException( + "Failure is not like expected. The exception class name " + + _StringUtils.jQuote(e.getClass().getName()) + " doesn't contain " + _StringUtils.jQuote(message) + ".", env); } } if (!blockFailed) { - throw new AssertationFailedInTemplateException( - "Block was expected to fail, but it didn't.", - env); + throw new AssertionFailedInTemplateException("Block was expected to fail, but it didn't.", env); } } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/e3e7f1e2/freemarker-test-utils/src/main/java/org/apache/freemarker/test/templateutil/AssertationFailedInTemplateException.java ---------------------------------------------------------------------- diff --git a/freemarker-test-utils/src/main/java/org/apache/freemarker/test/templateutil/AssertationFailedInTemplateException.java b/freemarker-test-utils/src/main/java/org/apache/freemarker/test/templateutil/AssertationFailedInTemplateException.java deleted file mode 100644 index 346e6ff..0000000 --- a/freemarker-test-utils/src/main/java/org/apache/freemarker/test/templateutil/AssertationFailedInTemplateException.java +++ /dev/null @@ -1,46 +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 org.apache.freemarker.test.templateutil; - -import org.apache.freemarker.core.Environment; -import org.apache.freemarker.core.TemplateException; - -/** - * Fills the role of {@link junit.framework.AssertionFailedError}, but carries the template location information. - */ -public class AssertationFailedInTemplateException extends TemplateException { - - public AssertationFailedInTemplateException(Environment env) { - super(env); - } - - public AssertationFailedInTemplateException(String description, Environment env) { - super(description, env); - } - - public AssertationFailedInTemplateException(Exception cause, Environment env) { - super(cause, env); - } - - public AssertationFailedInTemplateException(String description, Exception cause, Environment env) { - super(description, cause, env); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/e3e7f1e2/freemarker-test-utils/src/main/java/org/apache/freemarker/test/templateutil/AssertionFailedInTemplateException.java ---------------------------------------------------------------------- diff --git a/freemarker-test-utils/src/main/java/org/apache/freemarker/test/templateutil/AssertionFailedInTemplateException.java b/freemarker-test-utils/src/main/java/org/apache/freemarker/test/templateutil/AssertionFailedInTemplateException.java new file mode 100644 index 0000000..204e5ba --- /dev/null +++ b/freemarker-test-utils/src/main/java/org/apache/freemarker/test/templateutil/AssertionFailedInTemplateException.java @@ -0,0 +1,46 @@ +/* + * 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 org.apache.freemarker.test.templateutil; + +import org.apache.freemarker.core.Environment; +import org.apache.freemarker.core.TemplateException; + +/** + * Fills the role of {@link junit.framework.AssertionFailedError}, but carries the template location information. + */ +public class AssertionFailedInTemplateException extends TemplateException { + + public AssertionFailedInTemplateException(Environment env) { + super(env); + } + + public AssertionFailedInTemplateException(String description, Environment env) { + super(description, env); + } + + public AssertionFailedInTemplateException(Exception cause, Environment env) { + super(cause, env); + } + + public AssertionFailedInTemplateException(String description, Exception cause, Environment env) { + super(description, cause, env); + } + +}