Fix checkstyle warnings for impl/protocol test package
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / protocol / deserialization / MessageDeserializerInjectorTest.java
1 /*
2  * Copyright (c) 2016 Pantheon Technologies s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.openflowplugin.impl.protocol.deserialization;
10
11 import static org.mockito.Mockito.verify;
12
13 import java.util.function.Consumer;
14 import java.util.function.Function;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.junit.runner.RunWith;
18 import org.mockito.Mock;
19 import org.mockito.runners.MockitoJUnitRunner;
20 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
21 import org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey;
22 import org.opendaylight.openflowjava.protocol.api.keys.TypeToClassKey;
23 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
24 import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
26
27 @RunWith(MockitoJUnitRunner.class)
28 public class MessageDeserializerInjectorTest {
29     @Mock
30     private SwitchConnectionProvider switchConnectionProvider;
31
32     @Mock
33     private OFDeserializer<OfHeader> ofDeserializer;
34
35     private Function<Integer, Function<Class<? extends OfHeader>, Consumer<OFDeserializer<? extends OfHeader>>>>
36             injector;
37
38     @Before
39     public void setUp() throws Exception {
40         injector = MessageDeserializerInjector.createInjector(switchConnectionProvider, EncodeConstants
41                 .OF13_VERSION_ID);
42     }
43
44     @Test
45     public void injectDeserializers() throws Exception {
46         injector.apply(10).apply(OfHeader.class).accept(ofDeserializer);
47         verify(switchConnectionProvider).unregisterDeserializerMapping(new TypeToClassKey(EncodeConstants
48                 .OF13_VERSION_ID, 10));
49         verify(switchConnectionProvider).registerDeserializerMapping(new TypeToClassKey(EncodeConstants
50                 .OF13_VERSION_ID, 10), OfHeader.class);
51         verify(switchConnectionProvider).registerDeserializer(new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, 10,
52                 OfHeader.class), ofDeserializer);
53     }
54
55 }