WICKET-5677 clean up tests
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/c3eb7e24 Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/c3eb7e24 Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/c3eb7e24 Branch: refs/heads/WICKET-5677 Commit: c3eb7e24954d3909c74201682dba5e4de8fcadd4 Parents: 4703c1a Author: Carl-Eric Menzel <cmen...@apache.org> Authored: Mon Aug 18 14:08:16 2014 +0200 Committer: Carl-Eric Menzel <cmen...@apache.org> Committed: Mon Aug 18 14:08:16 2014 +0200 ---------------------------------------------------------------------- .../java/org/apache/wicket/OnReAddTest.java | 90 +++++++++++++------- 1 file changed, 57 insertions(+), 33 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/c3eb7e24/wicket-core/src/test/java/org/apache/wicket/OnReAddTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/OnReAddTest.java b/wicket-core/src/test/java/org/apache/wicket/OnReAddTest.java index 989b163..fb9535b 100644 --- a/wicket-core/src/test/java/org/apache/wicket/OnReAddTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/OnReAddTest.java @@ -33,94 +33,84 @@ public class OnReAddTest public WicketTesterScope scope = new WicketTesterScope(); private boolean onReAddCalled = false; - - private Component createUninitializedProbe() - { - return new Label("foo") - { - @Override - protected void onReAdd() - { - super.onReAdd(); - onReAddCalled = true; - } - }; - } - - private Component createInitializedProbe() { - Component probe = createUninitializedProbe(); - probe.internalInitialize(); - return probe; - } + private boolean onInitializeCalled = false; @Test - public void onAddIsNotCalledOnFirstAdd() + public void onFirstAddInitializeIsCalled() { Page page = createPage(); page.internalInitialize(); page.add(createUninitializedProbe()); assertFalse(onReAddCalled); - } - - private WebPage createPage() - { - return new WebPage() - { - }; + assertTrue(onInitializeCalled); } @Test - public void onAddIsNotCalledWhenParentIsNotConnectedToPage() + public void nothingIsCalledWithoutConnectionToPage() { MarkupContainer container = createContainer(); container.internalInitialize(); container.add(createUninitializedProbe()); assertFalse(onReAddCalled); + assertFalse(onInitializeCalled); } @Test - public void onAddIsNotCalledOnUninitializedProbeWhenParentIsAddedToPage() + public void uninitializedComponentIsInitializedOnConnectionToPage() { + // "old", initialized container + "new" uninitialized component: + // oninitialize should be called on the component when the container + // is added to the page, not before. MarkupContainer container = createContainer(); container.internalInitialize(); container.add(createUninitializedProbe()); assertFalse(onReAddCalled); + assertFalse(onInitializeCalled); WebPage page = createPage(); page.internalInitialize(); page.add(container); assertFalse(onReAddCalled); + assertTrue(onInitializeCalled); } @Test - public void onAddIsCalledAfterRemoveAndAdd() + public void initializeIsCalledOnFirstAdd_OnReAddIsCalledAfterEachRemoveAndAdd() { Page page = createPage(); page.internalInitialize(); Component probe = createUninitializedProbe(); page.add(probe); assertFalse(onReAddCalled); + assertTrue(onInitializeCalled); + onInitializeCalled = false; page.remove(probe); assertFalse(onReAddCalled); + assertFalse(onInitializeCalled); page.add(probe); assertTrue(onReAddCalled); + assertFalse(onInitializeCalled); } @Test - public void onAddRecursesToChildren() + public void onReAddRecursesToChildrenLikeOnInitialize() { Page page = createPage(); page.internalInitialize(); Component probe = createNestedProbe(); page.add(probe); assertFalse(onReAddCalled); + assertTrue(onInitializeCalled); + onInitializeCalled = false; probe.remove(); + assertFalse(onInitializeCalled); assertFalse(onReAddCalled); page.add(probe); + assertFalse(onInitializeCalled); assertTrue(onReAddCalled); } @Test - public void onAddEnforcesSuperCall() + public void onReAddEnforcesSuperCall() { Page page = createPage(); page.internalInitialize(); @@ -137,12 +127,46 @@ public class OnReAddTest brokenProbe.internalInitialize(); page.add(brokenProbe); fail("should have thrown exception"); - } catch (IllegalStateException e) + } + catch (IllegalStateException e) { assertTrue(e.getMessage().contains("super.onReAdd")); } } + private Component createUninitializedProbe() + { + return new Label("foo") + { + @Override + protected void onReAdd() + { + super.onReAdd(); + onReAddCalled = true; + } + + @Override protected void onInitialize() + { + super.onInitialize(); + onInitializeCalled = true; + } + }; + } + + private Component createInitializedProbe() + { + Component probe = createUninitializedProbe(); + probe.internalInitialize(); + return probe; + } + + private WebPage createPage() + { + return new WebPage() + { + }; + } + private Component createNestedProbe() { return createContainer().add(createUninitializedProbe());