You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2013/05/13 17:18:00 UTC
[1/2] git commit: WICKET-5176 StringResourceModel doesn't detach
model in some cases
Updated Branches:
refs/heads/master 6efe7a848 -> 7a0bb33e5
WICKET-5176 StringResourceModel doesn't detach model in some cases
Make sure that StringResourceModel detaches its wrapped model, parameters and defaultValue even when the LoadableDetachableModel is not attached.
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/34634266
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/34634266
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/34634266
Branch: refs/heads/master
Commit: 3463426699bdfea77fbbe8f384eb62bfb390d60e
Parents: 6efe7a8
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Mon May 13 18:14:43 2013 +0300
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Mon May 13 18:14:43 2013 +0300
----------------------------------------------------------------------
.../apache/wicket/model/StringResourceModel.java | 7 +--
.../wicket/model/StringResourceModelTest.java | 37 ++++++++++++++-
2 files changed, 38 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/wicket/blob/34634266/wicket-core/src/main/java/org/apache/wicket/model/StringResourceModel.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/model/StringResourceModel.java b/wicket-core/src/main/java/org/apache/wicket/model/StringResourceModel.java
index 95b37f8..35ef7bb 100644
--- a/wicket-core/src/main/java/org/apache/wicket/model/StringResourceModel.java
+++ b/wicket-core/src/main/java/org/apache/wicket/model/StringResourceModel.java
@@ -590,13 +590,10 @@ public class StringResourceModel extends LoadableDetachableModel<String>
return getString();
}
- /**
- * @see org.apache.wicket.model.IDetachable#detach()
- */
@Override
- protected final void onDetach()
+ public final void detach()
{
- super.onDetach();
+ super.detach();
// detach any model
if (model != null)
http://git-wip-us.apache.org/repos/asf/wicket/blob/34634266/wicket-core/src/test/java/org/apache/wicket/model/StringResourceModelTest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/model/StringResourceModelTest.java b/wicket-core/src/test/java/org/apache/wicket/model/StringResourceModelTest.java
index b69fee2..c2f22e8 100644
--- a/wicket-core/src/test/java/org/apache/wicket/model/StringResourceModelTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/model/StringResourceModelTest.java
@@ -21,7 +21,7 @@ import java.text.MessageFormat;
import java.util.Calendar;
import java.util.Locale;
-import junit.framework.Assert;
+import org.junit.Assert;
import org.apache.wicket.Component;
import org.apache.wicket.Session;
@@ -262,6 +262,41 @@ public class StringResourceModelTest extends WicketTestCase
}
/**
+ * https://issues.apache.org/jira/browse/WICKET-5176
+ */
+ @Test
+ public void detachEvenNotAttached() {
+ Wicket5176Model wrappedModel = new Wicket5176Model();
+ StringResourceModel stringResourceModel = new StringResourceModel("test", (Component) null, wrappedModel);
+ assertFalse(stringResourceModel.isAttached());
+ assertTrue(wrappedModel.isAttached());
+ stringResourceModel.detach();
+ assertFalse(wrappedModel.isAttached());
+ }
+
+ private static class Wicket5176Model implements IModel {
+ private boolean attached = true;
+
+ @Override
+ public Object getObject() {
+ return null;
+ }
+
+ @Override
+ public void setObject(Object object) {
+ }
+
+ @Override
+ public void detach() {
+ attached = false;
+ }
+
+ private boolean isAttached() {
+ return attached;
+ }
+ }
+
+ /**
* Inner class used for testing.
*/
public static class WeatherStation implements Serializable
[2/2] git commit: Remove the import of org.junit.Assert. It is
inherited from WicketTestCase
Posted by mg...@apache.org.
Remove the import of org.junit.Assert. It is inherited from WicketTestCase
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/7a0bb33e
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/7a0bb33e
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/7a0bb33e
Branch: refs/heads/master
Commit: 7a0bb33e55c2cfd93b0369d5e48c2ef0dec6cad8
Parents: 3463426
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Mon May 13 18:17:08 2013 +0300
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Mon May 13 18:17:08 2013 +0300
----------------------------------------------------------------------
.../wicket/model/StringResourceModelTest.java | 34 +++++++--------
1 files changed, 16 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/wicket/blob/7a0bb33e/wicket-core/src/test/java/org/apache/wicket/model/StringResourceModelTest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/model/StringResourceModelTest.java b/wicket-core/src/test/java/org/apache/wicket/model/StringResourceModelTest.java
index c2f22e8..e4fda1f 100644
--- a/wicket-core/src/test/java/org/apache/wicket/model/StringResourceModelTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/model/StringResourceModelTest.java
@@ -21,8 +21,6 @@ import java.text.MessageFormat;
import java.util.Calendar;
import java.util.Locale;
-import org.junit.Assert;
-
import org.apache.wicket.Component;
import org.apache.wicket.Session;
import org.apache.wicket.WicketTestCase;
@@ -61,8 +59,8 @@ public class StringResourceModelTest extends WicketTestCase
public void getSimpleResource()
{
StringResourceModel model = new StringResourceModel("simple.text", page, null);
- Assert.assertEquals("Text should be as expected", "Simple text", model.getString());
- Assert.assertEquals("Text should be as expected", "Simple text", model.getObject());
+ assertEquals("Text should be as expected", "Simple text", model.getString());
+ assertEquals("Text should be as expected", "Simple text", model.getObject());
}
/** */
@@ -72,13 +70,13 @@ public class StringResourceModelTest extends WicketTestCase
Label label1 = new Label("resourceModelWithComponent", new StringResourceModel(
"wrappedOnAssignment.text", page, null));
page.add(label1);
- Assert.assertEquals("Text should be as expected", "Non-wrapped text",
+ assertEquals("Text should be as expected", "Non-wrapped text",
label1.getDefaultModelObject());
Label label2 = new Label("resourceModelWithoutComponent", new StringResourceModel(
"wrappedOnAssignment.text", (Component)null, null));
page.add(label2);
- Assert.assertEquals("Text should be as expected", "Wrapped text",
+ assertEquals("Text should be as expected", "Wrapped text",
label2.getDefaultModelObject());
}
@@ -95,10 +93,10 @@ public class StringResourceModelTest extends WicketTestCase
{
StringResourceModel model = new StringResourceModel("weather.${currentStatus}", page,
wsModel);
- Assert.assertEquals("Text should be as expected", "It's sunny, wear sunscreen",
+ assertEquals("Text should be as expected", "It's sunny, wear sunscreen",
model.getString());
ws.setCurrentStatus("raining");
- Assert.assertEquals("Text should be as expected", "It's raining, take an umbrella",
+ assertEquals("Text should be as expected", "It's raining, take an umbrella",
model.getString());
}
@@ -111,7 +109,7 @@ public class StringResourceModelTest extends WicketTestCase
StringResourceModel model = new StringResourceModel("weather.${currentTemperature}", page,
wsModel);
- Assert.assertEquals("Text should be as expected", "Twenty-five dot seven",
+ assertEquals("Text should be as expected", "Twenty-five dot seven",
model.getString());
}
@@ -121,12 +119,12 @@ public class StringResourceModelTest extends WicketTestCase
{
tester.getSession().setLocale(Locale.ENGLISH);
StringResourceModel model = new StringResourceModel("weather.message", page, wsModel);
- Assert.assertEquals(
+ assertEquals(
"Text should be as expected",
"Weather station \"Europe's main weather station\" reports that the temperature is 25.7 \u00B0C",
model.getString());
ws.setCurrentTemperature(11.5);
- Assert.assertEquals(
+ assertEquals(
"Text should be as expected",
"Weather station \"Europe's main weather station\" reports that the temperature is 11.5 \u00B0C",
model.getString());
@@ -145,11 +143,11 @@ public class StringResourceModelTest extends WicketTestCase
ws.setCurrentTemperature(25.7);
String expected = format.format(new Object[] { 25.7, "\u00B0C" });
- Assert.assertEquals("Text should be as expected", expected, model.getString());
+ assertEquals("Text should be as expected", expected, model.getString());
ws.setCurrentTemperature(11.5);
expected = format.format(new Object[] { 11.5, "\u00B0C" });
- Assert.assertEquals("Text should be as expected", expected, model.getString());
+ assertEquals("Text should be as expected", expected, model.getString());
}
/** */
@@ -165,11 +163,11 @@ public class StringResourceModelTest extends WicketTestCase
cal.getTime(), "${currentStatus}", new PropertyModel<Double>(wsModel,
"currentTemperature"), new PropertyModel<String>(wsModel, "units"));
String expected = format.format(new Object[] { cal.getTime(), "sunny", 25.7, "\u00B0C" });
- Assert.assertEquals("Text should be as expected", expected, model.getString());
+ assertEquals("Text should be as expected", expected, model.getString());
ws.setCurrentStatus("raining");
ws.setCurrentTemperature(11.568);
expected = format.format(new Object[] { cal.getTime(), "raining", 11.568, "\u00B0C" });
- Assert.assertEquals("Text should be as expected", expected, model.getString());
+ assertEquals("Text should be as expected", expected, model.getString());
}
/** */
@@ -223,7 +221,7 @@ public class StringResourceModelTest extends WicketTestCase
StringResourceModel model = new StringResourceModel("simple.text", page, wsDetachModel);
model.getObject();
- Assert.assertNotNull(model.getLocalizer());
+ assertNotNull(model.getLocalizer());
model.detach();
}
@@ -250,7 +248,7 @@ public class StringResourceModelTest extends WicketTestCase
page.add(label1);
label1.getDefaultModelObject();
label1.detach();
- Assert.assertNull(nullOnDetachModel.getObject());
+ assertNull(nullOnDetachModel.getObject());
nullOnDetachModel.setObject(ws);
Label label2 = new Label("resourceModelWithoutComponent", new StringResourceModel(
@@ -258,7 +256,7 @@ public class StringResourceModelTest extends WicketTestCase
page.add(label2);
label2.getDefaultModelObject();
label2.detach();
- Assert.assertNull(nullOnDetachModel.getObject());
+ assertNull(nullOnDetachModel.getObject());
}
/**