From a7e61b5d5abc604df214cd268b8443138717e9af Mon Sep 17 00:00:00 2001 From: Marek Gradzki Date: Mon, 26 Sep 2016 08:20:34 +0200 Subject: HONEYCOMB-116: generic merge test for reader customizers Change-Id: I5c2505e6b3bcf622312f8dc324912507f6519a5b Signed-off-by: Marek Gradzki --- .../vpp/test/read/ListReaderCustomizerTest.java | 24 ++++++++++++++-------- .../vpp/test/read/ReaderCustomizerTest.java | 21 ++++++++++++++++--- 2 files changed, 34 insertions(+), 11 deletions(-) (limited to 'vpp-common/vpp-translate-test/src/main/java/io') diff --git a/vpp-common/vpp-translate-test/src/main/java/io/fd/honeycomb/vpp/test/read/ListReaderCustomizerTest.java b/vpp-common/vpp-translate-test/src/main/java/io/fd/honeycomb/vpp/test/read/ListReaderCustomizerTest.java index 0509ef9e5..8917c02db 100644 --- a/vpp-common/vpp-translate-test/src/main/java/io/fd/honeycomb/vpp/test/read/ListReaderCustomizerTest.java +++ b/vpp-common/vpp-translate-test/src/main/java/io/fd/honeycomb/vpp/test/read/ListReaderCustomizerTest.java @@ -16,15 +16,16 @@ package io.fd.honeycomb.vpp.test.read; -import static org.junit.Assert.assertNotNull; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; import io.fd.honeycomb.translate.spi.read.ListReaderCustomizer; -import org.junit.Test; +import java.lang.reflect.Method; +import java.util.List; import org.opendaylight.yangtools.concepts.Builder; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.Identifiable; import org.opendaylight.yangtools.yang.binding.Identifier; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; /** * Generic test for classes implementing {@link ListReaderCustomizer} interface. @@ -36,8 +37,10 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; public abstract class ListReaderCustomizerTest, K extends Identifier, B extends Builder> extends ReaderCustomizerTest { - protected ListReaderCustomizerTest(Class dataObjectClass) { - super(dataObjectClass); + protected ListReaderCustomizerTest( + final Class dataObjectClass, + final Class> parentBuilderClass) { + super(dataObjectClass, parentBuilderClass); } @Override @@ -45,8 +48,13 @@ public abstract class ListReaderCustomizerTest parentBuilder = mock(parentBuilderClass); + final List value = (List) mock(List.class); + getCustomizer().merge(parentBuilder, value); + + final Method method = parentBuilderClass.getMethod("set" + dataObjectClass.getSimpleName(), List.class); + method.invoke(verify(parentBuilder), value); } } diff --git a/vpp-common/vpp-translate-test/src/main/java/io/fd/honeycomb/vpp/test/read/ReaderCustomizerTest.java b/vpp-common/vpp-translate-test/src/main/java/io/fd/honeycomb/vpp/test/read/ReaderCustomizerTest.java index 6486c8eb9..22dc2b6fd 100644 --- a/vpp-common/vpp-translate-test/src/main/java/io/fd/honeycomb/vpp/test/read/ReaderCustomizerTest.java +++ b/vpp-common/vpp-translate-test/src/main/java/io/fd/honeycomb/vpp/test/read/ReaderCustomizerTest.java @@ -17,6 +17,8 @@ package io.fd.honeycomb.vpp.test.read; import static org.junit.Assert.assertNotNull; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; import io.fd.honeycomb.translate.MappingContext; import io.fd.honeycomb.translate.ModificationCache; @@ -26,6 +28,7 @@ import io.fd.honeycomb.translate.read.ReadContext; import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; import io.fd.honeycomb.vpp.test.util.FutureProducer; import io.fd.honeycomb.vpp.test.util.NamingContextHelper; +import java.lang.reflect.Method; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; @@ -52,12 +55,16 @@ public abstract class ReaderCustomizerTest> parentBuilderClass; protected final Class dataObjectClass; + protected ModificationCache cache; protected ReaderCustomizer customizer; - protected ReaderCustomizerTest(Class dataObjectClass) { + public ReaderCustomizerTest( + final Class dataObjectClass, + final Class> parentBuilderClass) { this.dataObjectClass = dataObjectClass; + this.parentBuilderClass = parentBuilderClass; } @Before @@ -87,5 +94,13 @@ public abstract class ReaderCustomizerTest parentBuilder = mock(parentBuilderClass); + final D value = mock(dataObjectClass); + getCustomizer().merge(parentBuilder, value); + + final Method method = parentBuilderClass.getMethod("set" + dataObjectClass.getSimpleName(), dataObjectClass); + method.invoke(verify(parentBuilder), value); + } } -- cgit 1.2.3-korg