This is an automated email from the ASF dual-hosted git repository.

svenmeier pushed a commit to branch wicket-8.x
in repository https://gitbox.apache.org/repos/asf/wicket.git


The following commit(s) were added to refs/heads/wicket-8.x by this push:
     new cf99783  WICKET-6713 start via class or instance
cf99783 is described below

commit cf99783fcf2a01936ea9d51bb34ab9db5fa6d6dc
Author: Sven Meier <svenme...@apache.org>
AuthorDate: Sat Nov 16 08:49:06 2019 +0100

    WICKET-6713 start via class or instance
    
    on same tester
---
 .../wicket/util/tester/BaseWicketTester.java       | 25 +++++++---------------
 .../wicket/util/tester/WicketTesterTest.java       | 18 ++++++++++++++++
 2 files changed, 26 insertions(+), 17 deletions(-)

diff --git 
a/wicket-core/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java 
b/wicket-core/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java
index 08d82d1..fb8cd9f 100644
--- 
a/wicket-core/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java
+++ 
b/wicket-core/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java
@@ -1365,9 +1365,6 @@ public class BaseWicketTester
                {
                        Constructor<C> c = 
componentClass.getConstructor(String.class);
                        comp = c.newInstance(ComponentInPage.ID);
-                       componentInPage = new ComponentInPage();
-                       componentInPage.component = comp;
-                       componentInPage.isInstantiated = true;
                }
                catch (Exception e)
                {
@@ -1377,7 +1374,11 @@ public class BaseWicketTester
                }
 
                // process the component
-               return startComponentInPage(comp, pageMarkup);
+               C started = startComponentInPage(comp, pageMarkup);
+               
+               componentInPage.isInstantiated = true;
+               
+               return started;
        }
 
        /**
@@ -1475,22 +1476,12 @@ public class BaseWicketTester
                // Add the child component
                page.add(component);
 
-               // Preserve 'componentInPage' because #startPage() needs to 
null-fy it
-               ComponentInPage oldComponentInPage = componentInPage;
-
                // Process the page
                startPage(page);
 
-               // Remember the "root" component processes and return it
-               if (oldComponentInPage != null)
-               {
-                       componentInPage = oldComponentInPage;
-               }
-               else
-               {
-                       componentInPage = new ComponentInPage();
-                       componentInPage.component = component;
-               }
+               componentInPage = new ComponentInPage();
+               componentInPage.component = component;
+               
                return component;
        }
 
diff --git 
a/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterTest.java 
b/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterTest.java
index 33ea646..dd76054 100644
--- 
a/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterTest.java
+++ 
b/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterTest.java
@@ -1339,4 +1339,22 @@ public class WicketTesterTest extends WicketTestCase
                tester.assertComponentOnAjaxResponse(testLink);
 
        }
+       
+       /**
+        * WICKET-6713 component can be started via class or instance on same 
tester
+        */
+       @Test
+       public void componentInPage() {
+               tester.startComponentInPage(Label.class);
+               
+               tester.assertVisible("");
+
+               tester.startComponentInPage(new Label("otherLabel"));
+               
+               tester.assertVisible("otherLabel");
+
+               tester.startComponentInPage(Label.class);
+               
+               tester.assertVisible("");
+       }
 }

Reply via email to