9a5521e02b5f1592022113a90bf4d54d7194351d
[yangtools.git] / codec / yang-data-codec-gson / src / test / java / org / opendaylight / yangtools / yang / data / codec / gson / YT1542Test.java
1 /*
2  * Copyright (c) 2023 PANTHEON.tech, 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.yangtools.yang.data.codec.gson;
9
10 import static org.junit.jupiter.api.Assertions.assertEquals;
11 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
12 import static org.junit.jupiter.api.Assertions.assertThrows;
13
14 import java.io.IOException;
15 import org.junit.jupiter.api.Test;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
18 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
19
20 class YT1542Test {
21     @Test
22     void writeInstanceIdentifierReportsIOException() {
23         final var codec = JSONCodecFactorySupplier.RFC7951.createSimple(YangParserTestUtils.parseYang())
24             .instanceIdentifierCodec();
25         final var ex = assertThrows(IOException.class, () -> codec.writeValue(null,
26             YangInstanceIdentifier.of(QName.create("foo", "bar"))));
27         assertEquals("Failed to encode instance-identifier", ex.getMessage());
28         assertInstanceOf(IllegalArgumentException.class, ex.getCause());
29     }
30 }