2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.mdsal.binding.dom.codec.impl;
10 import static org.junit.Assert.assertEquals;
11 import static org.mockito.Mockito.doReturn;
12 import static org.mockito.Mockito.mock;
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;
20 public class EnumerationCodecTest {
22 private enum TestEnum implements Enumeration {
26 public String getName() {
31 public int getIntValue() {
37 public void basicTest() throws Exception {
38 final EnumPair pair = mock(EnumPair.class);
39 doReturn(TestEnum.ENUM.name()).when(pair).getName();
40 doReturn(0).when(pair).getValue();
41 EnumTypeDefinition definition = mock(EnumTypeDefinition.class);
42 doReturn(ImmutableList.of(pair)).when(definition).getValues();
44 final EnumerationCodec codec = EnumerationCodec.loader(TestEnum.class, definition).call();
45 assertEquals(codec.deserialize(codec.serialize(TestEnum.ENUM)), TestEnum.ENUM);
46 assertEquals(codec.serialize(codec.deserialize(TestEnum.ENUM.name())), TestEnum.ENUM.name());