This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git


The following commit(s) were added to refs/heads/master by this push:
     new bdb6e53d3a ISIS-2994: test fixes
bdb6e53d3a is described below

commit bdb6e53d3a9307dab394709fd57183db9ea1c75f
Author: Andi Huber <[email protected]>
AuthorDate: Thu Apr 7 14:41:57 2022 +0200

    ISIS-2994: test fixes
---
 ...ionOrAnyMatchingValueSemanticsFacetFactory.java |  3 ++
 .../metamodel/services/grid/GridLoadingTest.java   | 13 +++---
 .../menubars/bootstrap/MenuBarsServiceBS3Test.java | 13 +++---
 .../JsonValueEncoderTest_asAdapter.java            | 48 +++++++++++++++++-----
 4 files changed, 53 insertions(+), 24 deletions(-)

diff --git 
a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/value/annotcfg/ValueFacetForValueAnnotationOrAnyMatchingValueSemanticsFacetFactory.java
 
b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/value/annotcfg/ValueFacetForValueAnnotationOrAnyMatchingValueSemanticsFacetFactory.java
index 38c8c3b416..8bd3d4fe27 100644
--- 
a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/value/annotcfg/ValueFacetForValueAnnotationOrAnyMatchingValueSemanticsFacetFactory.java
+++ 
b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/value/annotcfg/ValueFacetForValueAnnotationOrAnyMatchingValueSemanticsFacetFactory.java
@@ -110,6 +110,9 @@ extends FacetFactoryAbstract {
             if(valueIfAny.isPresent()) {
                 log.warn("could not find a ValueSemanticsProvider for value 
type {}; "
                         + "the type was found to be annotated with @Value", 
valueClass);
+                // fall through, so gets a ValueFacet
+            } else {
+                return;
             }
         } else {
             log.debug("found {} ValueSemanticsProvider(s) for value type {}", 
semanticsProviders.size(), valueClass);
diff --git 
a/core/metamodel/src/test/java/org/apache/isis/core/metamodel/services/grid/GridLoadingTest.java
 
b/core/metamodel/src/test/java/org/apache/isis/core/metamodel/services/grid/GridLoadingTest.java
index 623cbcdf5e..595e0614cb 100644
--- 
a/core/metamodel/src/test/java/org/apache/isis/core/metamodel/services/grid/GridLoadingTest.java
+++ 
b/core/metamodel/src/test/java/org/apache/isis/core/metamodel/services/grid/GridLoadingTest.java
@@ -21,6 +21,11 @@ package org.apache.isis.core.metamodel.services.grid;
 import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
 
+import static org.junit.Assert.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+
 import org.apache.isis.applib.services.grid.GridLoaderService;
 import org.apache.isis.applib.services.layout.LayoutService;
 import org.apache.isis.applib.services.layout.Style;
@@ -30,11 +35,6 @@ import 
org.apache.isis.core.metamodel.facets.all.named.MemberNamedFacet;
 import org.apache.isis.core.metamodel.facets.object.grid.GridFacet;
 import org.apache.isis.core.metamodel.spec.ManagedObject;
 
-import static org.junit.Assert.assertNotSame;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertSame;
-
 import lombok.val;
 
 class GridLoadingTest
@@ -46,7 +46,8 @@ extends MetaModelTestAbstract {
     @Override
     protected void afterSetUp() {
         layoutService = 
getServiceRegistry().lookupServiceElseFail(LayoutService.class);
-        gridLoaderService = 
(GridLoaderServiceDefault)getServiceRegistry().lookupServiceElseFail(GridLoaderService.class);
+        gridLoaderService = (GridLoaderServiceDefault)getServiceRegistry()
+                .lookupServiceElseFail(GridLoaderService.class);
     }
 
     @Test @Disabled("just a blueprint")
diff --git 
a/core/runtimeservices/src/test/java/org/apache/isis/core/runtimeservices/menubars/bootstrap/MenuBarsServiceBS3Test.java
 
b/core/runtimeservices/src/test/java/org/apache/isis/core/runtimeservices/menubars/bootstrap/MenuBarsServiceBS3Test.java
index 0bf3eb2421..729e6c9cb3 100644
--- 
a/core/runtimeservices/src/test/java/org/apache/isis/core/runtimeservices/menubars/bootstrap/MenuBarsServiceBS3Test.java
+++ 
b/core/runtimeservices/src/test/java/org/apache/isis/core/runtimeservices/menubars/bootstrap/MenuBarsServiceBS3Test.java
@@ -23,6 +23,11 @@ import java.nio.charset.StandardCharsets;
 import org.junit.jupiter.api.Test;
 import org.springframework.core.io.ByteArrayResource;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
 import org.apache.isis.applib.services.layout.LayoutService;
 import org.apache.isis.applib.services.menu.MenuBarsLoaderService;
 import org.apache.isis.applib.services.menu.MenuBarsService;
@@ -31,12 +36,6 @@ import 
org.apache.isis.core.metamodel.facetapi.Facet.Precedence;
 import org.apache.isis.core.metamodel.facets.all.named.MemberNamedFacet;
 import org.apache.isis.core.runtimeservices.RuntimeServicesTestAbstract;
 import 
org.apache.isis.core.runtimeservices.menubars.MenuBarsLoaderServiceDefault;
-import 
org.apache.isis.core.runtimeservices.menubars.bootstrap.MenuBarsServiceBS;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertSame;
-import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import lombok.val;
 
@@ -48,7 +47,7 @@ extends RuntimeServicesTestAbstract {
     private LayoutService layoutService;
 
     @Override
-    protected void onSetUp(MetaModelContext_forTestingBuilder mmcBuilder) {
+    protected void onSetUp(final MetaModelContext_forTestingBuilder 
mmcBuilder) {
         mmcBuilder.singleton(new Bar()); // install the menu-entry 
contributing domain service
     }
 
diff --git 
a/viewers/restfulobjects/rendering/src/test/java/org/apache/isis/viewer/restfulobjects/rendering/domainobjects/JsonValueEncoderTest_asAdapter.java
 
b/viewers/restfulobjects/rendering/src/test/java/org/apache/isis/viewer/restfulobjects/rendering/domainobjects/JsonValueEncoderTest_asAdapter.java
index 76f1acd7b9..99d2f4881d 100644
--- 
a/viewers/restfulobjects/rendering/src/test/java/org/apache/isis/viewer/restfulobjects/rendering/domainobjects/JsonValueEncoderTest_asAdapter.java
+++ 
b/viewers/restfulobjects/rendering/src/test/java/org/apache/isis/viewer/restfulobjects/rendering/domainobjects/JsonValueEncoderTest_asAdapter.java
@@ -124,7 +124,7 @@ public class JsonValueEncoderTest_asAdapter {
 
     private void whenReprIsBoolean(final Class<?> correspondingClass) {
         // given
-        allowingObjectSpecHas(ValueFacet.class, mockValueFacet);
+        allowingObjectSpecHasValue(correspondingClass);
         
allowingObjectSpecCorrespondingClassAndObjectTypeIs(correspondingClass);
         final boolean value = true;
         representation = new JsonRepresentation(BooleanNode.valueOf(value));
@@ -145,7 +145,7 @@ public class JsonValueEncoderTest_asAdapter {
     @Test(expected = IllegalArgumentException.class)
     public void whenObjectSpecIsBooleanButReprIsNot() throws Exception {
         // given
-        allowingObjectSpecHas(ValueFacet.class, mockValueFacet);
+        allowingObjectSpecHasValue(boolean.class);
         allowingObjectSpecCorrespondingClassAndObjectTypeIs(boolean.class);
 
         context.checking(new Expectations() {
@@ -171,7 +171,7 @@ public class JsonValueEncoderTest_asAdapter {
 
     private void whenReprIsInteger(final Class<?> correspondingClass) {
         // given
-        allowingObjectSpecHas(ValueFacet.class, mockValueFacet);
+        allowingObjectSpecHasValue(correspondingClass);
         
allowingObjectSpecCorrespondingClassAndObjectTypeIs(correspondingClass);
         final int value = 123;
         representation = new JsonRepresentation(IntNode.valueOf(value));
@@ -213,7 +213,7 @@ public class JsonValueEncoderTest_asAdapter {
 
     private void whenReprIsLong(final Class<?> correspondingClass) {
         // given
-        allowingObjectSpecHas(ValueFacet.class, mockValueFacet);
+        allowingObjectSpecHasValue(correspondingClass);
         
allowingObjectSpecCorrespondingClassAndObjectTypeIs(correspondingClass);
         final long value = 1234567890L;
         representation = new JsonRepresentation(LongNode.valueOf(value));
@@ -234,7 +234,7 @@ public class JsonValueEncoderTest_asAdapter {
     @Test(expected = IllegalArgumentException.class)
     public void whenObjectSpecIsLongButReprIsNot() throws Exception {
         // given
-        allowingObjectSpecHas(ValueFacet.class, mockValueFacet);
+        allowingObjectSpecHasValue(long.class);
         allowingObjectSpecCorrespondingClassAndObjectTypeIs(long.class);
 
         context.checking(new Expectations() {
@@ -260,7 +260,7 @@ public class JsonValueEncoderTest_asAdapter {
 
     private void whenReprIsDouble(final Class<?> correspondingClass) {
         // given
-        allowingObjectSpecHas(ValueFacet.class, mockValueFacet);
+        allowingObjectSpecHasValue(correspondingClass);
         
allowingObjectSpecCorrespondingClassAndObjectTypeIs(correspondingClass);
         final double value = 123.45;
         representation = new JsonRepresentation(DoubleNode.valueOf(value));
@@ -293,7 +293,7 @@ public class JsonValueEncoderTest_asAdapter {
     @Test
     public void whenReprIsBigInteger() throws Exception {
         // given
-        allowingObjectSpecHas(ValueFacet.class, mockValueFacet);
+        allowingObjectSpecHasValue(BigInteger.class);
         allowingObjectSpecCorrespondingClassAndObjectTypeIs(BigInteger.class);
         final BigInteger value = BigInteger.valueOf(123);
         representation = new JsonRepresentation(BigIntegerNode.valueOf(value));
@@ -326,7 +326,7 @@ public class JsonValueEncoderTest_asAdapter {
     @Test
     public void whenReprIsBigDecimal() throws Exception {
         // given
-        allowingObjectSpecHas(ValueFacet.class, mockValueFacet);
+        allowingObjectSpecHasValue(BigDecimal.class);
         allowingObjectSpecCorrespondingClassAndObjectTypeIs(BigDecimal.class);
         final BigDecimal value = new BigDecimal("123234234.45612312343535");
         representation = new JsonRepresentation(DecimalNode.valueOf(value));
@@ -334,6 +334,7 @@ public class JsonValueEncoderTest_asAdapter {
             {
                 oneOf(specLoader).specForType(value.getClass());
                 will(returnValue(Optional.of(mockObjectSpec)));
+
             }
         });
 
@@ -359,7 +360,7 @@ public class JsonValueEncoderTest_asAdapter {
     @Test
     public void whenReprIsString() throws Exception {
         // given
-        allowingObjectSpecHas(ValueFacet.class, mockValueFacet);
+        allowingObjectSpecHasValue(String.class);
         allowingObjectSpecCorrespondingClassAndObjectTypeIs(String.class);
         representation = new JsonRepresentation(TextNode.valueOf("aString"));
 
@@ -377,11 +378,36 @@ public class JsonValueEncoderTest_asAdapter {
         assertSame(mockObjectSpec, adapter.getSpecification());
     }
 
-    private <T extends Facet> void allowingObjectSpecHas(final Class<T> 
facetClass, final T encodableFacet) {
+
+
+    private void allowingObjectSpecHasValue(final Class<?> valueClass) {
+        context.checking(new Expectations() {
+            {
+                allowing(mockObjectSpec).getFacet(ValueFacet.class);
+                will(returnValue(mockValueFacet));
+
+                allowing(mockObjectSpec).lookupFacet(ValueFacet.class);
+                will(returnValue(Optional.of(mockValueFacet)));
+
+                allowing(mockValueFacet).getValueClass();
+                will(returnValue(valueClass));
+
+            }
+        });
+    }
+
+    private <T extends Facet> void allowingObjectSpecHas(final Class<T> 
facetClass, final T facet) {
         context.checking(new Expectations() {
             {
                 allowing(mockObjectSpec).getFacet(facetClass);
-                will(returnValue(encodableFacet));
+                will(returnValue(facet));
+
+                allowing(mockObjectSpec).lookupFacet(facetClass);
+                will(returnValue(Optional.ofNullable(facet)));
+
+                allowing(mockObjectSpec).getCorrespondingClass();
+                will(returnValue(mockObjectSpec.getClass())); // used only for 
illegal argument exception message
+
             }
         });
     }

Reply via email to