Repository: isis Updated Branches: refs/heads/master 75735601c -> 0a17eb4a0
ISIS-928: refactoring unit tests of simpleapp to use nested static class format. Project: http://git-wip-us.apache.org/repos/asf/isis/repo Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/4e7dde9f Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/4e7dde9f Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/4e7dde9f Branch: refs/heads/master Commit: 4e7dde9f694728ac5b87bff7b961ae8556be43e3 Parents: 7573560 Author: Dan Haywood <[email protected]> Authored: Tue Nov 18 12:03:03 2014 +0100 Committer: Dan Haywood <[email protected]> Committed: Tue Nov 18 12:09:22 2014 +0100 ---------------------------------------------------------------------- .../test/java/dom/simple/SimpleObjectTest.java | 51 ++++++++++ .../java/dom/simple/SimpleObjectTest_name.java | 48 --------- .../test/java/dom/simple/SimpleObjectsTest.java | 102 +++++++++++++++++++ .../dom/simple/SimpleObjectsTest_create.java | 74 -------------- .../dom/simple/SimpleObjectsTest_listAll.java | 69 ------------- 5 files changed, 153 insertions(+), 191 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/isis/blob/4e7dde9f/example/application/simpleapp/dom/src/test/java/dom/simple/SimpleObjectTest.java ---------------------------------------------------------------------- diff --git a/example/application/simpleapp/dom/src/test/java/dom/simple/SimpleObjectTest.java b/example/application/simpleapp/dom/src/test/java/dom/simple/SimpleObjectTest.java new file mode 100644 index 0000000..fe6f0ac --- /dev/null +++ b/example/application/simpleapp/dom/src/test/java/dom/simple/SimpleObjectTest.java @@ -0,0 +1,51 @@ +/** + * 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 dom.simple; + +import org.junit.Before; +import org.junit.Test; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.junit.Assert.assertThat; + +public class SimpleObjectTest { + + SimpleObject simpleObject; + + @Before + public void setUp() throws Exception { + simpleObject = new SimpleObject(); + } + + public static class Name extends SimpleObjectTest { + + @Test + public void happyCase() throws Exception { + // given + String name = "Foobar"; + assertThat(simpleObject.getName(), is(nullValue())); + + // when + simpleObject.setName(name); + + // then + assertThat(simpleObject.getName(), is(name)); + } + } + +} http://git-wip-us.apache.org/repos/asf/isis/blob/4e7dde9f/example/application/simpleapp/dom/src/test/java/dom/simple/SimpleObjectTest_name.java ---------------------------------------------------------------------- diff --git a/example/application/simpleapp/dom/src/test/java/dom/simple/SimpleObjectTest_name.java b/example/application/simpleapp/dom/src/test/java/dom/simple/SimpleObjectTest_name.java deleted file mode 100644 index ac1905b..0000000 --- a/example/application/simpleapp/dom/src/test/java/dom/simple/SimpleObjectTest_name.java +++ /dev/null @@ -1,48 +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 dom.simple; - -import org.junit.Before; -import org.junit.Test; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.nullValue; -import static org.junit.Assert.assertThat; - -public class SimpleObjectTest_name { - - private SimpleObject simpleObject; - - @Before - public void setUp() throws Exception { - simpleObject = new SimpleObject(); - } - - @Test - public void happyCase() throws Exception { - // given - String name = "Foobar"; - assertThat(simpleObject.getName(), is(nullValue())); - - // when - simpleObject.setName(name); - - // then - assertThat(simpleObject.getName(), is(name)); - } - -} http://git-wip-us.apache.org/repos/asf/isis/blob/4e7dde9f/example/application/simpleapp/dom/src/test/java/dom/simple/SimpleObjectsTest.java ---------------------------------------------------------------------- diff --git a/example/application/simpleapp/dom/src/test/java/dom/simple/SimpleObjectsTest.java b/example/application/simpleapp/dom/src/test/java/dom/simple/SimpleObjectsTest.java new file mode 100644 index 0000000..27b9ac3 --- /dev/null +++ b/example/application/simpleapp/dom/src/test/java/dom/simple/SimpleObjectsTest.java @@ -0,0 +1,102 @@ +/** + * 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 dom.simple; + +import java.util.List; +import com.google.common.collect.Lists; +import org.jmock.Expectations; +import org.jmock.Sequence; +import org.jmock.auto.Mock; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.apache.isis.applib.DomainObjectContainer; +import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2; +import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2.Mode; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +public class SimpleObjectsTest { + + @Rule + public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES); + + @Mock + DomainObjectContainer mockContainer; + + SimpleObjects simpleObjects; + + @Before + public void setUp() throws Exception { + simpleObjects = new SimpleObjects(); + simpleObjects.container = mockContainer; + } + + public static class Create extends SimpleObjectsTest { + + @Test + public void happyCase() throws Exception { + + // given + final SimpleObject simpleObject = new SimpleObject(); + + final Sequence seq = context.sequence("create"); + context.checking(new Expectations() { + { + oneOf(mockContainer).newTransientInstance(SimpleObject.class); + inSequence(seq); + will(returnValue(simpleObject)); + + oneOf(mockContainer).persistIfNotAlready(simpleObject); + inSequence(seq); + } + }); + + // when + final SimpleObject obj = simpleObjects.create("Foobar"); + + // then + assertThat(obj, is(simpleObject)); + assertThat(obj.getName(), is("Foobar")); + } + + } + + public static class ListAll extends SimpleObjectsTest { + + @Test + public void happyCase() throws Exception { + + // given + final List<SimpleObject> all = Lists.newArrayList(); + + context.checking(new Expectations() { + { + oneOf(mockContainer).allInstances(SimpleObject.class); + will(returnValue(all)); + } + }); + + // when + final List<SimpleObject> list = simpleObjects.listAll(); + + // then + assertThat(list, is(all)); + } + } +} http://git-wip-us.apache.org/repos/asf/isis/blob/4e7dde9f/example/application/simpleapp/dom/src/test/java/dom/simple/SimpleObjectsTest_create.java ---------------------------------------------------------------------- diff --git a/example/application/simpleapp/dom/src/test/java/dom/simple/SimpleObjectsTest_create.java b/example/application/simpleapp/dom/src/test/java/dom/simple/SimpleObjectsTest_create.java deleted file mode 100644 index 4fcb268..0000000 --- a/example/application/simpleapp/dom/src/test/java/dom/simple/SimpleObjectsTest_create.java +++ /dev/null @@ -1,74 +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 dom.simple; - -import org.jmock.Expectations; -import org.jmock.Sequence; -import org.jmock.auto.Mock; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.apache.isis.applib.DomainObjectContainer; -import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2; -import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2.Mode; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -public class SimpleObjectsTest_create { - - @Rule - public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES); - - @Mock - private DomainObjectContainer mockContainer; - - private SimpleObjects simpleObjects; - - @Before - public void setUp() throws Exception { - simpleObjects = new SimpleObjects(); - simpleObjects.container = mockContainer; - } - - @Test - public void happyCase() throws Exception { - - // given - final SimpleObject simpleObject = new SimpleObject(); - - final Sequence seq = context.sequence("create"); - context.checking(new Expectations() { - { - oneOf(mockContainer).newTransientInstance(SimpleObject.class); - inSequence(seq); - will(returnValue(simpleObject)); - - oneOf(mockContainer).persistIfNotAlready(simpleObject); - inSequence(seq); - } - }); - - // when - final SimpleObject obj = simpleObjects.create("Foobar"); - - // then - assertThat(obj, is(simpleObject)); - assertThat(obj.getName(), is("Foobar")); - } - -} http://git-wip-us.apache.org/repos/asf/isis/blob/4e7dde9f/example/application/simpleapp/dom/src/test/java/dom/simple/SimpleObjectsTest_listAll.java ---------------------------------------------------------------------- diff --git a/example/application/simpleapp/dom/src/test/java/dom/simple/SimpleObjectsTest_listAll.java b/example/application/simpleapp/dom/src/test/java/dom/simple/SimpleObjectsTest_listAll.java deleted file mode 100644 index 8a1ffbd..0000000 --- a/example/application/simpleapp/dom/src/test/java/dom/simple/SimpleObjectsTest_listAll.java +++ /dev/null @@ -1,69 +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 dom.simple; - -import java.util.List; -import com.google.common.collect.Lists; -import org.jmock.Expectations; -import org.jmock.auto.Mock; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.apache.isis.applib.DomainObjectContainer; -import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2; -import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2.Mode; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -public class SimpleObjectsTest_listAll { - - @Rule - public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES); - - @Mock - private DomainObjectContainer mockContainer; - - private SimpleObjects simpleObjects; - - @Before - public void setUp() throws Exception { - simpleObjects = new SimpleObjects(); - simpleObjects.container = mockContainer; - } - - @Test - public void happyCase() throws Exception { - - // given - final List<SimpleObject> all = Lists.newArrayList(); - - context.checking(new Expectations() { - { - oneOf(mockContainer).allInstances(SimpleObject.class); - will(returnValue(all)); - } - }); - - // when - final List<SimpleObject> list = simpleObjects.listAll(); - - // then - assertThat(list, is(all)); - } - -}
