Added MessageRegistryTest for method reference usage
Change-Id: I3c9bbbf3af89a67e51f908355f36d055c8dd64c3
Signed-off-by: Dirk Fauth <dirk.fauth@googlemail.com>
diff --git a/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/nls/BundleMessages.java b/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/nls/BundleMessages.java
index 4fdc34f..1b48693 100644
--- a/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/nls/BundleMessages.java
+++ b/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/nls/BundleMessages.java
@@ -38,4 +38,8 @@
public void format() {
messageFour = MessageFormat.format(messageFour, "Tom"); //$NON-NLS-1$
}
+
+ public String getMessage() {
+ return message;
+ }
}
diff --git a/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/nls/MessageRegistryTest.java b/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/nls/MessageRegistryTest.java
index bb17525..f42f39e 100644
--- a/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/nls/MessageRegistryTest.java
+++ b/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/nls/MessageRegistryTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2014, 2015 Dirk Fauth and others.
+ * Copyright (c) 2014, 2020 Dirk Fauth and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -90,6 +90,22 @@
}
@Test
+ public void testRegisterLocalizationByMethodReference() {
+ // ensure the en Locale is set for this test
+ this.context.set(TranslationService.LOCALE, Locale.ENGLISH);
+ TestObject o = ContextInjectionFactory.make(TestObject.class, this.context);
+
+ TestLocalizableObject control = new TestLocalizableObject();
+ o.registry.register(control::setLocalizableValue, (m) -> m.message);
+
+ // test value is set
+ assertNotNull(control.getLocalizableValue());
+
+ // test the set value
+ assertEquals("BundleMessage", control.getLocalizableValue());
+ }
+
+ @Test
public void testRegisterLocalizationByPropertyAndChangeLocale() {
// ensure the en Locale is set for this test
this.context.set(TranslationService.LOCALE, Locale.ENGLISH);
@@ -131,5 +147,24 @@
assertEquals("BundleNachricht", control.getLocalizableValue());
}
- // TODO add testcases for Java 8 method references
+ @Test
+ public void testRegisterLocalizationByMethodReferenceAndChangeLocale() {
+ // ensure the en Locale is set for this test
+ this.context.set(TranslationService.LOCALE, Locale.ENGLISH);
+ TestObject o = ContextInjectionFactory.make(TestObject.class, this.context);
+
+ TestLocalizableObject control = new TestLocalizableObject();
+ o.registry.register(control::setLocalizableValue, BundleMessages::getMessage);
+
+ // test value is set
+ assertNotNull(control.getLocalizableValue());
+
+ // test the set value
+ assertEquals("BundleMessage", control.getLocalizableValue());
+
+ // change the locale to GERMAN
+ this.context.set(TranslationService.LOCALE, Locale.GERMAN);
+
+ assertEquals("BundleNachricht", control.getLocalizableValue());
+ }
}