Binding2 runtime - Codecs impl - tests
[mdsal.git] / binding2 / mdsal-binding2-dom-codec / src / main / test / org / opendaylight / mdsal / binding / javav2 / dom / codec / impl / value / EnumerationCodecTest.java
1 /*
2  * Copyright (c) 2017 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 package org.opendaylight.mdsal.binding.javav2.dom.codec.impl.value;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.mockito.Mockito.doReturn;
12 import static org.mockito.Mockito.mock;
13
14 import com.google.common.collect.ImmutableList;
15 import org.junit.Test;
16 import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
17 import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition.EnumPair;
18
19 public class EnumerationCodecTest {
20
21     private enum TestEnum {
22         TEST
23     }
24
25     @Test
26     public void basicTest() throws Exception {
27         final EnumPair pair = mock(EnumPair.class);
28         doReturn(TestEnum.TEST.name()).when(pair).getName();
29         doReturn(0).when(pair).getValue();
30         final EnumTypeDefinition definition = mock(EnumTypeDefinition.class);
31         doReturn(ImmutableList.of(pair)).when(definition).getValues();
32
33         final EnumerationCodec codec = EnumerationCodec.loader(TestEnum.class, definition).call();
34         assertEquals(codec.deserialize(codec.serialize(TestEnum.TEST)), TestEnum.TEST);
35         assertEquals(codec.serialize(codec.deserialize(TestEnum.TEST.name())), TestEnum.TEST.name());
36     }
37 }