You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2018/10/28 14:15:24 UTC

[isis] branch v2 updated: ISIS-1277: fixes translation service tests (regression)

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

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


The following commit(s) were added to refs/heads/v2 by this push:
     new f7343ef  ISIS-1277: fixes translation service tests (regression)
f7343ef is described below

commit f7343eff04d912bf7ed571ee15e1531151ac4afb
Author: Andi Huber <ah...@apache.org>
AuthorDate: Sun Oct 28 15:15:17 2018 +0100

    ISIS-1277: fixes translation service tests (regression)
    
    With update of byte-buddy 1.8.0 -> 1.9.2, Apache Isis runs on JDK 11+,
    but we also use byte-buddy with 'untittestsupport' for mockery.
    
    It seems the newer version either no longer supports mockery of non
    public methods or requires some additional setup.
---
 .../ImposteriserTestUsingCodegenPlugin.java        | 44 +++++++++++++++++-----
 .../services/i18n/po/TranslationServicePo.java     |  4 +-
 .../runtime/services/i18n/po/PoReaderTest.java     | 27 ++++++++-----
 3 files changed, 55 insertions(+), 20 deletions(-)

diff --git a/core/detached-tests/src/test/java/org/apache/isis/core/unittestsupport/jmocking/ImposteriserTestUsingCodegenPlugin.java b/core/detached-tests/src/test/java/org/apache/isis/core/unittestsupport/jmocking/ImposteriserTestUsingCodegenPlugin.java
index 51955d1..7c99042 100644
--- a/core/detached-tests/src/test/java/org/apache/isis/core/unittestsupport/jmocking/ImposteriserTestUsingCodegenPlugin.java
+++ b/core/detached-tests/src/test/java/org/apache/isis/core/unittestsupport/jmocking/ImposteriserTestUsingCodegenPlugin.java
@@ -18,12 +18,6 @@
  */
 package org.apache.isis.core.unittestsupport.jmocking;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
 import java.io.File;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
@@ -32,17 +26,28 @@ import java.net.URL;
 import java.net.URLClassLoader;
 import java.util.Date;
 
-import org.apache.isis.commons.internal.context._Context;
-import org.apache.isis.core.plugins.codegen.ProxyFactoryPlugin;
+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.After;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
+import org.apache.isis.applib.services.i18n.TranslationsResolver;
+import org.apache.isis.commons.internal.context._Context;
+import org.apache.isis.core.plugins.codegen.ProxyFactoryPlugin;
+import org.apache.isis.core.runtime.services.i18n.po.TranslationServicePo;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
 public class ImposteriserTestUsingCodegenPlugin {
 
     private Imposteriser imposteriser = Imposterisers.getDefault();
@@ -93,7 +98,28 @@ public class ImposteriserTestUsingCodegenPlugin {
         assertNotNull(imposter);
         imposter.toString();
     }
-
+    
+    @Test
+    public void imposteriserShouldBeUsableForMockery() {
+        
+        final JUnit4Mockery context = new JUnit4Mockery() {
+            {
+                setImposteriser(imposteriser);
+            }
+        };
+        
+        // using TranslationService here is just arbitrary, can be replaced any time ...
+        final TranslationServicePo mockTranslationServicePo = context.mock(TranslationServicePo.class);
+        final TranslationsResolver mockTranslationsResolver = context.mock(TranslationsResolver.class);
+        
+        context.checking(new Expectations() {{
+            allowing(mockTranslationServicePo).getTranslationsResolver();
+            will(returnValue(mockTranslationsResolver));
+        }});
+        
+        Assert.assertNotNull(mockTranslationServicePo);
+        Assert.assertNotNull(mockTranslationServicePo.getTranslationsResolver());
+    }
 
     // //////////////////////////////////////
 
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/i18n/po/TranslationServicePo.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/i18n/po/TranslationServicePo.java
index e4480f9..48b8db0 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/i18n/po/TranslationServicePo.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/i18n/po/TranslationServicePo.java
@@ -184,7 +184,7 @@ public class TranslationServicePo implements TranslationService {
     private TranslationsResolver translationsResolver;
 
     @Programmatic
-    TranslationsResolver getTranslationsResolver() {
+    public TranslationsResolver getTranslationsResolver() {
         return translationsResolver;
     }
 
@@ -192,7 +192,7 @@ public class TranslationServicePo implements TranslationService {
     private LocaleProvider localeProvider;
 
     @Programmatic
-    LocaleProvider getLocaleProvider() {
+    public LocaleProvider getLocaleProvider() {
         return localeProvider;
     }
 
diff --git a/core/runtime/src/test/java/org/apache/isis/core/runtime/services/i18n/po/PoReaderTest.java b/core/runtime/src/test/java/org/apache/isis/core/runtime/services/i18n/po/PoReaderTest.java
index bdd20d2..093bde5 100644
--- a/core/runtime/src/test/java/org/apache/isis/core/runtime/services/i18n/po/PoReaderTest.java
+++ b/core/runtime/src/test/java/org/apache/isis/core/runtime/services/i18n/po/PoReaderTest.java
@@ -20,14 +20,17 @@ package org.apache.isis.core.runtime.services.i18n.po;
 
 import java.util.List;
 import java.util.Locale;
-import org.apache.isis.commons.internal.collections._Lists;
+
 import org.jmock.Expectations;
 import org.jmock.auto.Mock;
+import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
+
 import org.apache.isis.applib.services.i18n.LocaleProvider;
 import org.apache.isis.applib.services.i18n.TranslationsResolver;
+import org.apache.isis.commons.internal.collections._Lists;
 import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2;
 
 import static org.hamcrest.CoreMatchers.equalTo;
@@ -36,20 +39,18 @@ import static org.junit.Assert.assertThat;
 
 public class PoReaderTest {
 
-    @Rule
-    public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(JUnitRuleMockery2.Mode.INTERFACES_AND_CLASSES);
+    @Rule public JUnitRuleMockery2 context = JUnitRuleMockery2
+            .createFor(JUnitRuleMockery2.Mode.INTERFACES_AND_CLASSES);
 
-    @Mock
-    TranslationServicePo mockTranslationServicePo;
-    @Mock
-    TranslationsResolver mockTranslationsResolver;
-    @Mock
-    LocaleProvider mockLocaleProvider;
+    @Mock TranslationServicePo mockTranslationServicePo;
+    @Mock TranslationsResolver mockTranslationsResolver;
+    @Mock LocaleProvider mockLocaleProvider;
 
     PoReader poReader;
 
     @Before
     public void setUp() throws Exception {
+        
         context.checking(new Expectations() {{
             allowing(mockTranslationServicePo).getLocaleProvider();
             will(returnValue(mockLocaleProvider));
@@ -60,6 +61,14 @@ public class PoReaderTest {
             allowing(mockLocaleProvider).getLocale();
             will(returnValue(Locale.UK));
         }});
+        
+        //[ahuber] with update of byte-buddy 1.8.0 -> 1.9.2, Apache Isis runs on JDK 11+, but
+        // it seems to no longer support mockery of non public methods, so we 
+        // explicitly test proper mockery here ...  
+        Assert.assertNotNull(mockTranslationServicePo.getLocaleProvider());
+        Assert.assertNotNull(mockTranslationServicePo.getTranslationsResolver());
+        Assert.assertNotNull(mockLocaleProvider.getLocale());
+        
     }
 
     public static class Translate extends PoReaderTest {