This is an automated email from the ASF dual-hosted git repository. ahuber pushed a commit to branch v3 in repository https://gitbox.apache.org/repos/asf/causeway.git
The following commit(s) were added to refs/heads/v3 by this push: new fb7b44e68de CAUSEWAY-2297: ditch JUnit4 and JUnit4 based JMock integration fb7b44e68de is described below commit fb7b44e68de1feb6475968b2040c0bc59fc873ce Author: Andi Huber <ahu...@apache.org> AuthorDate: Thu Nov 21 15:56:15 2024 +0100 CAUSEWAY-2297: ditch JUnit4 and JUnit4 based JMock integration --- bom/pom.xml | 2 +- .../testdomain/fixtures/EntityTestFixtures.java | 4 +- .../causeway/testdomain/jdo/JdoInventoryDao.java | 2 +- .../causeway/testdomain/jpa/JpaInventoryDao.java | 2 +- .../bootstrapping/AutoConfigurationTest.java | 4 +- .../domainmodel/DomainModelTest_forEditing.java | 2 +- .../persistence/jdo/JdoBootstrappingTest.java | 2 +- .../testdomain/persistence/jdo/JdoQueryTest.java | 2 +- .../timestamping/jdo/JdoTimestampingTest.java | 2 +- .../persistence/jpa/JpaBootstrappingTest.java | 2 +- .../testdomain/persistence/jpa/JpaQueryTest.java | 2 +- .../springdata/SpringDataJpaBootstrappingTest.java | 2 +- .../testing/fakedata/applib/services/Integers.java | 4 +- .../applib/services/FakeDataServiceTest.java | 60 ++--- testing/unittestsupport/applib/pom.xml | 14 +- .../dom/value/ValueTypeContractTestAbstract.java | 8 +- .../applib/jmocking/CausewayActions.java | 64 ----- .../jmocking/ImposteriserUsingCodegenPlugin.java | 90 ------- .../applib/jmocking/Imposterisers.java | 37 --- .../applib/jmocking/InjectIntoJMockAction.java | 66 ----- .../applib/jmocking/JMockActions.java | 89 ------ .../applib/jmocking/JUnitRuleMockery2.java | 291 -------------------- .../applib/jmocking/MyMockomatic.java | 111 -------- .../applib/jmocking/PostponedAction.java | 49 ---- .../unittestsupport/applib/util/ApprovalUtils.java | 2 +- ...ewayActionsTest_returnNewTransientInstance.java | 88 ------ .../CollaboratingUsingConstructorInjection.java | 36 --- .../CollaboratingUsingSetterInjection.java | 39 --- .../applib/jmocking/Collaborator.java | 23 -- .../ImposteriserTestUsingCodegenPlugin_Test.java | 300 --------------------- .../jmocking/JMockActionsTest_returnArgument.java | 66 ----- .../jmocking/JMockActionsTest_returnEach.java | 68 ----- .../applib/jmocking/JUnitRuleMockery2Test.java | 45 ---- ..._autoWiring_constructorInjection_happyCase.java | 55 ---- ...y2Test_autoWiring_sadCase_noClassUnderTest.java | 44 --- ...est_autoWiring_sadCase_twoClassesUnderTest.java | 49 ---- ...2Test_autoWiring_setterInjection_happyCase.java | 55 ---- ...RuleMockery2Test_mockAnnotatedWithAllowing.java | 57 ---- ...RuleMockery2Test_mockAnnotatedWithIgnoring.java | 57 ---- ...kery2Test_mockAnnotatedWithNever_happyCase.java | 52 ---- ...ockery2Test_mockAnnotatedWithNever_sadCase.java | 57 ---- ...ockery2Test_mockAnnotatedWithOne_happyCase.java | 52 ---- ...eMockery2Test_mockAnnotatedWithOne_sadCase.java | 53 ---- .../applib/util/Files_deleteFileUtils_Test.java | 69 ++--- 44 files changed, 79 insertions(+), 2099 deletions(-) diff --git a/bom/pom.xml b/bom/pom.xml index f3a1d80ed1a..cf40f5a9b62 100644 --- a/bom/pom.xml +++ b/bom/pom.xml @@ -2105,7 +2105,7 @@ identified </dependency> <dependency> <groupId>org.jmock</groupId> - <artifactId>jmock-junit4</artifactId> + <artifactId>jmock-junit5</artifactId> <version>${jmock.version}</version> </dependency> diff --git a/regressiontests/base/src/main/java/org/apache/causeway/testdomain/fixtures/EntityTestFixtures.java b/regressiontests/base/src/main/java/org/apache/causeway/testdomain/fixtures/EntityTestFixtures.java index 12d1de6b3c8..b0d0926c97b 100644 --- a/regressiontests/base/src/main/java/org/apache/causeway/testdomain/fixtures/EntityTestFixtures.java +++ b/regressiontests/base/src/main/java/org/apache/causeway/testdomain/fixtures/EntityTestFixtures.java @@ -29,7 +29,7 @@ import java.util.stream.IntStream; import jakarta.inject.Inject; -import static org.junit.Assert.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -220,7 +220,7 @@ implements * VALUES (?,?,?,?,?,?,?,?,?) [42122-214] * ---- * This is an attempt to force the JDO schema to properly initialize. */ - protected void initSchema() {}; + protected void initSchema() {} @SneakyThrows public final Lock aquireLockAndClear() { diff --git a/regressiontests/base/src/main/java/org/apache/causeway/testdomain/jdo/JdoInventoryDao.java b/regressiontests/base/src/main/java/org/apache/causeway/testdomain/jdo/JdoInventoryDao.java index e5c25adb5de..a4cc531936d 100644 --- a/regressiontests/base/src/main/java/org/apache/causeway/testdomain/jdo/JdoInventoryDao.java +++ b/regressiontests/base/src/main/java/org/apache/causeway/testdomain/jdo/JdoInventoryDao.java @@ -20,8 +20,8 @@ package org.apache.causeway.testdomain.jdo; import jakarta.inject.Inject; -import static org.junit.Assert.assertNotNull; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Propagation; diff --git a/regressiontests/base/src/main/java/org/apache/causeway/testdomain/jpa/JpaInventoryDao.java b/regressiontests/base/src/main/java/org/apache/causeway/testdomain/jpa/JpaInventoryDao.java index 1a940ccc1c2..0d5307abe18 100644 --- a/regressiontests/base/src/main/java/org/apache/causeway/testdomain/jpa/JpaInventoryDao.java +++ b/regressiontests/base/src/main/java/org/apache/causeway/testdomain/jpa/JpaInventoryDao.java @@ -20,8 +20,8 @@ package org.apache.causeway.testdomain.jpa; import jakarta.inject.Inject; -import static org.junit.Assert.assertNotNull; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Propagation; diff --git a/regressiontests/bootstrapping/src/test/java/org/apache/causeway/testdomain/bootstrapping/AutoConfigurationTest.java b/regressiontests/bootstrapping/src/test/java/org/apache/causeway/testdomain/bootstrapping/AutoConfigurationTest.java index a2891f9301b..18592270183 100644 --- a/regressiontests/bootstrapping/src/test/java/org/apache/causeway/testdomain/bootstrapping/AutoConfigurationTest.java +++ b/regressiontests/bootstrapping/src/test/java/org/apache/causeway/testdomain/bootstrapping/AutoConfigurationTest.java @@ -23,9 +23,9 @@ import jakarta.inject.Inject; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.beans.factory.config.BeanPostProcessor; diff --git a/regressiontests/domainmodel/src/test/java/org/apache/causeway/testdomain/domainmodel/DomainModelTest_forEditing.java b/regressiontests/domainmodel/src/test/java/org/apache/causeway/testdomain/domainmodel/DomainModelTest_forEditing.java index 935f86e2097..26f52ab6fe1 100644 --- a/regressiontests/domainmodel/src/test/java/org/apache/causeway/testdomain/domainmodel/DomainModelTest_forEditing.java +++ b/regressiontests/domainmodel/src/test/java/org/apache/causeway/testdomain/domainmodel/DomainModelTest_forEditing.java @@ -24,8 +24,8 @@ import jakarta.xml.bind.annotation.XmlRootElement; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.TestPropertySource; diff --git a/regressiontests/persistence-jdo/src/test/java/org/apache/causeway/testdomain/persistence/jdo/JdoBootstrappingTest.java b/regressiontests/persistence-jdo/src/test/java/org/apache/causeway/testdomain/persistence/jdo/JdoBootstrappingTest.java index 3f0dbe8cdbf..dee64241569 100644 --- a/regressiontests/persistence-jdo/src/test/java/org/apache/causeway/testdomain/persistence/jdo/JdoBootstrappingTest.java +++ b/regressiontests/persistence-jdo/src/test/java/org/apache/causeway/testdomain/persistence/jdo/JdoBootstrappingTest.java @@ -28,8 +28,8 @@ import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestMethodOrder; -import static org.junit.Assert.assertNotNull; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.annotation.Commit; diff --git a/regressiontests/persistence-jdo/src/test/java/org/apache/causeway/testdomain/persistence/jdo/JdoQueryTest.java b/regressiontests/persistence-jdo/src/test/java/org/apache/causeway/testdomain/persistence/jdo/JdoQueryTest.java index 13d269aca77..3cb6d061db8 100644 --- a/regressiontests/persistence-jdo/src/test/java/org/apache/causeway/testdomain/persistence/jdo/JdoQueryTest.java +++ b/regressiontests/persistence-jdo/src/test/java/org/apache/causeway/testdomain/persistence/jdo/JdoQueryTest.java @@ -27,8 +27,8 @@ import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestMethodOrder; -import static org.junit.Assert.assertNotNull; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.TestPropertySource; diff --git a/regressiontests/persistence-jdo/src/test/java/org/apache/causeway/testdomain/timestamping/jdo/JdoTimestampingTest.java b/regressiontests/persistence-jdo/src/test/java/org/apache/causeway/testdomain/timestamping/jdo/JdoTimestampingTest.java index 15c488e9c17..bbf861bc24d 100644 --- a/regressiontests/persistence-jdo/src/test/java/org/apache/causeway/testdomain/timestamping/jdo/JdoTimestampingTest.java +++ b/regressiontests/persistence-jdo/src/test/java/org/apache/causeway/testdomain/timestamping/jdo/JdoTimestampingTest.java @@ -22,8 +22,8 @@ import jakarta.inject.Inject; import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.transaction.annotation.Transactional; diff --git a/regressiontests/persistence-jpa/src/test/java/org/apache/causeway/testdomain/persistence/jpa/JpaBootstrappingTest.java b/regressiontests/persistence-jpa/src/test/java/org/apache/causeway/testdomain/persistence/jpa/JpaBootstrappingTest.java index b12e3c01614..9c5be464fe8 100644 --- a/regressiontests/persistence-jpa/src/test/java/org/apache/causeway/testdomain/persistence/jpa/JpaBootstrappingTest.java +++ b/regressiontests/persistence-jpa/src/test/java/org/apache/causeway/testdomain/persistence/jpa/JpaBootstrappingTest.java @@ -29,9 +29,9 @@ import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestMethodOrder; -import static org.junit.Assert.assertNotNull; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; import org.springframework.boot.test.context.SpringBootTest; diff --git a/regressiontests/persistence-jpa/src/test/java/org/apache/causeway/testdomain/persistence/jpa/JpaQueryTest.java b/regressiontests/persistence-jpa/src/test/java/org/apache/causeway/testdomain/persistence/jpa/JpaQueryTest.java index a70e8765335..8f174ac2ede 100644 --- a/regressiontests/persistence-jpa/src/test/java/org/apache/causeway/testdomain/persistence/jpa/JpaQueryTest.java +++ b/regressiontests/persistence-jpa/src/test/java/org/apache/causeway/testdomain/persistence/jpa/JpaQueryTest.java @@ -31,8 +31,8 @@ import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestMethodOrder; -import static org.junit.Assert.assertNotNull; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.boot.test.context.SpringBootTest; diff --git a/regressiontests/persistence-jpa/src/test/java/org/apache/causeway/testdomain/persistence/jpa/springdata/SpringDataJpaBootstrappingTest.java b/regressiontests/persistence-jpa/src/test/java/org/apache/causeway/testdomain/persistence/jpa/springdata/SpringDataJpaBootstrappingTest.java index 99a2507851f..9b8912d6116 100644 --- a/regressiontests/persistence-jpa/src/test/java/org/apache/causeway/testdomain/persistence/jpa/springdata/SpringDataJpaBootstrappingTest.java +++ b/regressiontests/persistence-jpa/src/test/java/org/apache/causeway/testdomain/persistence/jpa/springdata/SpringDataJpaBootstrappingTest.java @@ -27,9 +27,9 @@ import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestMethodOrder; -import static org.junit.Assert.assertNotNull; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; import org.springframework.beans.factory.config.ConfigurableBeanFactory; diff --git a/testing/fakedata/applib/src/main/java/org/apache/causeway/testing/fakedata/applib/services/Integers.java b/testing/fakedata/applib/src/main/java/org/apache/causeway/testing/fakedata/applib/services/Integers.java index 09507578c2d..b119a4697a0 100644 --- a/testing/fakedata/applib/src/main/java/org/apache/causeway/testing/fakedata/applib/services/Integers.java +++ b/testing/fakedata/applib/src/main/java/org/apache/causeway/testing/fakedata/applib/services/Integers.java @@ -38,7 +38,9 @@ public class Integers extends AbstractRandomValueGenerator { } public int between(final int min, final int max) { - return min + fake.randomService.nextInt(max - min); + return min==max + ? min + : min + fake.randomService.nextInt(max - min); } } diff --git a/testing/fakedata/applib/src/test/java/org/apache/causeway/testing/fakedata/applib/services/FakeDataServiceTest.java b/testing/fakedata/applib/src/test/java/org/apache/causeway/testing/fakedata/applib/services/FakeDataServiceTest.java index 76cd956e7a7..8fa6eacb8a9 100644 --- a/testing/fakedata/applib/src/test/java/org/apache/causeway/testing/fakedata/applib/services/FakeDataServiceTest.java +++ b/testing/fakedata/applib/src/test/java/org/apache/causeway/testing/fakedata/applib/services/FakeDataServiceTest.java @@ -31,11 +31,9 @@ import java.util.Set; import java.util.UUID; import java.util.function.Predicate; -import org.jmock.Expectations; -import org.jmock.auto.Mock; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; import static org.assertj.core.api.Assertions.assertThat; @@ -47,39 +45,28 @@ import org.apache.causeway.applib.value.Clob; import org.apache.causeway.applib.value.Password; import org.apache.causeway.commons.internal.collections._Lists; import org.apache.causeway.commons.internal.collections._Sets; -import org.apache.causeway.testing.unittestsupport.applib.jmocking.JUnitRuleMockery2; -public class FakeDataServiceTest { - - @Rule - public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(JUnitRuleMockery2.Mode.INTERFACES_AND_CLASSES); +class FakeDataServiceTest { FakeDataService fakeDataService; + RepositoryService mockRepositoryService = Mockito.mock(RepositoryService.class); + ClockService mockClockService = Mockito.mock(ClockService.class); - @Mock - RepositoryService mockRepositoryService; - - @Mock - ClockService mockClockService; - - @Before + @BeforeEach public void setUp() throws Exception { fakeDataService = new FakeDataService(mockClockService, mockRepositoryService); fakeDataService.init(); - final VirtualClock virtualClock = VirtualClock.frozenAt(Instant.now()); - - context.checking(new Expectations() {{ - allowing(mockClockService).getClock(); - will(returnValue(virtualClock)); - }}); + final VirtualClock virtualClock = VirtualClock.frozenAt(Instant.now()); + Mockito.when(mockClockService.getClock()).thenReturn(virtualClock); } public static class CausewayBlobsTest extends FakeDataServiceTest { CausewayBlobs causewayBlobs; - @Before + @Override + @BeforeEach public void setUp() throws Exception { super.setUp(); causewayBlobs = fakeDataService.causewayBlobs(); @@ -127,7 +114,8 @@ public class FakeDataServiceTest { CausewayClobs causewayClobs; - @Before + @Override + @BeforeEach public void setUp() throws Exception { super.setUp(); causewayClobs = fakeDataService.causewayClobs(); @@ -209,14 +197,6 @@ public class FakeDataServiceTest { assertThat(pwd.getPassword().length()).isEqualTo(12); } - //TODO[2249] deprecated -// @Test -// public void moneys_any() throws Exception { -// final Money pwd = fakeDataService.causewayMoneys().any(); -// assertThat(pwd.getAmount()).isNotNull(); -// assertThat(pwd.getCurrency()).isNotNull(); -// } - @Test public void jodaDateTimes_any() throws Exception { final OffsetDateTime any = fakeDataService.javaTimeDateTimes().any(); @@ -285,12 +265,7 @@ public class FakeDataServiceTest { final Collection<Object> ints = _Lists.newArrayList(Arrays.asList(new Object(), thisOne, new Object())); for (int i = 0; i < 1000; i++) { - final Object rand = fakeDataService.collections().anyOfExcept(ints, new Predicate<Object>() { - @Override - public boolean test(final Object obj) { - return obj == thisOne; - } - }); + final Object rand = fakeDataService.collections().anyOfExcept(ints, (Predicate<Object>) obj -> obj == thisOne); seen.add(rand); } @@ -323,12 +298,7 @@ public class FakeDataServiceTest { final Collection<Integer> ints = _Lists.newArrayList(Arrays.asList(1, 2, 3, 4)); for (int i = 0; i < 1000; i++) { - final int rand = fakeDataService.collections().anyOfExcept(ints, new Predicate<Integer>() { - @Override - public boolean test(final Integer integer) { - return integer == 2; - } - }); + final int rand = fakeDataService.collections().anyOfExcept(ints, (Predicate<Integer>) integer -> integer == 2); seen.add(rand); } diff --git a/testing/unittestsupport/applib/pom.xml b/testing/unittestsupport/applib/pom.xml index 06a8dcad653..e4372cb427d 100644 --- a/testing/unittestsupport/applib/pom.xml +++ b/testing/unittestsupport/applib/pom.xml @@ -76,6 +76,10 @@ <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> </exclusion> + <exclusion> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter-api</artifactId> + </exclusion> </exclusions> </dependency> @@ -97,7 +101,7 @@ <dependency> <groupId>org.jmock</groupId> - <artifactId>jmock-junit4</artifactId> + <artifactId>jmock-junit5</artifactId> <exclusions> <exclusion> <groupId>junit</groupId> @@ -115,6 +119,14 @@ <groupId>org.objenesis</groupId> <artifactId>objenesis</artifactId> </exclusion> +<!-- <exclusion>--> +<!-- <groupId>org.junit.jupiter</groupId>--> +<!-- <artifactId>junit-jupiter-api</artifactId>--> +<!-- </exclusion>--> +<!-- <exclusion>--> +<!-- <groupId>org.junit.platform</groupId>--> +<!-- <artifactId>junit-platform-launcher</artifactId>--> +<!-- </exclusion>--> </exclusions> </dependency> diff --git a/testing/unittestsupport/applib/src/main/java/org/apache/causeway/testing/unittestsupport/applib/dom/value/ValueTypeContractTestAbstract.java b/testing/unittestsupport/applib/src/main/java/org/apache/causeway/testing/unittestsupport/applib/dom/value/ValueTypeContractTestAbstract.java index 206ebc1b4a7..8b1052d9f1a 100644 --- a/testing/unittestsupport/applib/src/main/java/org/apache/causeway/testing/unittestsupport/applib/dom/value/ValueTypeContractTestAbstract.java +++ b/testing/unittestsupport/applib/src/main/java/org/apache/causeway/testing/unittestsupport/applib/dom/value/ValueTypeContractTestAbstract.java @@ -29,7 +29,7 @@ import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.notNullValue; -import static org.junit.Assume.assumeThat; +import static org.junit.jupiter.api.Assumptions.assumeTrue; /** * Contract test for value types ({@link #equals(Object) equals} and @@ -99,11 +99,11 @@ public abstract class ValueTypeContractTestAbstract<T> { @SuppressWarnings({ "rawtypes", "unchecked" }) public void comparableEquivalence() throws Exception { for (final T o1 : getObjectsWithSameValue()) { - assumeThat(o1 instanceof Comparable, is(true)); + assumeTrue(o1 instanceof Comparable); Comparable c1 = (Comparable)o1; for (final T o2 : getObjectsWithSameValue()) { - assumeThat(o2 instanceof Comparable, is(true)); + assumeTrue(o2 instanceof Comparable); Comparable c2 = (Comparable)o2; assertThat(c1.compareTo(c2), is(0)); @@ -111,7 +111,7 @@ public abstract class ValueTypeContractTestAbstract<T> { } for (final T o2 : getObjectsWithDifferentValue()) { - assumeThat(o2 instanceof Comparable, is(true)); + assumeTrue(o2 instanceof Comparable); Comparable c2 = (Comparable)o2; final int x = c1.compareTo(c2); diff --git a/testing/unittestsupport/applib/src/main/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/CausewayActions.java b/testing/unittestsupport/applib/src/main/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/CausewayActions.java deleted file mode 100644 index 27664968c9c..00000000000 --- a/testing/unittestsupport/applib/src/main/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/CausewayActions.java +++ /dev/null @@ -1,64 +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.causeway.testing.unittestsupport.applib.jmocking; - -import org.hamcrest.Description; -import org.jmock.api.Action; -import org.jmock.api.Invocation; - -import org.apache.causeway.commons.internal.factory._InstanceUtil; - -/** - * @since 2.0 {@index} - */ -public final class CausewayActions { - - private CausewayActions() { - } - - public static Action injectInto() { - return InjectIntoJMockAction.injectInto(); - } - - @SafeVarargs - public static <T> Action returnEach(final T... values) { - return JMockActions.returnEach(values); - } - - public static Action returnArgument(final int i) { - return JMockActions.returnArgument(i); - } - - public static Action returnNewTransientInstance() { - return new Action(){ - - @Override - public void describeTo(final Description description) { - description.appendText("new transient instance"); - } - - @Override - public Object invoke(final Invocation invocation) throws Throwable { - var cls = (Class<?>) invocation.getParameter(0); - return _InstanceUtil.createInstance(cls); - } - }; - } - -} diff --git a/testing/unittestsupport/applib/src/main/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/ImposteriserUsingCodegenPlugin.java b/testing/unittestsupport/applib/src/main/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/ImposteriserUsingCodegenPlugin.java deleted file mode 100644 index b1447cd9bb8..00000000000 --- a/testing/unittestsupport/applib/src/main/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/ImposteriserUsingCodegenPlugin.java +++ /dev/null @@ -1,90 +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.causeway.testing.unittestsupport.applib.jmocking; - -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; - -import org.jmock.api.Imposteriser; -import org.jmock.api.Invocation; -import org.jmock.api.Invokable; -import org.jmock.lib.JavaReflectionImposteriser; - -import org.apache.causeway.commons.internal.proxy._ProxyFactory; -import org.apache.causeway.core.codegen.bytebuddy.services.ProxyFactoryServiceByteBuddy; - -class ImposteriserUsingCodegenPlugin implements Imposteriser { - - public static final Imposteriser INSTANCE = new ImposteriserUsingCodegenPlugin(); - - private final Imposteriser reflectionImposteriser = new JavaReflectionImposteriser(); - - private ImposteriserUsingCodegenPlugin() { - } - - @Override - public boolean canImposterise(Class<?> mockedType) { - - if(mockedType.isInterface()) { - return reflectionImposteriser.canImposterise(mockedType); - } - - return !mockedType.isPrimitive() && - !Modifier.isFinal(mockedType.getModifiers()) && - !toStringMethodIsFinal(mockedType); - } - - @Override - public <T> T imposterise(final Invokable mockObject, final Class<T> mockedType, Class<?>... ancilliaryTypes) { - if (!canImposterise(mockedType)) { - throw new IllegalArgumentException(mockedType.getName() + " cannot be imposterized (either a primitive, or a final type or has final toString method)"); - } - - if(mockedType.isInterface()) { - return reflectionImposteriser.imposterise(mockObject, mockedType, ancilliaryTypes); - } - - final _ProxyFactory<T> factory = _ProxyFactory.builder(mockedType) - .interfaces(ancilliaryTypes) - .build(new ProxyFactoryServiceByteBuddy()); - - final boolean initialize = false; - - return factory.createInstance( - (obj, method, args)->mockObject.invoke(new Invocation(obj, method, args)), - initialize); - } - - // ////////////////////////////////////// - - private static boolean toStringMethodIsFinal(Class<?> type) { - try { - Method toString = type.getMethod("toString"); - return Modifier.isFinal(toString.getModifiers()); - - } - catch (SecurityException e) { - throw new IllegalStateException("not allowed to reflect on toString method", e); - } - catch (NoSuchMethodException e) { - throw new Error("no public toString method found", e); - } - } - -} diff --git a/testing/unittestsupport/applib/src/main/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/Imposterisers.java b/testing/unittestsupport/applib/src/main/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/Imposterisers.java deleted file mode 100644 index eab27628b9c..00000000000 --- a/testing/unittestsupport/applib/src/main/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/Imposterisers.java +++ /dev/null @@ -1,37 +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.causeway.testing.unittestsupport.applib.jmocking; - -import org.jmock.api.Imposteriser; - -/** - * @since 2.0 {@index} - */ -public final class Imposterisers { - - private Imposterisers() {} - - /** - * @return framework's default Imposteriser instance - */ - public static Imposteriser getDefault() { - return ImposteriserUsingCodegenPlugin.INSTANCE; - } - -} diff --git a/testing/unittestsupport/applib/src/main/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/InjectIntoJMockAction.java b/testing/unittestsupport/applib/src/main/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/InjectIntoJMockAction.java deleted file mode 100644 index 741fb902779..00000000000 --- a/testing/unittestsupport/applib/src/main/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/InjectIntoJMockAction.java +++ /dev/null @@ -1,66 +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.causeway.testing.unittestsupport.applib.jmocking; - -import java.lang.reflect.Method; - -import org.hamcrest.Description; -import org.jmock.api.Action; -import org.jmock.api.Invocation; - -/** - * @since 2.0 {@index} - */ -public final class InjectIntoJMockAction implements Action { - - @Override - public void describeTo(final Description description) { - description.appendText("inject self"); - } - - // x.injectInto(y) ---> y.setXxx(x) - @Override - public Object invoke(final Invocation invocation) throws Throwable { - final Object injectable = invocation.getInvokedObject(); - final Object toInjectInto = invocation.getParameter(0); - final Method[] methods = toInjectInto.getClass().getMethods(); - for (final Method method : methods) { - if (!method.getName().startsWith("set")) { - continue; - } - if (method.getParameterTypes().length != 1) { - continue; - } - final Class<?> methodParameterType = method.getParameterTypes()[0]; - if (methodParameterType.isAssignableFrom(injectable.getClass())) { - method.invoke(toInjectInto, injectable); - break; - } - } - return null; - } - - /** - * Factory - */ - public static Action injectInto() { - return new InjectIntoJMockAction(); - } - -} diff --git a/testing/unittestsupport/applib/src/main/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/JMockActions.java b/testing/unittestsupport/applib/src/main/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/JMockActions.java deleted file mode 100644 index 61427af068d..00000000000 --- a/testing/unittestsupport/applib/src/main/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/JMockActions.java +++ /dev/null @@ -1,89 +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.causeway.testing.unittestsupport.applib.jmocking; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Iterator; - -import org.hamcrest.Description; -import org.jmock.api.Action; -import org.jmock.api.Invocation; - -/** - * @since 2.0 {@index} - */ -public final class JMockActions { - - private JMockActions() { - } - - @SafeVarargs - public static <T> Action returnEach(final T... values) { - return new ReturnEachAction<T>(values); - } - - public static Action returnArgument(final int i) { - return new ReturnArgumentJMockAction(i); - } - - private static class ReturnEachAction<T> implements Action { - - private final Collection<T> collection; - private final Iterator<T> iterator; - - ReturnEachAction(Collection<T> collection) { - this.collection = collection; - this.iterator = collection.iterator(); - } - - @SafeVarargs - private ReturnEachAction(T... array) { - this(Arrays.asList(array)); - } - - @Override - public T invoke(Invocation invocation) throws Throwable { - return iterator.next(); - } - - @Override - public void describeTo(Description description) { - description.appendValueList("return iterator.next() over ", ", ", "", collection); - } - } - - private static final class ReturnArgumentJMockAction implements Action { - private final int i; - - private ReturnArgumentJMockAction(final int i) { - this.i = i; - } - - @Override - public void describeTo(final Description description) { - description.appendText("parameter #" + i + " "); - } - - @Override - public Object invoke(final Invocation invocation) throws Throwable { - return invocation.getParameter(i); - } - } -} diff --git a/testing/unittestsupport/applib/src/main/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/JUnitRuleMockery2.java b/testing/unittestsupport/applib/src/main/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/JUnitRuleMockery2.java deleted file mode 100644 index 9e2f41fe3e0..00000000000 --- a/testing/unittestsupport/applib/src/main/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/JUnitRuleMockery2.java +++ /dev/null @@ -1,291 +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.causeway.testing.unittestsupport.applib.jmocking; - -import java.lang.annotation.Retention; -import java.lang.annotation.Target; -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.util.List; -import java.util.function.Consumer; - -import static java.lang.annotation.ElementType.FIELD; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -import org.jmock.Expectations; -import org.jmock.auto.Mock; -import org.jmock.integration.junit4.JUnit4Mockery; -import org.jmock.internal.AllDeclaredFields; -import org.jmock.lib.concurrent.Synchroniser; -import org.junit.rules.MethodRule; -import org.junit.runners.model.FrameworkMethod; -import org.junit.runners.model.Statement; -import org.picocontainer.MutablePicoContainer; -import org.picocontainer.PicoBuilder; - -import static org.junit.Assert.fail; - -import org.apache.causeway.commons.internal.base._Casts; -import org.apache.causeway.commons.internal.reflection._Reflect; - -import lombok.RequiredArgsConstructor; - -import junit.framework.AssertionFailedError; - -/** - * Use as a <tt>@Rule</tt>, meaning that the <tt>@RunWith(JMock.class)</tt> can - * be ignored. - * - * <pre> - * public class MyTest { - * - * @Rule - * public final Junit4Mockery2 context = Junit4Mockery2.createFor(Mode.INTERFACES); - * - * } - * </pre> - * - * <p> - * The class also adds some convenience methods, and uses a factory method to - * make it explicit whether the context can mock only interfaces or interfaces - * and classes. - * - * @since 2.0 {@index} - */ -public class JUnitRuleMockery2 extends JUnit4Mockery implements MethodRule { - - /** - * Factory method. - */ - public static JUnitRuleMockery2 createFor(final Mode mode) { - - final JUnitRuleMockery2 jUnitRuleMockery2 = new JUnitRuleMockery2(); - if (mode == Mode.INTERFACES_AND_CLASSES) { - jUnitRuleMockery2.setImposteriser(Imposterisers.getDefault()); - } - jUnitRuleMockery2.setThreadingPolicy(new Synchroniser()); - return jUnitRuleMockery2; - } - - /** - * Annotate the field that references the class under test; - * is automatically instantiated and autowired by this class, - * accessible to the test using {@link JUnitRuleMockery2#getClassUnderTest()}. - */ - @Retention(RUNTIME) - @Target(FIELD) - public static @interface ClassUnderTest {} - - /** - * Annotate fields annotated with {@link Mock}, to indicate that they should be set up - * with an {@link Expectations#ignoring(Object)} expectation. - */ - @Retention(RUNTIME) - @Target(FIELD) - public static @interface Ignoring {} - - /** - * Annotate fields annotated with {@link Mock}, to indicate that they should be set up - * with an {@link Expectations#allowing(Object)} expectation. - */ - @Retention(RUNTIME) - @Target(FIELD) - public static @interface Allowing {} - - /** - * Annotate fields annotated with {@link Mock}, to indicate that they should be set up - * with an {@link Expectations#never(Object)} expectation. - */ - @Retention(RUNTIME) - @Target(FIELD) - public static @interface Never {} - - /** - * Annotate fields annotated with {@link Mock}, to indicate that they should be set up - * with an {@link Expectations#one(Object)} expectation. - */ - @Retention(RUNTIME) - @Target(FIELD) - public static @interface One {} - - /** - * Annotate fields annotated with {@link Mock}, to indicate that they should be set up - * to check the specified {@link ExpectationsOn expectation}. - */ - @Retention(RUNTIME) - @Target(FIELD) - public static @interface Checking { - Class<? extends ExpectationsOn> value() default ExpectationsOn.class; - } - - public static enum Mode { - INTERFACES_ONLY, INTERFACES_AND_CLASSES; - } - - private final MyMockomatic mockomatic = new MyMockomatic(this); - private final MutablePicoContainer container = new PicoBuilder().withConstructorInjection().withSetterInjection().build(); - private Class<?> cutType; - - private JUnitRuleMockery2() { - } - - @Override - public Statement apply(final Statement base, final FrameworkMethod method, final Object target) { - return new Statement() { - - @Override - public void evaluate() throws Throwable { - prepare(target); - base.evaluate(); - assertIsSatisfied(); - } - - private void prepare(final Object target) throws IllegalAccessException { - final List<Field> allFields = AllDeclaredFields.in(target.getClass()); - assertOnlyOneJMockContextIn(allFields); - List<Object> mocks = fillInAutoMocks(target, allFields); - Field cutField = locateClassUnderTestFieldIfAny(allFields); - if (cutField != null) { - cutType = cutField.getType(); - for (Object mock : mocks) { - container.addComponent(mock); - } - container.addComponent(cutType); - - final Object cut = container.getComponent(cutType); - _Reflect.setFieldOn(cutField, target, cut); - - } else { - cutType = null; - } - - } - - private void assertOnlyOneJMockContextIn(final List<Field> allFields) { - Field contextField = null; - for (final Field field : allFields) { - if (JUnitRuleMockery2.class.isAssignableFrom(field.getType())) { - if (null != contextField) { - fail("Test class should only have one JUnitRuleMockery2 field, found " + contextField.getName() + " and " + field.getName()); - } - contextField = field; - } - } - } - - protected Field locateClassUnderTestFieldIfAny(final List<Field> allFields) { - Field cutField = null; - for (final Field field : allFields) { - if(field.getAnnotation(ClassUnderTest.class) != null) { - if (null != cutField) { - fail("Test class should only have one field annotated with @ClassUnderTest, found " + cutField.getName() + " and " + field.getName()); - } - cutField = field; - } - } - return cutField; - } - - private List<Object> fillInAutoMocks(final Object target, final List<Field> allFields) { - return mockomatic.fillIn(target, allFields); - } - }; - } - - public <T> T getClassUnderTest() { - if(cutType == null) { - throw new IllegalStateException("No field annotated @ClassUnderTest was found"); - } - return _Casts.uncheckedCast( container.getComponent(cutType) ); - } - - /** - * Ignoring any interaction with the mock; an allowing/ignoring mock will be - * returned in turn. - */ - public <T> T ignoring(final T mock) { - checking(expectationsWith(exp->exp.ignoring(mock))); - return mock; - } - - /** - * Allow any interaction with the mock; an allowing mock will be returned in - * turn. - */ - public <T> T allowing(final T mock) { - checking(expectationsWith(exp->exp.allowing(mock))); - return mock; - } - - /** - * Prohibit any interaction with the mock. - */ - public <T> T never(final T mock) { - checking(expectationsWith(exp->exp.never(mock))); - return mock; - } - - /** - * Ignore a set of mocks. - */ - public void ignoring(Object... mocks) { - for (Object mock : mocks) { - ignoring(mock); - } - } - - /** - * Require one interaction - */ - public Object oneOf(final Object mock) { - checking(expectationsWith(exp->exp.oneOf(mock))); - return mock; - } - - @RequiredArgsConstructor - public static class ExpectationsOn extends Expectations { - private final Object mockObj; - public <T> T mock() { - return _Casts.uncheckedCast(mockObj); - } - } - - public <T> T checking(T mock, Class<? extends ExpectationsOn> expectationsClass) { - try { - Constructor<? extends ExpectationsOn> constructor = expectationsClass.getConstructor(Object.class); - ExpectationsOn expectations = constructor.newInstance(mock); - checking(expectations); - return mock; - } catch (Exception e) { - throw new AssertionFailedError("Unable to instantiate expectations class '" + expectationsClass.getName() + "'"); - } - } - - private static class ExpectationsWithInitializer extends Expectations { - private ExpectationsWithInitializer(Consumer<Expectations> initializer) { - super(); - initializer.accept(this); - } - } - - public static Expectations expectationsWith(Consumer<Expectations> initializer) { - return new ExpectationsWithInitializer(initializer); - } - -} diff --git a/testing/unittestsupport/applib/src/main/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/MyMockomatic.java b/testing/unittestsupport/applib/src/main/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/MyMockomatic.java deleted file mode 100644 index cf5b53c4662..00000000000 --- a/testing/unittestsupport/applib/src/main/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/MyMockomatic.java +++ /dev/null @@ -1,111 +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.causeway.testing.unittestsupport.applib.jmocking; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.List; - -import org.jmock.Sequence; -import org.jmock.States; -import org.jmock.auto.Auto; -import org.jmock.auto.Mock; - -import org.apache.causeway.commons.internal.reflection._Reflect; - -class MyMockomatic { - private final JUnitRuleMockery2 context; - - public MyMockomatic(final JUnitRuleMockery2 context) { - this.context = context; - } - - public List<Object> fillIn(final Object object, final List<Field> knownFields) { - List<Object> mocks = new ArrayList<Object>(); - for (final Field field : knownFields) { - autoMockIfAnnotated(object, field, mocks); - autoInstantiateIfAnnotated(object, field); - } - return mocks; - } - - private void autoMockIfAnnotated(final Object object, - final Field field, List<Object> mocks) { - if (!field.isAnnotationPresent(Mock.class)) { - return; - } - final Object mock = context.mock(field.getType(), field.getName()); - setAutoField(field, object, mock, "auto-mock field " + field.getName()); - if(field.isAnnotationPresent(JUnitRuleMockery2.Ignoring.class)) { - context.ignoring(mock); - } - if(field.isAnnotationPresent(JUnitRuleMockery2.Allowing.class)) { - context.allowing(mock); - } - if(field.isAnnotationPresent(JUnitRuleMockery2.Never.class)) { - context.never(mock); - } - if(field.isAnnotationPresent(JUnitRuleMockery2.One.class)) { - context.oneOf(mock); - } - if(field.isAnnotationPresent(JUnitRuleMockery2.Checking.class)) { - checking(field, mock); - } - mocks.add(mock); - } - - private <T> void checking(final Field field, final T mock) { - JUnitRuleMockery2.Checking checking = field.getAnnotation(JUnitRuleMockery2.Checking.class); - Class<? extends JUnitRuleMockery2.ExpectationsOn> expectationsOnClass = - (Class<? extends JUnitRuleMockery2.ExpectationsOn>) checking.value(); - context.checking(mock, expectationsOnClass); - } - - private void autoInstantiateIfAnnotated(final Object object, - final Field field) { - if (!field.isAnnotationPresent(Auto.class)) { - return; - } - final Class<?> type = field.getType(); - if (type == States.class) { - autoInstantiateStates(field, object); - } else if (type == Sequence.class) { - autoInstantiateSequence(field, object); - } else { - throw new IllegalStateException("cannot auto-instantiate field of type " + type.getName()); - } - } - - private void autoInstantiateStates(final Field field, final Object object) { - setAutoField(field, object, context.states(field.getName()), "auto-instantiate States field " + field.getName()); - } - - private void autoInstantiateSequence(final Field field, final Object object) { - setAutoField(field, object, context.sequence(field.getName()), "auto-instantiate Sequence field " + field.getName()); - } - - private void setAutoField(final Field field, final Object object, final Object value, final String description) { - try { - _Reflect.setFieldOn(field, object, value); - } catch (final IllegalAccessException e) { - throw new IllegalStateException("cannot " + description, e); - } - } - -} \ No newline at end of file diff --git a/testing/unittestsupport/applib/src/main/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/PostponedAction.java b/testing/unittestsupport/applib/src/main/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/PostponedAction.java deleted file mode 100644 index dd167d4545e..00000000000 --- a/testing/unittestsupport/applib/src/main/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/PostponedAction.java +++ /dev/null @@ -1,49 +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.causeway.testing.unittestsupport.applib.jmocking; - -import java.util.function.Supplier; - -import org.hamcrest.Description; -import org.jmock.api.Action; -import org.jmock.api.Invocation; - -import lombok.NonNull; -import lombok.RequiredArgsConstructor; - -/** - * @since 2.0 {@index} - */ -@RequiredArgsConstructor(staticName = "returnValuePostponed") -public class PostponedAction implements Action { - - @NonNull private Supplier<Object> resultSupplier; - - @Override - public Object invoke(Invocation invocation) throws Throwable { - return resultSupplier.get(); - } - - @Override - public void describeTo(Description description) { - description.appendText("returns "); - description.appendValue(resultSupplier.get()); - } - -} diff --git a/testing/unittestsupport/applib/src/main/java/org/apache/causeway/testing/unittestsupport/applib/util/ApprovalUtils.java b/testing/unittestsupport/applib/src/main/java/org/apache/causeway/testing/unittestsupport/applib/util/ApprovalUtils.java index 9e02d63d331..711c7407589 100644 --- a/testing/unittestsupport/applib/src/main/java/org/apache/causeway/testing/unittestsupport/applib/util/ApprovalUtils.java +++ b/testing/unittestsupport/applib/src/main/java/org/apache/causeway/testing/unittestsupport/applib/util/ApprovalUtils.java @@ -30,7 +30,7 @@ import lombok.experimental.UtilityClass; public class ApprovalUtils { /** - * Enables approvar testing's text compare for given file extension. + * Enables approval testing's text compare for given file extension. * @param ext - should include the leading dot '.' like in say {@code .yaml} */ public void registerFileExtensionForTextCompare(final String ext) { diff --git a/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/CausewayActionsTest_returnNewTransientInstance.java b/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/CausewayActionsTest_returnNewTransientInstance.java deleted file mode 100644 index 3bbd46bbc4b..00000000000 --- a/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/CausewayActionsTest_returnNewTransientInstance.java +++ /dev/null @@ -1,88 +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.causeway.testing.unittestsupport.applib.jmocking; - -import org.hamcrest.Description; -import org.hamcrest.Matcher; -import org.hamcrest.TypeSafeMatcher; -import org.jmock.Expectations; -import org.jmock.auto.Mock; -import org.junit.Rule; -import org.junit.Test; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.CoreMatchers.nullValue; -import static org.hamcrest.MatcherAssert.assertThat; - -public class CausewayActionsTest_returnNewTransientInstance { - - // we can't use the 'real' DomainObjectConainter because applib depends on this module, not vice versa - // but it doesn't matter; we are just testing the action (of the expectation), not the object on which - // we add the expectation - public static interface MyDomainObjectContainer { - <T> T newTransientInstance(Class<T> t); - - void persistIfNotAlready(Object o); - } - - public static class MyCustomer { - } - - @Mock - private MyDomainObjectContainer mockContainer; - - @Rule - public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(JUnitRuleMockery2.Mode.INTERFACES_AND_CLASSES); - - @Test - public void testIt() { - - context.checking(new Expectations() { - { - allowing(mockContainer).newTransientInstance(with(anySubclassOf(Object.class))); - will(CausewayActions.returnNewTransientInstance()); - ignoring(mockContainer); - } - }); - - // is allowed (and executed) - MyCustomer o = mockContainer.newTransientInstance(MyCustomer.class); - assertThat(o, is(not(nullValue()))); - - // is ignored - mockContainer.persistIfNotAlready(o); - } - - private static <X> Matcher<Class<X>> anySubclassOf(final Class<X> cls) { - return new TypeSafeMatcher<Class<X>>() { - - @Override - public void describeTo(final Description arg0) { - arg0.appendText("is subclass of ").appendText(cls.getName()); - } - - @Override - public boolean matchesSafely(final Class<X> item) { - return cls.isAssignableFrom(item); - } - }; - } - -} diff --git a/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/CollaboratingUsingConstructorInjection.java b/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/CollaboratingUsingConstructorInjection.java deleted file mode 100644 index ef3734d734e..00000000000 --- a/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/CollaboratingUsingConstructorInjection.java +++ /dev/null @@ -1,36 +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.causeway.testing.unittestsupport.applib.jmocking; - -public class CollaboratingUsingConstructorInjection { - final Collaborator collaborator; - - public CollaboratingUsingConstructorInjection(final Collaborator collaborator) { - this.collaborator = collaborator; - } - - public void collaborateWithCollaborator() { - collaborator.doOtherStuff(); - } - - public void dontCollaborateWithCollaborator() { - - } - -} \ No newline at end of file diff --git a/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/CollaboratingUsingSetterInjection.java b/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/CollaboratingUsingSetterInjection.java deleted file mode 100644 index 819c5d36e0f..00000000000 --- a/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/CollaboratingUsingSetterInjection.java +++ /dev/null @@ -1,39 +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.causeway.testing.unittestsupport.applib.jmocking; - -public class CollaboratingUsingSetterInjection { - Collaborator collaborator; - - public CollaboratingUsingSetterInjection() { - } - - public void setCollaborator(Collaborator collaborator) { - this.collaborator = collaborator; - } - - public void collaborateWithCollaborator() { - collaborator.doOtherStuff(); - } - - public void dontCollaborateWithCollaborator() { - - } - -} \ No newline at end of file diff --git a/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/Collaborator.java b/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/Collaborator.java deleted file mode 100644 index 28409b7f9c6..00000000000 --- a/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/Collaborator.java +++ /dev/null @@ -1,23 +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.causeway.testing.unittestsupport.applib.jmocking; - -public interface Collaborator { - public void doOtherStuff(); -} \ No newline at end of file diff --git a/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/ImposteriserTestUsingCodegenPlugin_Test.java b/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/ImposteriserTestUsingCodegenPlugin_Test.java deleted file mode 100644 index 6e0748c0c1e..00000000000 --- a/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/ImposteriserTestUsingCodegenPlugin_Test.java +++ /dev/null @@ -1,300 +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.causeway.testing.unittestsupport.applib.jmocking; - -import java.io.File; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.Date; - -import org.jmock.Expectations; -import org.jmock.api.Imposteriser; -import org.jmock.api.Invocation; -import org.jmock.api.Invokable; -import org.jmock.integration.junit4.JUnit4Mockery; -import org.jmock.lib.action.VoidAction; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; - -import org.apache.causeway.commons.internal.context._Context; -import org.apache.causeway.commons.internal.reflection._Reflect; - -class ImposteriserTestUsingCodegenPlugin_Test { - - private Imposteriser imposteriser = Imposterisers.getDefault(); - - private Invokable invokable; - @SuppressWarnings("unused") - private Invocation invocation; - - @BeforeEach - void setUp() throws Exception { - _Context.clear(); - invokable = invocation -> { - ImposteriserTestUsingCodegenPlugin_Test.this.invocation = invocation; - return "result"; - }; - } - - @AfterEach - void tearDown() throws Exception { - invokable = null; - invocation = null; - } - - @Test - void happyCaseWhenJdkInterface() { - assertTrue(imposteriser.canImposterise(Runnable.class)); - final Runnable imposter = imposteriser.imposterise(invokable, Runnable.class); - assertNotNull(imposter); - imposter.run(); - } - - @Test @Disabled("fails with surefire on jdk-11, not with eclipse") //TODO[2112] jdk-11 issue? - void happyCaseWhenJdkClass() { - assertTrue(imposteriser.canImposterise(Date.class)); - final Date imposter = imposteriser.imposterise(invokable, Date.class); - assertNotNull(imposter); - imposter.toString(); - } - - // class we want to mock, while making sure, that we have access to non public methods - static class NonPublicMethodStub { - Integer getInteger() { - return 1; - } - } - - @Test - void imposteriserShouldBeUsableForMockery() { - - final JUnit4Mockery context = new JUnit4Mockery() { - { - setImposteriser(imposteriser); - } - }; - - final NonPublicMethodStub mocked = context.mock(NonPublicMethodStub.class); - - context.checking(new Expectations() {{ - allowing(mocked).getInteger(); - will(returnValue(Integer.valueOf(2))); - }}); - - assertNotNull(mocked); - assertNotNull(mocked.getInteger()); - assertEquals(2, mocked.getInteger().intValue()); - } - - // ////////////////////////////////////// - - @Test - void cannotImposterisePrimitiveType() { - assertFalse(imposteriser.canImposterise(int.class)); - } - - @Test - void cannotImposteriseVoidType() { - assertFalse(imposteriser.canImposterise(void.class)); - } - - // ////////////////////////////////////// - - public static abstract class AnAbstractNestedClass { - public abstract String foo(); - } - - @Test - void happyCaseWhenAbstractClass() { - assertTrue(imposteriser.canImposterise(AnAbstractNestedClass.class)); - final AnAbstractNestedClass imposter = imposteriser.imposterise(invokable, AnAbstractNestedClass.class); - assertNotNull(imposter); - assertEquals("result", imposter.foo()); - } - - // ////////////////////////////////////// - - public static class AnInnerClass { - public String foo() {return "original result";} - } - - @Test - void happyCaseWhenNonFinalInstantiableClass() { - assertTrue(imposteriser.canImposterise(AnInnerClass.class)); - final AnInnerClass imposter = imposteriser.imposterise(invokable, AnInnerClass.class); - assertNotNull(imposter); - assertEquals("result", imposter.foo()); - } - - // ////////////////////////////////////// - - public static final class AFinalClass { - public String foo() {return "original result";} - } - - @Test - void cannotImposteriseWhenFinalInstantiableClasses() { - assertFalse(imposteriser.canImposterise(AFinalClass.class)); - } - - // ////////////////////////////////////// - - public static class AClassWithAPrivateConstructor { - private AClassWithAPrivateConstructor(final String someArgument) {} - - public String foo() {return "original result";} - } - - @Test - void happyCaseWhenClassWithNonPublicConstructor() { - assertTrue(imposteriser.canImposterise(AClassWithAPrivateConstructor.class)); - AClassWithAPrivateConstructor imposter = - imposteriser.imposterise(invokable, AClassWithAPrivateConstructor.class); - - assertNotNull(imposter); - assertEquals("result", imposter.foo()); - } - - // ////////////////////////////////////// - - public static class ConcreteClassWithConstructorAndInstanceInitializer { - { - shouldNotBeCalled("instance initializer"); - } - - public ConcreteClassWithConstructorAndInstanceInitializer() { - shouldNotBeCalled("constructor"); - } - - public String foo() { - shouldNotBeCalled("method foo()"); - return null; // never reached - } - - private static void shouldNotBeCalled(final String exceptionMessageIfCalled) { - throw new IllegalStateException(exceptionMessageIfCalled + " should not be called"); - } - } - - @Test - void happyCaseWhenConcreteClassWithConstructorAndInitialisersThatShouldNotBeCalled() { - assertTrue(imposteriser.canImposterise(ConcreteClassWithConstructorAndInstanceInitializer.class)); - ConcreteClassWithConstructorAndInstanceInitializer imposter = - imposteriser.imposterise(invokable, ConcreteClassWithConstructorAndInstanceInitializer.class); - assertNotNull(imposter); - assertEquals("result", imposter.foo()); - } - - // ////////////////////////////////////// - - public interface AnInterface { - String foo(); - } - - @Test - void happyCaseWhenCustomInterface() { - assertTrue(imposteriser.canImposterise(AnInterface.class)); - AnInterface imposter = imposteriser.imposterise(invokable, AnInterface.class); - - assertNotNull(imposter); - assertEquals("result", imposter.foo()); - } - - // ////////////////////////////////////// - - @Test - void happyCaseWhenClassInASignedJarFile() throws Exception { - File jarFile = new File("src/test/resources/signed.jar").getAbsoluteFile(); - - assertTrue(jarFile.exists()); - - URL jarURL = jarFile.toURI().toURL(); - try(URLClassLoader loader = new URLClassLoader(new URL[]{jarURL})){ - Class<?> typeInSignedJar = loader.loadClass("TypeInSignedJar"); - - assertTrue(imposteriser.canImposterise(typeInSignedJar)); - Object o = imposteriser.imposterise(new VoidAction(), typeInSignedJar); - - assertTrue(typeInSignedJar.isInstance(o)); - } - } - - // ////////////////////////////////////// - - public static class ClassWithFinalToStringMethod { - @Override - public final String toString() { - return "you can't override me!"; - } - } - - // See issue JMOCK-150 - @Test - void cannotImposteriseAClassWithAFinalToStringMethod() { - assertFalse(imposteriser.canImposterise(ClassWithFinalToStringMethod.class)); - - try { - imposteriser.imposterise(new VoidAction(), ClassWithFinalToStringMethod.class); - fail("should have thrown IllegalArgumentException"); - } - catch (IllegalArgumentException expected) { - - } - } - - // ////////////////////////////////////// - - public interface EmptyInterface {} - - public interface AnInterface2 { - String foo(); - } - - // See issue JMOCK-145 - @Test @Disabled("fails with surefire on jdk-11, not with eclipse") //TODO[2112] jdk-11 issue? - void worksAroundBugInCglibWhenAskedToImposteriseObject() { - imposteriser.imposterise(new VoidAction(), Object.class); - imposteriser.imposterise(new VoidAction(), Object.class, EmptyInterface.class); - imposteriser.imposterise(new VoidAction(), Object.class, AnInterface2.class); - } - - // ////////////////////////////////////// - - // See issue JMOCK-256 (GitHub #36) - @Test @Disabled("fails with surefire on jdk-11, not with eclipse") //TODO[2112] jdk-11 issue? - void doesntDelegateFinalizeMethod() throws Exception { - Invokable failIfInvokedAction = invocation -> { - fail("invocation should not have happened"); - return null; - }; - - var imposter = imposteriser.imposterise(failIfInvokedAction, Object.class); - _Reflect.invokeMethodOn(Object.class.getDeclaredMethod("finalize"), imposter); - - } - -} diff --git a/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/JMockActionsTest_returnArgument.java b/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/JMockActionsTest_returnArgument.java deleted file mode 100644 index 36ac0fed2df..00000000000 --- a/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/JMockActionsTest_returnArgument.java +++ /dev/null @@ -1,66 +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.causeway.testing.unittestsupport.applib.jmocking; - -import org.jmock.Expectations; -import org.jmock.auto.Mock; -import org.junit.Rule; -import org.junit.Test; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; - -import org.apache.causeway.testing.unittestsupport.applib.jmocking.JUnitRuleMockery2.Mode; - -public class JMockActionsTest_returnArgument { - - @Rule - public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES); - - @Mock - private CollaboratorForReturnArgument collaborator; - - @Test - public void poke() { - context.checking(new Expectations() { - { - oneOf(collaborator).selectOneOf(with(any(Integer.class)), with(any(Integer.class)), with(any(Integer.class))); - will(JMockActions.returnArgument(1)); // ie the 2nd argument, which is '20' - } - }); - assertThat(new ClassUnderTestForReturnArgument(collaborator).addTo(4), is(24)); // adding 4 to the second argument - } - - public interface CollaboratorForReturnArgument { - public int selectOneOf(int x, int y, int z); - } - - public static class ClassUnderTestForReturnArgument { - private final CollaboratorForReturnArgument collaborator; - - private ClassUnderTestForReturnArgument(final CollaboratorForReturnArgument collaborator) { - this.collaborator = collaborator; - } - - public int addTo(int x) { - return x + collaborator.selectOneOf(10, 20, 30); - } - } - -} diff --git a/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/JMockActionsTest_returnEach.java b/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/JMockActionsTest_returnEach.java deleted file mode 100644 index bee4d1bb25a..00000000000 --- a/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/JMockActionsTest_returnEach.java +++ /dev/null @@ -1,68 +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.causeway.testing.unittestsupport.applib.jmocking; - -import org.jmock.Expectations; -import org.jmock.auto.Mock; -import org.junit.Rule; -import org.junit.Test; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; - -import org.apache.causeway.testing.unittestsupport.applib.jmocking.JUnitRuleMockery2.Mode; - -public class JMockActionsTest_returnEach { - - @Rule - public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES); - - @Mock - private CollaboratorForReturnEach collaborator; - - @Test - public void poke() { - context.checking(new Expectations() { - { - exactly(3).of(collaborator).readValue(); - will(JMockActions.returnEach(1,2,3)); - } - }); - assertThat(new ClassUnderTestForReturnEach(collaborator).prependAndRead("foo"), is("foo 1")); - assertThat(new ClassUnderTestForReturnEach(collaborator).prependAndRead("bar"), is("bar 2")); - assertThat(new ClassUnderTestForReturnEach(collaborator).prependAndRead("baz"), is("baz 3")); - } - - public interface CollaboratorForReturnEach { - public int readValue(); - } - - public static class ClassUnderTestForReturnEach { - private final CollaboratorForReturnEach collaborator; - - private ClassUnderTestForReturnEach(final CollaboratorForReturnEach collaborator) { - this.collaborator = collaborator; - } - - public String prependAndRead(String prepend) { - return prepend + " " + collaborator.readValue(); - } - } - -} diff --git a/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/JUnitRuleMockery2Test.java b/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/JUnitRuleMockery2Test.java deleted file mode 100644 index c9d66e3c097..00000000000 --- a/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/JUnitRuleMockery2Test.java +++ /dev/null @@ -1,45 +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.causeway.testing.unittestsupport.applib.jmocking; - -import org.jmock.Expectations; -import org.jmock.auto.Mock; -import org.junit.Rule; -import org.junit.Test; - -import org.apache.causeway.testing.unittestsupport.applib.jmocking.JUnitRuleMockery2.Mode; - -public class JUnitRuleMockery2Test { - - @Rule - public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES); - - @Mock - private Collaborator collaborator; - - @Test - public void poke() { - context.checking(new Expectations() { - { - oneOf(collaborator).doOtherStuff(); - } - }); - new CollaboratingUsingConstructorInjection(collaborator).collaborateWithCollaborator(); - } -} diff --git a/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/JUnitRuleMockery2Test_autoWiring_constructorInjection_happyCase.java b/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/JUnitRuleMockery2Test_autoWiring_constructorInjection_happyCase.java deleted file mode 100644 index d71d3d4d10a..00000000000 --- a/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/JUnitRuleMockery2Test_autoWiring_constructorInjection_happyCase.java +++ /dev/null @@ -1,55 +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.causeway.testing.unittestsupport.applib.jmocking; - -import org.jmock.auto.Mock; -import org.junit.Rule; -import org.junit.Test; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.not; -import static org.hamcrest.Matchers.nullValue; - -import org.apache.causeway.testing.unittestsupport.applib.jmocking.JUnitRuleMockery2.ClassUnderTest; -import org.apache.causeway.testing.unittestsupport.applib.jmocking.JUnitRuleMockery2.Mode; - -public class JUnitRuleMockery2Test_autoWiring_constructorInjection_happyCase { - - @Rule - public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES); - - @Mock - private Collaborator collaborator; - - @ClassUnderTest - private CollaboratingUsingConstructorInjection collaborating; - - // no longer necessary :-) - // @Before - // public void setUp() throws Exception { - // collaborating = (CollaboratingUsingConstructorInjection) context.getClassUnderTest(); - // } - - @Test - public void wiring() { - assertThat(collaborating.collaborator, is(not(nullValue()))); - } - -} diff --git a/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/JUnitRuleMockery2Test_autoWiring_sadCase_noClassUnderTest.java b/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/JUnitRuleMockery2Test_autoWiring_sadCase_noClassUnderTest.java deleted file mode 100644 index ac6e4a15067..00000000000 --- a/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/JUnitRuleMockery2Test_autoWiring_sadCase_noClassUnderTest.java +++ /dev/null @@ -1,44 +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.causeway.testing.unittestsupport.applib.jmocking; - -import org.jmock.auto.Mock; -import org.junit.Rule; -import org.junit.Test; - -import org.apache.causeway.testing.unittestsupport.applib.jmocking.JUnitRuleMockery2.Mode; - -public class JUnitRuleMockery2Test_autoWiring_sadCase_noClassUnderTest { - - @Rule - public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES); - - @Mock - private Collaborator collaborator; - - // @ClassUnderTest - @SuppressWarnings("unused") - private CollaboratingUsingConstructorInjection collaborating; - - @Test(expected=IllegalStateException.class) - public void cannotFindClassUnderTest() { - context.getClassUnderTest(); - } - -} diff --git a/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/JUnitRuleMockery2Test_autoWiring_sadCase_twoClassesUnderTest.java b/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/JUnitRuleMockery2Test_autoWiring_sadCase_twoClassesUnderTest.java deleted file mode 100644 index 11394391c22..00000000000 --- a/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/JUnitRuleMockery2Test_autoWiring_sadCase_twoClassesUnderTest.java +++ /dev/null @@ -1,49 +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.causeway.testing.unittestsupport.applib.jmocking; - -import org.jmock.auto.Mock; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; - -import org.apache.causeway.testing.unittestsupport.applib.jmocking.JUnitRuleMockery2.ClassUnderTest; -import org.apache.causeway.testing.unittestsupport.applib.jmocking.JUnitRuleMockery2.Mode; - -public class JUnitRuleMockery2Test_autoWiring_sadCase_twoClassesUnderTest { - - @Rule - public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES); - - @Mock - private Collaborator collaborator; - - @ClassUnderTest - private CollaboratingUsingConstructorInjection collaborating; - - @ClassUnderTest - private CollaboratingUsingConstructorInjection anotherCollaborating; - - @Ignore("This isn't actually possible to test, because the test is actually thrown by the rule, which is further up the callstack than the test method") - @Test(expected=AssertionError.class) - public void cannotFindClassUnderTest() { - context.getClassUnderTest(); - } - -} diff --git a/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/JUnitRuleMockery2Test_autoWiring_setterInjection_happyCase.java b/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/JUnitRuleMockery2Test_autoWiring_setterInjection_happyCase.java deleted file mode 100644 index fced9221309..00000000000 --- a/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/JUnitRuleMockery2Test_autoWiring_setterInjection_happyCase.java +++ /dev/null @@ -1,55 +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.causeway.testing.unittestsupport.applib.jmocking; - -import org.jmock.auto.Mock; -import org.junit.Rule; -import org.junit.Test; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.not; -import static org.hamcrest.Matchers.nullValue; - -import org.apache.causeway.testing.unittestsupport.applib.jmocking.JUnitRuleMockery2.ClassUnderTest; -import org.apache.causeway.testing.unittestsupport.applib.jmocking.JUnitRuleMockery2.Mode; - -public class JUnitRuleMockery2Test_autoWiring_setterInjection_happyCase { - - @Rule - public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES); - - @Mock - private Collaborator collaborator; - - @ClassUnderTest - private CollaboratingUsingSetterInjection collaborating; - - // no longer necessary :-) - // @Before - // public void setUp() throws Exception { - // collaborating = context.getClassUnderTest(); - // } - - @Test - public void wiring() { - assertThat(collaborating.collaborator, is(not(nullValue()))); - } - -} diff --git a/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/JUnitRuleMockery2Test_mockAnnotatedWithAllowing.java b/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/JUnitRuleMockery2Test_mockAnnotatedWithAllowing.java deleted file mode 100644 index 945cdc1a337..00000000000 --- a/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/JUnitRuleMockery2Test_mockAnnotatedWithAllowing.java +++ /dev/null @@ -1,57 +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.causeway.testing.unittestsupport.applib.jmocking; - -import org.jmock.auto.Mock; -import org.junit.Rule; -import org.junit.Test; - -import org.apache.causeway.testing.unittestsupport.applib.jmocking.JUnitRuleMockery2.Allowing; -import org.apache.causeway.testing.unittestsupport.applib.jmocking.JUnitRuleMockery2.ClassUnderTest; -import org.apache.causeway.testing.unittestsupport.applib.jmocking.JUnitRuleMockery2.Mode; - -public class JUnitRuleMockery2Test_mockAnnotatedWithAllowing { - - @Rule - public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES); - - @Allowing - @Mock - private Collaborator collaborator; - - @ClassUnderTest - private CollaboratingUsingConstructorInjection collaborating; - - // no longer necessary :-) - // @Before - // public void setUp() throws Exception { - // collaborating = (CollaboratingUsingConstructorInjection) context.getClassUnderTest(); - // } - - @Test - public void invocationOnCollaboratorIsIgnored() { - collaborating.collaborateWithCollaborator(); - } - - @Test - public void lackOfInvocationOnCollaboratorIsIgnored() { - collaborating.dontCollaborateWithCollaborator(); - } - -} diff --git a/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/JUnitRuleMockery2Test_mockAnnotatedWithIgnoring.java b/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/JUnitRuleMockery2Test_mockAnnotatedWithIgnoring.java deleted file mode 100644 index 1637f82503b..00000000000 --- a/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/JUnitRuleMockery2Test_mockAnnotatedWithIgnoring.java +++ /dev/null @@ -1,57 +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.causeway.testing.unittestsupport.applib.jmocking; - -import org.jmock.auto.Mock; -import org.junit.Rule; -import org.junit.Test; - -import org.apache.causeway.testing.unittestsupport.applib.jmocking.JUnitRuleMockery2.ClassUnderTest; -import org.apache.causeway.testing.unittestsupport.applib.jmocking.JUnitRuleMockery2.Ignoring; -import org.apache.causeway.testing.unittestsupport.applib.jmocking.JUnitRuleMockery2.Mode; - -public class JUnitRuleMockery2Test_mockAnnotatedWithIgnoring { - - @Rule - public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES); - - @Ignoring - @Mock - private Collaborator collaborator; - - @ClassUnderTest - private CollaboratingUsingConstructorInjection collaborating; - - // no longer necessary :-) - // @Before - // public void setUp() throws Exception { - // collaborating = context.getClassUnderTest(); - // } - - @Test - public void invocationOnCollaboratorIsIgnored() { - collaborating.collaborateWithCollaborator(); - } - - @Test - public void lackOfInvocationOnCollaboratorIsIgnored() { - collaborating.dontCollaborateWithCollaborator(); - } - -} diff --git a/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/JUnitRuleMockery2Test_mockAnnotatedWithNever_happyCase.java b/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/JUnitRuleMockery2Test_mockAnnotatedWithNever_happyCase.java deleted file mode 100644 index eea0b309364..00000000000 --- a/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/JUnitRuleMockery2Test_mockAnnotatedWithNever_happyCase.java +++ /dev/null @@ -1,52 +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.causeway.testing.unittestsupport.applib.jmocking; - -import org.jmock.auto.Mock; -import org.junit.Rule; -import org.junit.Test; - -import org.apache.causeway.testing.unittestsupport.applib.jmocking.JUnitRuleMockery2.ClassUnderTest; -import org.apache.causeway.testing.unittestsupport.applib.jmocking.JUnitRuleMockery2.Mode; -import org.apache.causeway.testing.unittestsupport.applib.jmocking.JUnitRuleMockery2.Never; - -public class JUnitRuleMockery2Test_mockAnnotatedWithNever_happyCase { - - @Rule - public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES); - - @Never - @Mock - private Collaborator collaborator; - - @ClassUnderTest - private CollaboratingUsingConstructorInjection collaborating; - - // no longer necessary :-) - // @Before - // public void setUp() throws Exception { - // collaborating = (CollaboratingUsingConstructorInjection) context.getClassUnderTest(); - // } - - @Test - public void invocationOnCollaboratorIsIgnored() { - collaborating.dontCollaborateWithCollaborator(); - } - -} diff --git a/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/JUnitRuleMockery2Test_mockAnnotatedWithNever_sadCase.java b/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/JUnitRuleMockery2Test_mockAnnotatedWithNever_sadCase.java deleted file mode 100644 index 78870d16c46..00000000000 --- a/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/JUnitRuleMockery2Test_mockAnnotatedWithNever_sadCase.java +++ /dev/null @@ -1,57 +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.causeway.testing.unittestsupport.applib.jmocking; - -import org.jmock.auto.Mock; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -import org.apache.causeway.testing.unittestsupport.applib.jmocking.JUnitRuleMockery2.ClassUnderTest; -import org.apache.causeway.testing.unittestsupport.applib.jmocking.JUnitRuleMockery2.Mode; -import org.apache.causeway.testing.unittestsupport.applib.jmocking.JUnitRuleMockery2.Never; - -public class JUnitRuleMockery2Test_mockAnnotatedWithNever_sadCase { - - @Rule - public ExpectedException exp = ExpectedException.none(); - - @Rule - public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES); - - @Never - @Mock - private Collaborator collaborator; - - @ClassUnderTest - private CollaboratingUsingConstructorInjection collaborating; - - // no longer necessary :-) - // @Before - // public void setUp() throws Exception { - // collaborating = context.getClassUnderTest(); - // } - - @Test - public void invocationOnCollaboratorIsIgnored() { - exp.expect(AssertionError.class); - collaborating.collaborateWithCollaborator(); - } - -} diff --git a/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/JUnitRuleMockery2Test_mockAnnotatedWithOne_happyCase.java b/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/JUnitRuleMockery2Test_mockAnnotatedWithOne_happyCase.java deleted file mode 100644 index 7762aab71fc..00000000000 --- a/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/JUnitRuleMockery2Test_mockAnnotatedWithOne_happyCase.java +++ /dev/null @@ -1,52 +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.causeway.testing.unittestsupport.applib.jmocking; - -import org.jmock.auto.Mock; -import org.junit.Rule; -import org.junit.Test; - -import org.apache.causeway.testing.unittestsupport.applib.jmocking.JUnitRuleMockery2.ClassUnderTest; -import org.apache.causeway.testing.unittestsupport.applib.jmocking.JUnitRuleMockery2.Mode; -import org.apache.causeway.testing.unittestsupport.applib.jmocking.JUnitRuleMockery2.One; - -public class JUnitRuleMockery2Test_mockAnnotatedWithOne_happyCase { - - @Rule - public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES); - - @One - @Mock - private Collaborator collaborator; - - @ClassUnderTest - private CollaboratingUsingConstructorInjection collaborating; - - // no longer necessary :-) - // @Before - // public void setUp() throws Exception { - // collaborating = (CollaboratingUsingConstructorInjection) context.getClassUnderTest(); - // } - - @Test - public void invocationOnCollaboratorIsIgnored() { - collaborating.collaborateWithCollaborator(); - } - -} diff --git a/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/JUnitRuleMockery2Test_mockAnnotatedWithOne_sadCase.java b/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/JUnitRuleMockery2Test_mockAnnotatedWithOne_sadCase.java deleted file mode 100644 index 47b9a6995fc..00000000000 --- a/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/jmocking/JUnitRuleMockery2Test_mockAnnotatedWithOne_sadCase.java +++ /dev/null @@ -1,53 +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.causeway.testing.unittestsupport.applib.jmocking; - -import org.jmock.auto.Mock; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; - -import org.apache.causeway.testing.unittestsupport.applib.jmocking.JUnitRuleMockery2.ClassUnderTest; -import org.apache.causeway.testing.unittestsupport.applib.jmocking.JUnitRuleMockery2.Mode; -import org.apache.causeway.testing.unittestsupport.applib.jmocking.JUnitRuleMockery2.One; - -public class JUnitRuleMockery2Test_mockAnnotatedWithOne_sadCase { - - @Rule - public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES); - - @One - @Mock - private Collaborator collaborator; - - @ClassUnderTest - private CollaboratingUsingConstructorInjection collaborating; - - // no longer necessary :-) - // @Before - // public void setUp() throws Exception { - // collaborating = (CollaboratingUsingConstructorInjection) context.getClassUnderTest(); - // } - - @Ignore("This isn't actually possible to test, because the test is actually thrown by the rule, which is further up the callstack than the test method") @Test(expected=AssertionError.class) - public void invocationOnCollaboratorIsIgnored() { - collaborating.dontCollaborateWithCollaborator(); - } - -} diff --git a/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/util/Files_deleteFileUtils_Test.java b/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/util/Files_deleteFileUtils_Test.java index 3db657e9294..9d61faf5d1e 100644 --- a/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/util/Files_deleteFileUtils_Test.java +++ b/testing/unittestsupport/applib/src/test/java/org/apache/causeway/testing/unittestsupport/applib/util/Files_deleteFileUtils_Test.java @@ -21,62 +21,51 @@ package org.apache.causeway.testing.unittestsupport.applib.util; import java.io.File; import java.io.IOException; -import org.hamcrest.Description; -import org.hamcrest.Matcher; -import org.hamcrest.TypeSafeMatcher; -import org.jmock.Expectations; import org.jmock.auto.Mock; -import org.junit.Rule; -import org.junit.Test; -import org.apache.causeway.testing.unittestsupport.applib.jmocking.JUnitRuleMockery2; - -public class Files_deleteFileUtils_Test { - - @Rule - public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(JUnitRuleMockery2.Mode.INTERFACES_AND_CLASSES); +class Files_deleteFileUtils_Test { @Mock private FileUtils.Deleter deleter; - @Test + //@Test public void test() throws IOException { final File cusIdxFile = new File("xml/objects/CUS.xml").getAbsoluteFile(); final File cus1File = new File("xml/objects/CUS/1.xml").getAbsoluteFile(); final File cus2File = new File("xml/objects/CUS/2.xml").getAbsoluteFile(); - context.checking(new Expectations() { - { - oneOf(deleter).deleteFile(with(equalsFile(cusIdxFile))); - oneOf(deleter).deleteFile(with(equalsFile(cus1File))); - oneOf(deleter).deleteFile(with(equalsFile(cus2File))); - } - }); +// context.checking(new Expectations() { +// { +// oneOf(deleter).deleteFile(with(equalsFile(cusIdxFile))); +// oneOf(deleter).deleteFile(with(equalsFile(cus1File))); +// oneOf(deleter).deleteFile(with(equalsFile(cus2File))); +// } +// }); FileUtils.deleteFiles( - new File("xml/objects").getAbsoluteFile(), + new File("xml/objects").getAbsoluteFile(), FileUtils.filterFileNameExtension(".xml"), FileUtils.Recursion.DO_RECURSE, deleter); } - private static Matcher<File> equalsFile(final File file) throws IOException { - final String canonicalPath = file.getCanonicalPath(); - return new TypeSafeMatcher<File>() { - - @Override - public void describeTo(Description arg0) { - arg0.appendText("file '" + canonicalPath + "'"); - } - - @Override - public boolean matchesSafely(File arg0) { - try { - return arg0.getCanonicalPath().equals(canonicalPath); - } catch (IOException e) { - return false; - } - } - }; - } +// private static Matcher<File> equalsFile(final File file) throws IOException { +// final String canonicalPath = file.getCanonicalPath(); +// return new TypeSafeMatcher<File>() { +// +// @Override +// public void describeTo(final Description arg0) { +// arg0.appendText("file '" + canonicalPath + "'"); +// } +// +// @Override +// public boolean matchesSafely(final File arg0) { +// try { +// return arg0.getCanonicalPath().equals(canonicalPath); +// } catch (IOException e) { +// return false; +// } +// } +// }; +// } }