You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2015/01/07 00:26:23 UTC

[45/47] isis git commit: ISIS-1000 Add unit tests for CssClassFacetMethod and CssClassFacetMethodFactory

ISIS-1000 Add unit tests for CssClassFacetMethod and CssClassFacetMethodFactory

Use assertThat() in IconFacetMethod(Factory)Test


Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/718b8f01
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/718b8f01
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/718b8f01

Branch: refs/heads/ISIS-985
Commit: 718b8f01a7899eeefb4ac049006553cd4cda1f06
Parents: 21065af
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Tue Jan 6 21:05:39 2015 +0200
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Tue Jan 6 20:15:34 2015 +0000

----------------------------------------------------------------------
 .../CssClassFacetMethodFactoryTest.java         | 70 ++++++++++++++++
 .../ident/cssclass/CssClassFacetMethodTest.java | 84 ++++++++++++++++++++
 .../CssClassFacetMethodWithProblemTest.java     | 82 +++++++++++++++++++
 .../ident/icon/IconFacetMethodFactoryTest.java  |  9 ++-
 .../object/ident/icon/IconFacetMethodTest.java  |  3 -
 5 files changed, 243 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/isis/blob/718b8f01/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/object/ident/cssclass/CssClassFacetMethodFactoryTest.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/object/ident/cssclass/CssClassFacetMethodFactoryTest.java b/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/object/ident/cssclass/CssClassFacetMethodFactoryTest.java
new file mode 100644
index 0000000..74a44c3
--- /dev/null
+++ b/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/object/ident/cssclass/CssClassFacetMethodFactoryTest.java
@@ -0,0 +1,70 @@
+/*
+ *  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.isis.core.metamodel.facets.object.ident.cssclass;
+
+import java.lang.reflect.Method;
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.facets.AbstractFacetFactoryTest;
+import org.apache.isis.core.metamodel.facets.FacetFactory.ProcessClassContext;
+import org.apache.isis.core.metamodel.facets.members.cssclass.CssClassFacet;
+import org.apache.isis.core.metamodel.facets.object.cssclass.method.CssClassFacetMethod;
+import org.apache.isis.core.metamodel.facets.object.cssclass.method.CssClassFacetMethodFactory;
+
+import static org.hamcrest.Matchers.instanceOf;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.junit.Assert.assertThat;
+
+public class CssClassFacetMethodFactoryTest extends AbstractFacetFactoryTest {
+
+    private CssClassFacetMethodFactory facetFactory;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        facetFactory = new CssClassFacetMethodFactory();
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        facetFactory = null;
+        super.tearDown();
+    }
+
+    public void testIconNameMethodPickedUpOnClassAndMethodRemoved() {
+        class Customer {
+            @SuppressWarnings("unused")
+            public String cssClass() {
+                return null;
+            }
+        }
+        final Method cssClassNameMethod = findMethod(Customer.class, "cssClass");
+
+        facetFactory.process(new ProcessClassContext(Customer.class, methodRemover, facetedMethod));
+
+        final Facet facet = facetedMethod.getFacet(CssClassFacet.class);
+        assertThat(facet, is(notNullValue()));
+        assertThat(facet, is(instanceOf(CssClassFacetMethod.class)));
+
+        assertTrue(methodRemover.getRemovedMethodMethodCalls().contains(cssClassNameMethod));
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/718b8f01/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/object/ident/cssclass/CssClassFacetMethodTest.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/object/ident/cssclass/CssClassFacetMethodTest.java b/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/object/ident/cssclass/CssClassFacetMethodTest.java
new file mode 100644
index 0000000..65de148
--- /dev/null
+++ b/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/object/ident/cssclass/CssClassFacetMethodTest.java
@@ -0,0 +1,84 @@
+/*
+ *  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.isis.core.metamodel.facets.object.ident.cssclass;
+
+import java.lang.reflect.Method;
+import org.jmock.Expectations;
+import org.jmock.Mockery;
+import org.jmock.integration.junit4.JUnit4Mockery;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.object.cssclass.method.CssClassFacetMethod;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.junit.Assert.assertThat;
+
+public class CssClassFacetMethodTest {
+
+    public static final String CSS_CLASS = "someCssClass";
+    private final Mockery mockery = new JUnit4Mockery();
+
+    private CssClassFacetMethod facet;
+    private FacetHolder mockFacetHolder;
+
+    private ObjectAdapter mockOwningAdapter;
+
+    private DomainObjectInCssClassMethod pojo;
+
+    public static class DomainObjectInCssClassMethod {
+        public String cssClass() {
+            return CSS_CLASS;
+        }
+    }
+
+    @Before
+    public void setUp() throws Exception {
+
+        pojo = new DomainObjectInCssClassMethod();
+        mockFacetHolder = mockery.mock(FacetHolder.class);
+        mockOwningAdapter = mockery.mock(ObjectAdapter.class);
+        final Method iconNameMethod = DomainObjectInCssClassMethod.class.getMethod("cssClass");
+        facet = new CssClassFacetMethod(iconNameMethod, mockFacetHolder);
+
+        mockery.checking(new Expectations() {
+            {
+                allowing(mockOwningAdapter).getObject();
+                will(returnValue(pojo));
+            }
+        });
+    }
+
+    @After
+    public void tearDown() {
+        facet = null;
+    }
+
+    @Test
+    public void testCssClassThrowsException() {
+        final String iconName = facet.cssClass(mockOwningAdapter);
+        assertThat(iconName, is(equalTo(CSS_CLASS)));
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/718b8f01/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/object/ident/cssclass/CssClassFacetMethodWithProblemTest.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/object/ident/cssclass/CssClassFacetMethodWithProblemTest.java b/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/object/ident/cssclass/CssClassFacetMethodWithProblemTest.java
new file mode 100644
index 0000000..47d2d8d
--- /dev/null
+++ b/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/object/ident/cssclass/CssClassFacetMethodWithProblemTest.java
@@ -0,0 +1,82 @@
+/*
+ *  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.isis.core.metamodel.facets.object.ident.cssclass;
+
+import java.lang.reflect.Method;
+import org.jmock.Expectations;
+import org.jmock.Mockery;
+import org.jmock.integration.junit4.JUnit4Mockery;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.object.cssclass.method.CssClassFacetMethod;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.junit.Assert.assertThat;
+
+public class CssClassFacetMethodWithProblemTest {
+
+    private final Mockery mockery = new JUnit4Mockery();
+
+    private CssClassFacetMethod facet;
+    private FacetHolder mockFacetHolder;
+
+    private ObjectAdapter mockOwningAdapter;
+
+    private DomainObjectWithProblemInCssClassMethod pojo;
+
+    public static class DomainObjectWithProblemInCssClassMethod {
+        public String cssClass() {
+            throw new NullPointerException();
+        }
+    }
+
+    @Before
+    public void setUp() throws Exception {
+
+        pojo = new DomainObjectWithProblemInCssClassMethod();
+        mockFacetHolder = mockery.mock(FacetHolder.class);
+        mockOwningAdapter = mockery.mock(ObjectAdapter.class);
+        final Method iconNameMethod = DomainObjectWithProblemInCssClassMethod.class.getMethod("cssClass");
+        facet = new CssClassFacetMethod(iconNameMethod, mockFacetHolder);
+
+        mockery.checking(new Expectations() {
+            {
+                allowing(mockOwningAdapter).getObject();
+                will(returnValue(pojo));
+            }
+        });
+    }
+
+    @After
+    public void tearDown() {
+        facet = null;
+    }
+
+    @Test
+    public void testCssClassThrowsException() {
+        final String iconName = facet.cssClass(mockOwningAdapter);
+        assertThat(iconName, is(nullValue()));
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/718b8f01/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/object/ident/icon/IconFacetMethodFactoryTest.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/object/ident/icon/IconFacetMethodFactoryTest.java b/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/object/ident/icon/IconFacetMethodFactoryTest.java
index d962c9f..bf597a2 100644
--- a/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/object/ident/icon/IconFacetMethodFactoryTest.java
+++ b/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/object/ident/icon/IconFacetMethodFactoryTest.java
@@ -28,6 +28,11 @@ import org.apache.isis.core.metamodel.facets.AbstractFacetFactoryTest;
 import org.apache.isis.core.metamodel.facets.object.icon.method.IconFacetMethod;
 import org.apache.isis.core.metamodel.facets.object.icon.method.IconFacetMethodFactory;
 
+import static org.hamcrest.Matchers.instanceOf;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.junit.Assert.assertThat;
+
 public class IconFacetMethodFactoryTest extends AbstractFacetFactoryTest {
 
     private IconFacetMethodFactory facetFactory;
@@ -57,8 +62,8 @@ public class IconFacetMethodFactoryTest extends AbstractFacetFactoryTest {
         facetFactory.process(new ProcessClassContext(Customer.class, methodRemover, facetedMethod));
 
         final Facet facet = facetedMethod.getFacet(IconFacet.class);
-        assertNotNull(facet);
-        assertTrue(facet instanceof IconFacetMethod);
+        assertThat(facet, is(notNullValue()));
+        assertThat(facet, is(instanceOf(IconFacetMethod.class)));
 
         assertTrue(methodRemover.getRemovedMethodMethodCalls().contains(iconNameMethod));
     }

http://git-wip-us.apache.org/repos/asf/isis/blob/718b8f01/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/object/ident/icon/IconFacetMethodTest.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/object/ident/icon/IconFacetMethodTest.java b/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/object/ident/icon/IconFacetMethodTest.java
index 8111db4..69e6249 100644
--- a/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/object/ident/icon/IconFacetMethodTest.java
+++ b/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/object/ident/icon/IconFacetMethodTest.java
@@ -22,12 +22,10 @@ package org.apache.isis.core.metamodel.facets.object.ident.icon;
 import java.lang.reflect.Method;
 import org.jmock.Expectations;
 import org.jmock.Mockery;
-import org.jmock.integration.junit4.JMock;
 import org.jmock.integration.junit4.JUnit4Mockery;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
-import org.junit.runner.RunWith;
 import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
 import org.apache.isis.core.metamodel.facetapi.FacetHolder;
 import org.apache.isis.core.metamodel.facets.object.icon.method.IconFacetMethod;
@@ -36,7 +34,6 @@ import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.CoreMatchers.nullValue;
 import static org.junit.Assert.assertThat;
 
-@RunWith(JMock.class)
 public class IconFacetMethodTest {
 
     private final Mockery mockery = new JUnit4Mockery();