Split STATIC_CODECS into per-type caches
[mdsal.git] / binding / mdsal-binding-dom-codec / src / test / java / org / opendaylight / mdsal / binding / dom / codec / impl / EnumerationCodecTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. 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.dom.codec.impl;
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.binding.Enumeration;
17 import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
18 import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition.EnumPair;
19
20 public class EnumerationCodecTest {
21     private enum TestEnum implements Enumeration {
22         ENUM;
23
24         @Override
25         public String getName() {
26             return "ENUM";
27         }
28
29         @Override
30         public int getIntValue() {
31             return 0;
32         }
33     }
34
35     @Test
36     public void basicTest() throws Exception {
37         final EnumPair pair = mock(EnumPair.class);
38         doReturn(TestEnum.ENUM.name()).when(pair).getName();
39         doReturn(0).when(pair).getValue();
40         EnumTypeDefinition definition = mock(EnumTypeDefinition.class);
41         doReturn(ImmutableList.of(pair)).when(definition).getValues();
42
43         final EnumerationCodec codec = EnumerationCodec.of(TestEnum.class, definition);
44         assertEquals(codec.deserialize(codec.serialize(TestEnum.ENUM)), TestEnum.ENUM);
45         assertEquals(codec.serialize(codec.deserialize(TestEnum.ENUM.name())), TestEnum.ENUM.name());
46     }
47 }