From 846d76351506fa7251366d1a9e9718e2395fd5b6 Mon Sep 17 00:00:00 2001 From: Constantin Date: Thu, 1 Feb 2024 20:06:26 +0200 Subject: [PATCH] BAEL-7263: Highlight scenarios where defined variable is evaluated as false --- .../webapp/WEB-INF/views/checkVariableIsDefined.html | 5 +++++ .../controller/HomeControllerIntegrationTest.java | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/spring-web-modules/spring-thymeleaf-5/src/main/webapp/WEB-INF/views/checkVariableIsDefined.html b/spring-web-modules/spring-thymeleaf-5/src/main/webapp/WEB-INF/views/checkVariableIsDefined.html index 47992899f8..7d995718f6 100644 --- a/spring-web-modules/spring-thymeleaf-5/src/main/webapp/WEB-INF/views/checkVariableIsDefined.html +++ b/spring-web-modules/spring-thymeleaf-5/src/main/webapp/WEB-INF/views/checkVariableIsDefined.html @@ -10,5 +10,10 @@
+
+
+
+
+ diff --git a/spring-web-modules/spring-thymeleaf-5/src/test/java/com/baeldung/thymeleaf/controller/HomeControllerIntegrationTest.java b/spring-web-modules/spring-thymeleaf-5/src/test/java/com/baeldung/thymeleaf/controller/HomeControllerIntegrationTest.java index d4e3c4aa28..9ebc80c658 100644 --- a/spring-web-modules/spring-thymeleaf-5/src/test/java/com/baeldung/thymeleaf/controller/HomeControllerIntegrationTest.java +++ b/spring-web-modules/spring-thymeleaf-5/src/test/java/com/baeldung/thymeleaf/controller/HomeControllerIntegrationTest.java @@ -74,6 +74,17 @@ public class HomeControllerIntegrationTest { .andExpect(content().string(not(containsString(IF_CONDITIONAL_MSG)))); } + @Test + public void whenVariableIsDefinedAndNotTrue_thenIfConditionalIsFalse() throws Exception { + mockMvc.perform(MockMvcRequestBuilders.get("/variable-defined")) + .andExpect(status().isOk()) + .andExpect(view().name("checkVariableIsDefined.html")) + .andExpect(content().string(not(containsString("Evaluating \"false\"")))) + .andExpect(content().string(not(containsString("Evaluating \"no\"")))) + .andExpect(content().string(not(containsString("Evaluating \"off\"")))) + .andExpect(content().string(not(containsString("Evaluating 0")))); + } + @Test public void whenVariableIsDefined_thenUnlessConditionalIsTrue() throws Exception { mockMvc.perform(MockMvcRequestBuilders.get("/variable-defined"))