2 * Copyright (c) 2023 PANTHEON.tech, 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.yangtools.yang.data.codec.gson;
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;
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;
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());