Repository: wicket
Updated Branches:
  refs/heads/master 62e6be756 -> 9ce6d42f7


WICKET-5991 Introduce models which use Java 8 supplier/consumer

Remove SupplierModel.
IModel is a @FunctionalInterface now and covers the use cases


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

Branch: refs/heads/master
Commit: 9ce6d42f71d48c77843a13435c6534fe3f2f748d
Parents: 62e6be7
Author: Martin Tzvetanov Grigorov <[email protected]>
Authored: Mon Mar 14 12:38:47 2016 +0100
Committer: Martin Tzvetanov Grigorov <[email protected]>
Committed: Mon Mar 14 12:38:47 2016 +0100

----------------------------------------------------------------------
 .../wicket/model/lambda/SupplierModel.java      | 86 ------------------
 .../wicket/model/lambda/SupplierModelTest.java  | 92 --------------------
 2 files changed, 178 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/9ce6d42f/wicket-core/src/main/java/org/apache/wicket/model/lambda/SupplierModel.java
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/main/java/org/apache/wicket/model/lambda/SupplierModel.java 
b/wicket-core/src/main/java/org/apache/wicket/model/lambda/SupplierModel.java
deleted file mode 100644
index 68866d8..0000000
--- 
a/wicket-core/src/main/java/org/apache/wicket/model/lambda/SupplierModel.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.wicket.model.lambda;
-
-import java.util.Objects;
-
-import org.apache.wicket.model.IModel;
-import org.apache.wicket.util.lang.Args;
-
-/**
- * A model that gets its value from a {@link java.util.function.Supplier}.
- *
- * @param <T>
- *            - type of the model object
- */
-public class SupplierModel<T> implements IModel<T>
-{
-       /**
-        * Supplies the model object.
-        */
-       private final WicketSupplier<T> getter;
-
-       /**
-        * Constructor.
-        *
-        * @param getter
-        *              The getter of the model object
-        */
-       public SupplierModel(WicketSupplier<T> getter)
-       {
-               this.getter = Args.notNull(getter, "getter");
-       }
-
-
-       @Override
-       public T getObject()
-       {
-               return getter.get();
-       }
-
-       @Override
-       public final void setObject(T object)
-       {
-               IModel.super.setObject(object);
-       }
-
-       @Override
-       public int hashCode()
-       {
-               return org.apache.wicket.util.lang.Objects.hashCode(getter);
-       }
-
-       @Override
-       public boolean equals(Object obj)
-       {
-               if (obj == null)
-               {
-                       return false;
-               }
-               if (getClass() != obj.getClass())
-               {
-                       return false;
-               }
-               final SupplierModel<?> other = (SupplierModel<?>) obj;
-               if (!Objects.equals(this.getter, other.getter))
-               {
-                       return false;
-               }
-               return true;
-       }
-
-}

http://git-wip-us.apache.org/repos/asf/wicket/blob/9ce6d42f/wicket-core/src/test/java/org/apache/wicket/model/lambda/SupplierModelTest.java
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/test/java/org/apache/wicket/model/lambda/SupplierModelTest.java
 
b/wicket-core/src/test/java/org/apache/wicket/model/lambda/SupplierModelTest.java
deleted file mode 100644
index 384dd89..0000000
--- 
a/wicket-core/src/test/java/org/apache/wicket/model/lambda/SupplierModelTest.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.wicket.model.lambda;
-
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import org.apache.wicket.core.util.lang.WicketObjects;
-import org.apache.wicket.model.IModel;
-import org.junit.Test;
-
-/**
- * Tests for {@link SupplierModel}
- */
-public class SupplierModelTest
-{
-       @Test
-       public void nocaching()
-       {
-               // given
-               Person person = mock(Person.class);
-               when(person.getName()).thenReturn("The person's name");
-               IModel<String> personNameModel = new 
SupplierModel<>(person::getName);
-
-               // when
-
-               // once
-               personNameModel.getObject();
-               personNameModel.getObject();
-
-               personNameModel.detach();
-               // twice
-               personNameModel.getObject();
-               personNameModel.getObject();
-               personNameModel.getObject();
-
-               // then
-               verify(person, times(5)).getName();
-       }
-
-       @Test
-       public void serialize()
-       {
-               Person person = new Person();
-               final String personName = "The person's name";
-               person.setName(personName);
-               final WicketSupplier<String> getName = person::getName;
-               IModel<String> personNameModel = new SupplierModel<>(getName);
-
-               final IModel<String> clone = 
WicketObjects.cloneObject(personNameModel);
-               assertThat(clone.getObject(), is(personName));
-       }
-
-       @Test
-       public void equality()
-       {
-               Person person = new Person();
-               final WicketSupplier<String> getName = person::getName;
-               IModel<String> personNameModel1 = new SupplierModel<>(getName);
-               IModel<String> personNameModel2 = new SupplierModel<>(getName);
-               assertEquals(personNameModel1, personNameModel2);
-       }
-
-       @Test
-       public void hashcode()
-       {
-               Person person = new Person();
-               final WicketSupplier<String> getName = person::getName;
-               IModel<String> personNameModel1 = new SupplierModel<>(getName);
-               IModel<String> personNameModel2 = new SupplierModel<>(getName);
-               assertEquals(personNameModel1.hashCode(), 
personNameModel2.hashCode());
-       }
-}

Reply via email to