2 * Copyright (c) 2015 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.protocol.rsvp.parser.spi;
10 import static org.junit.Assert.assertArrayEquals;
12 import io.netty.buffer.ByteBuf;
13 import io.netty.buffer.Unpooled;
14 import java.lang.reflect.Constructor;
15 import java.lang.reflect.InvocationTargetException;
16 import org.junit.Test;
18 public class EROSubobjectUtilTest {
20 @Test(expected = UnsupportedOperationException.class)
21 @SuppressWarnings({ "checkstyle:IllegalThrows", "checkstyle:avoidHidingCauseException" })
22 public void testPrivateConstructor() throws Throwable {
23 final Constructor<EROSubobjectUtil> c = EROSubobjectUtil.class.getDeclaredConstructor();
24 c.setAccessible(true);
27 } catch (final InvocationTargetException e) {
33 public void testFormatSubobject1() {
34 final byte[] array = new byte[]{2, 3};
35 final byte[] expected = new byte[]{(byte) 0x81, 4, 2, 3};
36 final ByteBuf body = Unpooled.copiedBuffer(array);
37 final ByteBuf aggregator = Unpooled.buffer(4);
38 EROSubobjectUtil.formatSubobject(1, Boolean.TRUE, body, aggregator);
39 assertArrayEquals(expected, aggregator.array());
43 public void testFormatSubobject2() {
44 final byte[] array = new byte[]{2, 3};
45 final byte[] expected = new byte[]{1, 4, 2, 3};
46 final ByteBuf body = Unpooled.copiedBuffer(array);
47 final ByteBuf aggregator = Unpooled.buffer(4);
48 EROSubobjectUtil.formatSubobject(1, Boolean.FALSE, body, aggregator);
49 assertArrayEquals(expected, aggregator.array());
53 public void testFormatSubobject3() {
54 final byte[] array = new byte[]{2, 3};
55 final byte[] expected = new byte[]{1, 4, 2, 3};
56 final ByteBuf body = Unpooled.copiedBuffer(array);
57 final ByteBuf aggregator = Unpooled.buffer(4);
58 EROSubobjectUtil.formatSubobject(1, null, body, aggregator);
59 assertArrayEquals(expected, aggregator.array());