You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by sv...@apache.org on 2016/04/25 09:57:13 UTC

[4/4] wicket git commit: We already have Model.of()

We already have Model.of()


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/4f07ee16
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/4f07ee16
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/4f07ee16

Branch: refs/heads/master
Commit: 4f07ee164627e5d95516e42712b30cb6b72250e3
Parents: 140e530
Author: Sven Meier <sv...@apache.org>
Authored: Mon Apr 25 09:24:05 2016 +0200
Committer: Sven Meier <sv...@apache.org>
Committed: Mon Apr 25 09:38:37 2016 +0200

----------------------------------------------------------------------
 .../java/org/apache/wicket/model/IModel.java    | 15 ---------
 .../org/apache/wicket/model/IModelTest.java     | 34 ++++++++++----------
 2 files changed, 17 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/4f07ee16/wicket-core/src/main/java/org/apache/wicket/model/IModel.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/model/IModel.java b/wicket-core/src/main/java/org/apache/wicket/model/IModel.java
index 68c259c..a4522bd 100644
--- a/wicket-core/src/main/java/org/apache/wicket/model/IModel.java
+++ b/wicket-core/src/main/java/org/apache/wicket/model/IModel.java
@@ -282,19 +282,4 @@ public interface IModel<T> extends IDetachable
 			}
 		};
 	}
-
-	/**
-	 * Returns a IModel lifting the given object into the Model.
-	 *
-	 * @param <T>
-	 *            the type of the given object
-	 * @param object
-	 *            an object to be lifted into a IModel
-	 * @return a new IModel
-	 */
-	static <T> IModel<T> of(T object)
-	{
-		return () -> object;
-	}
-
 }

http://git-wip-us.apache.org/repos/asf/wicket/blob/4f07ee16/wicket-core/src/test/java/org/apache/wicket/model/IModelTest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/model/IModelTest.java b/wicket-core/src/test/java/org/apache/wicket/model/IModelTest.java
index 45dc752..acf10bd 100644
--- a/wicket-core/src/test/java/org/apache/wicket/model/IModelTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/model/IModelTest.java
@@ -51,7 +51,7 @@ public class IModelTest extends Assert
 	@Test
 	public void filterMatch()
 	{
-		IModel<Person> johnModel = IModel.of(person)
+		IModel<Person> johnModel = Model.of(person)
 				.filter((p) -> p.getName().equals(name));
 
 		assertThat(johnModel.getObject(), is(person));
@@ -60,7 +60,7 @@ public class IModelTest extends Assert
 	@Test
 	public void filterNoMatch()
 	{
-		IModel<Person> johnModel = IModel.of(person)
+		IModel<Person> johnModel = Model.of(person)
 				.filter((p) -> p.getName().equals("Jane"));
 
 		assertThat(johnModel.getObject(), is(nullValue()));
@@ -69,48 +69,48 @@ public class IModelTest extends Assert
 	@Test(expected = IllegalArgumentException.class)
 	public void nullFilter()
 	{
-		IModel.of(person).filter(null);
+		Model.of(person).filter(null);
 	}
 
 	@Test
 	public void map()
 	{
-		IModel<String> personNameModel = IModel.of(person).map(Person::getName);
+		IModel<String> personNameModel = Model.of(person).map(Person::getName);
 		assertThat(personNameModel.getObject(), is(equalTo(name)));
 	}
 
 	@Test
 	public void map2()
 	{
-		IModel<String> streetModel = IModel.of(person).map(Person::getAddress).map(Address::getStreet);
+		IModel<String> streetModel = Model.of(person).map(Person::getAddress).map(Address::getStreet);
 		assertThat(streetModel.getObject(), is(equalTo(street)));
 	}
 
 	@Test(expected = IllegalArgumentException.class)
 	public void nullMapper()
 	{
-		IModel.of(person).map(null);
+		Model.of(person).map(null);
 	}
 
 	@Test
 	public void withMap()
 	{
-		IModel<String> janeModel = IModel.of("Jane");
+		IModel<String> janeModel = Model.of("Jane");
 		WicketBiFunction<Person, String, String> function =
 				(WicketBiFunction<Person, String, String>) (person1, other) ->
 						person1.getName() + " is in relationship with " + other;
-		IModel<String> relationShipModel = IModel.of(person).mapWith(function, janeModel);
+		IModel<String> relationShipModel = Model.of(person).mapWith(function, janeModel);
 		assertThat(relationShipModel.getObject(), is(equalTo("John is in relationship with Jane")));
 	}
 
 	@Test
 	public void withMapWithNullObject()
 	{
-		IModel<String> janeModel = IModel.of(null);
+		IModel<String> janeModel = Model.of((String)null);
 		WicketBiFunction<Person, String, String> function =
 				(WicketBiFunction<Person, String, String>) (person1, other) ->
 						person1.getName() + " is in relationship with " + other;
-		IModel<String> relationShipModel = IModel.of(person).mapWith(function, janeModel);
+		IModel<String> relationShipModel = Model.of(person).mapWith(function, janeModel);
 		assertThat(relationShipModel.getObject(), is(nullValue()));
 	}
 
@@ -121,19 +121,19 @@ public class IModelTest extends Assert
 		WicketBiFunction<Person, String, String> function =
 				(WicketBiFunction<Person, String, String>) (person1, other) ->
 						person1.getName() + " is in relationship with " + other;
-		IModel.of(person).mapWith(function, janeModel);
+		Model.of(person).mapWith(function, janeModel);
 	}
 
 	@Test(expected = IllegalArgumentException.class)
 	public void withMapWithNullCombiner()
 	{
-		IModel.of(person).mapWith(null, Model.of("Jane"));
+		Model.of(person).mapWith(null, Model.of("Jane"));
 	}
 
 	@Test
 	public void flatMap()
 	{
-		IModel<String> heirModel = IModel.of(person)
+		IModel<String> heirModel = Model.of(person)
 			.flatMap(john ->
 					LambdaModel.of(
 						() -> john.getName() + " is my parent",
@@ -150,7 +150,7 @@ public class IModelTest extends Assert
 	@Test(expected = IllegalArgumentException.class)
 	public void nullFlatMapper()
 	{
-		IModel.of(person).flatMap(null);
+		Model.of(person).flatMap(null);
 	}
 
 	@Test
@@ -158,7 +158,7 @@ public class IModelTest extends Assert
 	{
 		person.setName(null);
 		String defaultName = "Default name";
-		IModel<String> defaultNameModel = IModel.of(person).map(Person::getName).orElse(defaultName);
+		IModel<String> defaultNameModel = Model.of(person).map(Person::getName).orElse(defaultName);
 
 		assertThat(defaultNameModel.getObject(), is(equalTo(defaultName)));
 	}
@@ -168,7 +168,7 @@ public class IModelTest extends Assert
 	{
 		person.setName(null);
 		String defaultName = "Default name";
-		IModel<String> defaultNameModel = IModel.of(person).map(Person::getName).orElseGet(() -> defaultName);
+		IModel<String> defaultNameModel = Model.of(person).map(Person::getName).orElseGet(() -> defaultName);
 
 		assertThat(defaultNameModel.getObject(), is(equalTo(defaultName)));
 	}
@@ -176,6 +176,6 @@ public class IModelTest extends Assert
 	@Test(expected = IllegalArgumentException.class)
 	public void orElseGetNullOther()
 	{
-		IModel.of(person).map(Person::getName).orElseGet(null);
+		Model.of(person).map(Person::getName).orElseGet(null);
 	}
 }