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/01/22 08:18:58 UTC
[isis] branch master updated: ISIS-1842 add missing generic type
arguments + add missing test cases
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 44d6331 ISIS-1842 add missing generic type arguments + add missing test cases
44d6331 is described below
commit 44d6331b2e023ad5f38214ad3d0b2590b002be64
Author: Andi Huber <ah...@apache.org>
AuthorDate: Mon Jan 22 09:18:56 2018 +0100
ISIS-1842 add missing generic type arguments + add missing test cases
---
.../applib/fixturescripts/ExecutionParameters.java | 40 +++++++++++++---------
.../fixturescripts/ExecutionParameters_Test.java | 37 ++++++++++++++++++++
2 files changed, 61 insertions(+), 16 deletions(-)
diff --git a/core/applib/src/main/java/org/apache/isis/applib/fixturescripts/ExecutionParameters.java b/core/applib/src/main/java/org/apache/isis/applib/fixturescripts/ExecutionParameters.java
index 82e4574..8a5fc89 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/fixturescripts/ExecutionParameters.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/fixturescripts/ExecutionParameters.java
@@ -29,6 +29,8 @@ import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Maps;
import com.google.common.io.CharSource;
+
+import org.apache.isis.applib.util.Casts;
import org.joda.time.DateTime;
import org.joda.time.LocalDate;
import org.joda.time.LocalDateTime;
@@ -76,36 +78,42 @@ public class ExecutionParameters {
}
public <T> T getParameterAsT(final String parameterName, final Class<T> cls) {
- T value = null;
+ return Casts.uncheckedCast(getParameterAsObject(parameterName, cls));
+ }
+
+ protected Object getParameterAsObject(final String parameterName, final Class<?> cls) {
+ final Object value;
if (Enum.class.isAssignableFrom(cls)) {
- Class enumClass = cls;
- value = (T) getParameterAsEnum(parameterName, enumClass);
+ Class<?> enumClass = cls;
+ value = getParameterAsEnum(parameterName, Casts.uncheckedCast(enumClass));
} else if (cls == Boolean.class) {
- value = (T) getParameterAsBoolean(parameterName);
+ value = getParameterAsBoolean(parameterName);
} else if (cls == Byte.class) {
- value = (T) getParameterAsByte(parameterName);
+ value = getParameterAsByte(parameterName);
} else if (cls == Short.class) {
- value = (T) getParameterAsShort(parameterName);
+ value = getParameterAsShort(parameterName);
} else if (cls == Integer.class) {
- value = (T) getParameterAsInteger(parameterName);
+ value = getParameterAsInteger(parameterName);
} else if (cls == Long.class) {
- value = (T) getParameterAsLong(parameterName);
+ value = getParameterAsLong(parameterName);
} else if (cls == Float.class) {
- value = (T) getParameterAsFloat(parameterName);
+ value = getParameterAsFloat(parameterName);
} else if (cls == Double.class) {
- value = (T) getParameterAsDouble(parameterName);
+ value = getParameterAsDouble(parameterName);
} else if (cls == Character.class) {
- value = (T) getParameterAsCharacter(parameterName);
+ value = getParameterAsCharacter(parameterName);
} else if (cls == BigDecimal.class) {
- value = (T) getParameterAsBigDecimal(parameterName);
+ value = getParameterAsBigDecimal(parameterName);
} else if (cls == BigInteger.class) {
- value = (T) getParameterAsBigInteger(parameterName);
+ value = getParameterAsBigInteger(parameterName);
} else if (cls == LocalDate.class) {
- value = (T) getParameterAsLocalDate(parameterName);
+ value = getParameterAsLocalDate(parameterName);
} else if (cls == LocalDateTime.class) {
- value = (T) getParameterAsLocalDateTime(parameterName);
+ value = getParameterAsLocalDateTime(parameterName);
} else if (cls == String.class) {
- value = (T) getParameter(parameterName);
+ value = getParameter(parameterName);
+ } else {
+ value = null;
}
return value;
}
diff --git a/core/applib/src/test/java/org/apache/isis/applib/fixturescripts/ExecutionParameters_Test.java b/core/applib/src/test/java/org/apache/isis/applib/fixturescripts/ExecutionParameters_Test.java
index 419b948..7c67b46 100644
--- a/core/applib/src/test/java/org/apache/isis/applib/fixturescripts/ExecutionParameters_Test.java
+++ b/core/applib/src/test/java/org/apache/isis/applib/fixturescripts/ExecutionParameters_Test.java
@@ -148,6 +148,22 @@ public class ExecutionParameters_Test {
assertThat(roundTripped, is(value));
assertThat(roundTrippedAsT, is(value));
}
+
+ @Test
+ public void roundTripString() throws Exception {
+
+ // given
+ final String value = "Hello World!";
+
+ // when
+ executionParameters.setParameter("test", value);
+ final String roundTripped = executionParameters.getParameter("test");
+ final String roundTrippedAsT = executionParameters.getParameterAsT("test", String.class);
+
+ // then
+ assertThat(roundTripped, is(value));
+ assertThat(roundTrippedAsT, is(value));
+ }
@Test
public void roundTripBoolean() throws Exception {
@@ -229,6 +245,27 @@ public class ExecutionParameters_Test {
assertThat(roundTripped, is(value));
assertThat(roundTrippedAsT, is(value));
}
+
+ private static enum EnumForTest {
+ hello,
+ world
+ }
+
+ @Test
+ public void roundTripEnum() throws Exception {
+
+ // given
+ final EnumForTest value = EnumForTest.hello;
+
+ // when
+ executionParameters.setParameter("test", value);
+ final EnumForTest roundTripped = executionParameters.getParameterAsEnum("test", EnumForTest.class);
+ final EnumForTest roundTrippedAsT = executionParameters.getParameterAsT("test", EnumForTest.class);
+
+ // then
+ assertThat(roundTripped, is(value));
+ assertThat(roundTrippedAsT, is(value));
+ }
}
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
ahuber@apache.org.