struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lukaszlen...@apache.org
Subject [12/17] struts git commit: Uses container to inject required dependencies
Date Mon, 13 Mar 2017 17:46:21 GMT
Uses container to inject required dependencies


Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/55ea82cd
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/55ea82cd
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/55ea82cd

Branch: refs/heads/master
Commit: 55ea82cd4faaecf1f3ca1fffd4428db2471b952d
Parents: f56c59c
Author: Lukasz Lenart <lukaszlenart@apache.org>
Authored: Fri Mar 10 09:40:20 2017 +0100
Committer: Lukasz Lenart <lukaszlenart@apache.org>
Committed: Fri Mar 10 09:40:20 2017 +0100

----------------------------------------------------------------------
 .../opensymphony/xwork2/ActionSupportTest.java  |  6 ++--
 .../validator/ActionValidatorManagerTest.java   | 34 +++++++++++---------
 .../apache/struts2/views/jsp/TextTagTest.java   |  4 +--
 .../struts2/views/jsp/ui/TooltipTest.java       |  9 +++---
 4 files changed, 27 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/55ea82cd/core/src/test/java/com/opensymphony/xwork2/ActionSupportTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/com/opensymphony/xwork2/ActionSupportTest.java b/core/src/test/java/com/opensymphony/xwork2/ActionSupportTest.java
index bd47c1c..d5422a1 100644
--- a/core/src/test/java/com/opensymphony/xwork2/ActionSupportTest.java
+++ b/core/src/test/java/com/opensymphony/xwork2/ActionSupportTest.java
@@ -252,7 +252,7 @@ public class ActionSupportTest extends XWorkTestCase {
 
     public void testGetTextsWithListAndStack() throws Exception {
         ActionContext.getContext().setLocale(new Locale("da"));
-        MyActionSupport mas = new MyActionSupport();
+        MyActionSupport mas = container.inject(MyActionSupport.class);
 
         ValueStack stack = ActionContext.getContext().getValueStack();
 
@@ -270,7 +270,7 @@ public class ActionSupportTest extends XWorkTestCase {
 
     public void testGetTextsWithArrayAndStack() throws Exception {
         ActionContext.getContext().setLocale(new Locale("da"));
-        MyActionSupport mas = new MyActionSupport();
+        MyActionSupport mas = container.inject(MyActionSupport.class);
 
         ValueStack stack = ActionContext.getContext().getValueStack();
 
@@ -313,7 +313,7 @@ public class ActionSupportTest extends XWorkTestCase {
         assertEquals("4567def", formatted);
     }
 
-    private class MyActionSupport extends ActionSupport {
+    public static class MyActionSupport extends ActionSupport {
 
         private Double val;
 

http://git-wip-us.apache.org/repos/asf/struts/blob/55ea82cd/core/src/test/java/com/opensymphony/xwork2/validator/ActionValidatorManagerTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/com/opensymphony/xwork2/validator/ActionValidatorManagerTest.java
b/core/src/test/java/com/opensymphony/xwork2/validator/ActionValidatorManagerTest.java
index 6d7eeeb..872711a 100644
--- a/core/src/test/java/com/opensymphony/xwork2/validator/ActionValidatorManagerTest.java
+++ b/core/src/test/java/com/opensymphony/xwork2/validator/ActionValidatorManagerTest.java
@@ -26,47 +26,47 @@ public class ActionValidatorManagerTest extends XWorkTestCase {
         /* MockAction.class */
         // reference number
         ValueStack stack = container.getInstance(ValueStackFactory.class).createValueStack();
-        final RequiredStringValidator referenceNumberRequiredStringValidator = new RequiredStringValidator();
+        final RequiredStringValidator referenceNumberRequiredStringValidator = container.inject(RequiredStringValidator.class);
         referenceNumberRequiredStringValidator.setFieldName("referenceNumber");
         referenceNumberRequiredStringValidator.setDefaultMessage("Reference number is required");
         referenceNumberRequiredStringValidator.setValueStack(stack);
 
         // order
-        final RequiredFieldValidator orderRequiredValidator = new RequiredFieldValidator();
+        final RequiredFieldValidator orderRequiredValidator = container.inject(RequiredFieldValidator.class);
         orderRequiredValidator.setFieldName("order");
         orderRequiredValidator.setDefaultMessage("Order is required");
         orderRequiredValidator.setValueStack(stack);
 
         // customer
-        final RequiredFieldValidator customerRequiredValidator = new RequiredFieldValidator();
+        final RequiredFieldValidator customerRequiredValidator = container.inject(RequiredFieldValidator.class);
         customerRequiredValidator.setFieldName("customer");
         customerRequiredValidator.setDefaultMessage("Customer is required");
         customerRequiredValidator.setValueStack(stack);
-        final VisitorFieldValidator customerVisitorValidator = new VisitorFieldValidator();
+        final VisitorFieldValidator customerVisitorValidator = container.inject(VisitorFieldValidator.class);
         customerVisitorValidator.setAppendPrefix(true);
         customerVisitorValidator.setFieldName("customer");
         customerVisitorValidator.setValueStack(stack);
 
         /* Customer.class */
         // customer -> name
-        final RequiredStringValidator customerNameRequiredStringValidator = new RequiredStringValidator();
+        final RequiredStringValidator customerNameRequiredStringValidator = container.inject(RequiredStringValidator.class);
         customerNameRequiredStringValidator.setFieldName("name");
         customerNameRequiredStringValidator.setDefaultMessage("Name is required");
         customerNameRequiredStringValidator.setValueStack(stack);
 
         // customer -> age
-        final RequiredFieldValidator customerAgeRequiredValidator = new RequiredFieldValidator();
+        final RequiredFieldValidator customerAgeRequiredValidator = container.inject(RequiredFieldValidator.class);
         customerAgeRequiredValidator.setFieldName("age");
         customerAgeRequiredValidator.setDefaultMessage("Age is required");
         customerAgeRequiredValidator.setValueStack(stack);
 
         // customer -> Address
-        final RequiredFieldValidator customerAddressRequiredFieldValidator = new RequiredFieldValidator();
+        final RequiredFieldValidator customerAddressRequiredFieldValidator = container.inject(RequiredFieldValidator.class);
         customerAddressRequiredFieldValidator.setFieldName("address");
         customerAddressRequiredFieldValidator.setDefaultMessage("Address is required");
         customerAddressRequiredFieldValidator.setValueStack(stack);
 
-        final VisitorFieldValidator customerAddressVisitorFieldValidator = new VisitorFieldValidator();
+        final VisitorFieldValidator customerAddressVisitorFieldValidator = container.inject(VisitorFieldValidator.class);
         customerAddressVisitorFieldValidator.setFieldName("address");
         customerAddressVisitorFieldValidator.setAppendPrefix(true);
         //customerAddressVisitorFieldValidator.setDefaultMessage("");
@@ -76,26 +76,26 @@ public class ActionValidatorManagerTest extends XWorkTestCase {
 
         /* Address.class */
         // customer -> Address -> street
-        final RequiredStringValidator customerAddressStreetRequiredFieldValidator = new RequiredStringValidator();
+        final RequiredStringValidator customerAddressStreetRequiredFieldValidator = container.inject(RequiredStringValidator.class);
         customerAddressStreetRequiredFieldValidator.setFieldName("street");
         customerAddressStreetRequiredFieldValidator.setDefaultMessage("Street is required");
         customerAddressStreetRequiredFieldValidator.setShortCircuit(true);
         customerAddressStreetRequiredFieldValidator.setValueStack(stack);
 
-        final RequiredStringValidator customerAddressStreetRequiredFieldValidator2 = new
RequiredStringValidator();
+        final RequiredStringValidator customerAddressStreetRequiredFieldValidator2 = container.inject(RequiredStringValidator.class);
         customerAddressStreetRequiredFieldValidator2.setFieldName("street");
         customerAddressStreetRequiredFieldValidator2.setDefaultMessage("Street is required
2");
         customerAddressStreetRequiredFieldValidator2.setShortCircuit(true);
         customerAddressStreetRequiredFieldValidator2.setValueStack(stack);
 
         // customer -> Address -> pobox
-        final RequiredStringValidator customerAddressPoboxRequiredFieldValidator = new RequiredStringValidator();
+        final RequiredStringValidator customerAddressPoboxRequiredFieldValidator = container.inject(RequiredStringValidator.class);
         customerAddressPoboxRequiredFieldValidator.setFieldName("pobox");
         customerAddressPoboxRequiredFieldValidator.setDefaultMessage("PO Box is required");
         customerAddressPoboxRequiredFieldValidator.setShortCircuit(false);
         customerAddressPoboxRequiredFieldValidator.setValueStack(stack);
 
-        final RequiredStringValidator customerAddressPoboxRequiredFieldValidator2 = new RequiredStringValidator();
+        final RequiredStringValidator customerAddressPoboxRequiredFieldValidator2 = container.inject(RequiredStringValidator.class);
         customerAddressPoboxRequiredFieldValidator2.setFieldName("pobox");
         customerAddressPoboxRequiredFieldValidator2.setDefaultMessage("PO Box is required
2");
         customerAddressPoboxRequiredFieldValidator2.setShortCircuit(false);
@@ -146,10 +146,12 @@ public class ActionValidatorManagerTest extends XWorkTestCase {
                 return Collections.emptyList();
             }
         };
+        container.inject(validatorManager);
+
         customerVisitorValidator.setActionValidatorManager(validatorManager);
         customerAddressVisitorFieldValidator.setActionValidatorManager(validatorManager);
 
-        MockAction action = new MockAction();
+        MockAction action = container.inject(MockAction.class);
         stack.push(action);
         validatorManager.validate(action, "ctx");
 
@@ -170,7 +172,7 @@ public class ActionValidatorManagerTest extends XWorkTestCase {
         assertEquals((action.getFieldErrors().get("customer.address.pobox")).size(), 2);
     }
 
-    private class MockAction extends ActionSupport {
+    public static class MockAction extends ActionSupport {
 
         private String referenceNumber;
         private Integer order;
@@ -188,7 +190,7 @@ public class ActionValidatorManagerTest extends XWorkTestCase {
     }
 
 
-    private class Customer {
+    public static class Customer {
         private String name;
         private Integer age;
         private Address address = new Address();
@@ -203,7 +205,7 @@ public class ActionValidatorManagerTest extends XWorkTestCase {
         public void setAddress(Address address) { this.address = address; }
     }
 
-    private class Address {
+    public static class Address {
         private String street;
         private String pobox;
 

http://git-wip-us.apache.org/repos/asf/struts/blob/55ea82cd/core/src/test/java/org/apache/struts2/views/jsp/TextTagTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/struts2/views/jsp/TextTagTest.java b/core/src/test/java/org/apache/struts2/views/jsp/TextTagTest.java
index 661acd3..dc4c9f6 100644
--- a/core/src/test/java/org/apache/struts2/views/jsp/TextTagTest.java
+++ b/core/src/test/java/org/apache/struts2/views/jsp/TextTagTest.java
@@ -178,7 +178,7 @@ public class TextTagTest extends AbstractTagTest {
         ValueStack newStack = container.getInstance(ValueStackFactory.class).createValueStack();
         newStack.getContext().put(ActionContext.LOCALE, foreignLocale);
         newStack.getContext().put(ActionContext.CONTAINER, container);
-        newStack.push(new TestAction1());
+        newStack.push(container.inject(TestAction1.class));
         request.setAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY, newStack);
         assertNotSame(ActionContext.getContext().getValueStack().peek(), newStack.peek());
 
@@ -189,7 +189,7 @@ public class TextTagTest extends AbstractTagTest {
 
     public void testTextTagUsesLocaleFromValueStack() throws JspException {
         stack.pop();
-        stack.push(new TestAction1());
+        stack.push(container.inject(TestAction1.class));
 
         Locale defaultLocale = getDefaultLocale();
         Locale foreignLocale = getForeignLocale();

http://git-wip-us.apache.org/repos/asf/struts/blob/55ea82cd/core/src/test/java/org/apache/struts2/views/jsp/ui/TooltipTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/struts2/views/jsp/ui/TooltipTest.java b/core/src/test/java/org/apache/struts2/views/jsp/ui/TooltipTest.java
index 971ecce..e11c7c3 100644
--- a/core/src/test/java/org/apache/struts2/views/jsp/ui/TooltipTest.java
+++ b/core/src/test/java/org/apache/struts2/views/jsp/ui/TooltipTest.java
@@ -370,15 +370,14 @@ public class TooltipTest extends AbstractUITagTest {
         verify(TooltipTest.class.getResource("tooltip-3.txt"));
     }
 
-    /**
-     * @throws Exception 
-     * 
-     */
     public void setUp() throws Exception {
         super.setUp();
-        initDispatcher(new HashMap<String,String>(){{ 
+
+        initDispatcher(new HashMap<String,String>(){{
             put("configProviders", TestConfigurationProvider.class.getName());
         }});
         createMocks();
+
+
     }
 }


Mime
View raw message