This is an automated email from the ASF dual-hosted git repository. sruehl pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git
The following commit(s) were added to refs/heads/master by this push: new 89ee18c added some more Util methods and tests for it 89ee18c is described below commit 89ee18c66db546eff76351c581f436faa4ec2540 Author: Sebastian Rühl <sru...@apache.org> AuthorDate: Sat Feb 17 16:01:31 2018 +0100 added some more Util methods and tests for it --- .../java/ads/api/commands/types/AdsReturnCode.java | 8 ++++++++ .../ads/api/commands/CommandFactoryMethodTest.java | 6 +++++- .../types/CommandTypesFactoryMethodTest.java | 24 +++++++++++++++++++++- .../ads/api/generic/GenericFactoryMethodTest.java | 6 +++++- 4 files changed, 41 insertions(+), 3 deletions(-) diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/AdsReturnCode.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/AdsReturnCode.java index 00da995..0040628 100644 --- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/AdsReturnCode.java +++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/AdsReturnCode.java @@ -189,6 +189,14 @@ public enum AdsReturnCode { return UNKNOWN; } + public static AdsReturnCode of(String name) { + return valueOf(name); + } + + public static AdsReturnCode ofInt(String value) { + return of(Long.parseLong(value)); + } + public long getHex() { return hex; } diff --git a/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/commands/CommandFactoryMethodTest.java b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/commands/CommandFactoryMethodTest.java index 41b6d22..5bec44c 100644 --- a/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/commands/CommandFactoryMethodTest.java +++ b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/commands/CommandFactoryMethodTest.java @@ -25,6 +25,7 @@ import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import java.lang.reflect.Method; +import java.lang.reflect.Modifier; import java.util.Arrays; import java.util.Collection; import java.util.Collections; @@ -74,7 +75,10 @@ public class CommandFactoryMethodTest { public void testOf() throws Exception { List<Method> getters = Arrays .stream(clazz.getDeclaredMethods()) - .filter(method -> method.getName().startsWith("get") && method.getParameterCount() == 0) + .filter(method -> ( + method.getName().startsWith("get") || method.getName().startsWith("is")) + && Modifier.isPublic(method.getModifiers()) + && method.getParameterCount() == 0) .collect(Collectors.toList()); for (Method method : clazz.getDeclaredMethods()) { if (!method.getName().equals("of")) { diff --git a/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/commands/types/CommandTypesFactoryMethodTest.java b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/commands/types/CommandTypesFactoryMethodTest.java index 1ffe66a..290cafb 100644 --- a/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/commands/types/CommandTypesFactoryMethodTest.java +++ b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/commands/types/CommandTypesFactoryMethodTest.java @@ -26,9 +26,12 @@ import org.junit.runners.Parameterized; import java.lang.reflect.Field; import java.lang.reflect.Method; +import java.lang.reflect.Modifier; import java.math.BigInteger; import java.nio.charset.Charset; +import java.util.Arrays; import java.util.Collection; +import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -44,6 +47,7 @@ public class CommandTypesFactoryMethodTest { @Parameterized.Parameters(name = "{index} {0}") public static Collection<Object[]> data() { return Stream.of( + AdsReturnCode.class, ADSState.class, CycleTime.class, Data.class, @@ -85,7 +89,24 @@ public class CommandTypesFactoryMethodTest { @Test public void testOfString() throws Exception { Method ofMethod = clazz.getDeclaredMethod("of", String.class); - ofMethod.invoke(null, "1"); + ofMethod.invoke(null, clazz != AdsReturnCode.class ? "1" : "ADS_CODE_0"); + } + + @Test + public void testGetter() throws Exception { + List<Method> getters = Arrays + .stream(clazz.getDeclaredMethods()) + .filter(method -> ( + method.getName().startsWith("get") || method.getName().startsWith("is")) + && Modifier.isPublic(method.getModifiers()) + && method.getParameterCount() == 0) + .collect(Collectors.toList()); + Method ofMethod = clazz.getDeclaredMethod("of", String.class); + Object invoke = ofMethod.invoke(null, clazz != AdsReturnCode.class ? "1" : "ADS_CODE_0"); + // Testing getters for the coverage (sonar) + for (Method getter : getters) { + getter.invoke(invoke); + } } @Test @@ -115,6 +136,7 @@ public class CommandTypesFactoryMethodTest { @Test public void testOfBytes() throws Exception { assumeThat(clazz, not(Data.class)); + assumeThat(clazz, not(AdsReturnCode.class)); Field num_bytes_field = clazz.getDeclaredField("NUM_BYTES"); Integer numberOfBytes = (Integer) num_bytes_field.get(null); Method ofMethod = clazz.getDeclaredMethod("of", byte[].class); diff --git a/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/generic/GenericFactoryMethodTest.java b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/generic/GenericFactoryMethodTest.java index f73a7c4..ca8f415 100644 --- a/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/generic/GenericFactoryMethodTest.java +++ b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/generic/GenericFactoryMethodTest.java @@ -25,6 +25,7 @@ import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import java.lang.reflect.Method; +import java.lang.reflect.Modifier; import java.util.Arrays; import java.util.Collection; import java.util.List; @@ -56,7 +57,10 @@ public class GenericFactoryMethodTest { public void testOf() throws Exception { List<Method> getters = Arrays .stream(clazz.getDeclaredMethods()) - .filter(method -> method.getName().startsWith("get") && method.getParameterCount() == 0) + .filter(method -> ( + method.getName().startsWith("get") || method.getName().startsWith("is")) + && Modifier.isPublic(method.getModifiers()) + && method.getParameterCount() == 0) .collect(Collectors.toList()); for (Method method : clazz.getDeclaredMethods()) { if (!method.getName().equals("of")) { -- To stop receiving notification emails like this one, please contact sru...@apache.org.