2 * Copyright (c) 2017 Pantheon Technologies s.r.o. 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.javav2.dom.codec.impl.value;
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.model.api.type.EnumTypeDefinition;
17 import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition.EnumPair;
19 public class EnumerationCodecTest {
21 private enum TestEnum {
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();
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());