HONEYCOMB-58 - Routing Api
[honeycomb.git] / vpp-common / vpp-translate-test / src / main / java / io / fd / honeycomb / vpp / test / read / ListReaderCustomizerTest.java
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package io.fd.honeycomb.vpp.test.read;
18
19 import static org.mockito.Mockito.mock;
20 import static org.mockito.Mockito.verify;
21
22 import io.fd.honeycomb.translate.spi.read.ListReaderCustomizer;
23 import java.lang.reflect.Method;
24 import java.util.List;
25 import org.opendaylight.yangtools.concepts.Builder;
26 import org.opendaylight.yangtools.yang.binding.DataObject;
27 import org.opendaylight.yangtools.yang.binding.Identifiable;
28 import org.opendaylight.yangtools.yang.binding.Identifier;
29
30 /**
31  * Generic test for classes implementing {@link ListReaderCustomizer} interface.
32  *
33  * @param <D> Specific DataObject derived type (Identifiable), that is handled by this customizer
34  * @param <K> Specific Identifier for handled type (D)
35  * @param <B> Specific Builder for handled type (D)
36  */
37 public abstract class ListReaderCustomizerTest<D extends DataObject & Identifiable<K>, K extends Identifier<D>, B extends Builder<D>> extends
38     ReaderCustomizerTest<D, B> {
39
40     protected ListReaderCustomizerTest(
41         final Class<D> dataObjectClass,
42         final Class<? extends Builder<? extends DataObject>> parentBuilderClass) {
43         super(dataObjectClass, parentBuilderClass);
44     }
45
46     @Override
47     protected ListReaderCustomizer<D, K, B> getCustomizer() {
48         return ListReaderCustomizer.class.cast(super.getCustomizer());
49     }
50
51     @Override
52     public void testMerge() throws Exception {
53         final Builder<? extends DataObject> parentBuilder = mock(parentBuilderClass);
54         final List<D> value = (List<D>) mock(List.class);
55         getCustomizer().merge(parentBuilder, value);
56
57         final Method method = parentBuilderClass.getMethod("set" + dataObjectClass.getSimpleName(), List.class);
58         method.invoke(verify(parentBuilder), value);
59     }
60 }