You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@freemarker.apache.org by dd...@apache.org on 2017/08/20 23:07:17 UTC
incubator-freemarker git commit: (Some AssertFailsDirective code
cleanup.)
Repository: incubator-freemarker
Updated Branches:
refs/heads/3 999afd28d -> 87d905f0c
(Some AssertFailsDirective code cleanup.)
Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/87d905f0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/87d905f0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/87d905f0
Branch: refs/heads/3
Commit: 87d905f0c664ac702b72707a5e80a02da9d6457e
Parents: 999afd2
Author: ddekany <dd...@apache.org>
Authored: Mon Aug 21 01:07:10 2017 +0200
Committer: ddekany <dd...@apache.org>
Committed: Mon Aug 21 01:07:10 2017 +0200
----------------------------------------------------------------------
.../test/templateutil/AssertFailsDirective.java | 106 ++++++++++---------
1 file changed, 55 insertions(+), 51 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/87d905f0/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 9e82895..855eb55 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
@@ -67,70 +67,74 @@ public class AssertFailsDirective implements TemplateDirectiveModel {
String exception = CallableUtils.getOptionalStringArgument(args, EXCEPTION_ARG_IDX, this);
int causeNestingLevel = CallableUtils.getOptionalIntArgument(
args, CAUSE_NESTING_LEVEL_ARG_IDX, 0, this);
- if (callPlace.hasNestedContent()) {
- boolean blockFailed;
- try {
- callPlace.executeNestedContent(null, _NullWriter.INSTANCE, env);
- blockFailed = false;
- } catch (Throwable e) {
- blockFailed = true;
-
- int causeNestingLevelCountDown = causeNestingLevel;
- while (causeNestingLevelCountDown != 0) {
- e = e.getCause();
- if (e == null) {
+
+ if (!callPlace.hasNestedContent()) {
+ throw CallableUtils.newGenericExecuteException(
+ "It doesn't make sense to call this directive without nested content.", this);
+ }
+
+ boolean blockFailed;
+ try {
+ callPlace.executeNestedContent(null, _NullWriter.INSTANCE, env);
+ blockFailed = false;
+ } catch (Throwable e) {
+ blockFailed = true;
+
+ int causeNestingLevelCountDown = causeNestingLevel;
+ while (causeNestingLevelCountDown != 0) {
+ e = e.getCause();
+ if (e == null) {
+ throw new AssertationFailedInTemplateException(
+ "Failure is not like expected: The cause exception nesting dept was lower than "
+ + causeNestingLevel + ".",
+ env);
+ }
+ causeNestingLevelCountDown--;
+ }
+
+ if (message != null || messageRegexp != null) {
+ if (e.getMessage() == null) {
+ throw new AssertationFailedInTemplateException(
+ "Failure is not like expected. The exception message was null, "
+ + "and thus it doesn't contain:\n" + _StringUtils.jQuote(message) + ".",
+ env);
+ }
+ if (message != null) {
+ 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 cause exception nesting dept was lower than "
- + causeNestingLevel + ".",
+ "Failure is not like expected. The exception message:\n" + _StringUtils
+ .jQuote(actualMessage)
+ + "\ndoesn't contain:\n" + _StringUtils.jQuote(message) + ".",
env);
}
- causeNestingLevelCountDown--;
}
-
- if (message != null || messageRegexp != null) {
- if (e.getMessage() == null) {
+ if (messageRegexp != null) {
+ if (!messageRegexp.matcher(e.getMessage()).find()) {
throw new AssertationFailedInTemplateException(
- "Failure is not like expected. The exception message was null, "
- + "and thus it doesn't contain:\n" + _StringUtils.jQuote(message) + ".",
+ "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 (message != null) {
- 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)
- + "\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())
- + ".",
- 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())
- + " doesn't contain " + _StringUtils.jQuote(message) + ".",
- env);
}
}
- if (!blockFailed) {
+ if (exception != null && !e.getClass().getName().contains(exception)) {
throw new AssertationFailedInTemplateException(
- "Block was expected to fail, but it didn't.",
+ "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);
+ }
}
@Override