Migrate deprecated assertThat()
[bgpcep.git] / util / src / test / java / org / opendaylight / protocol / util / PCEPHexDumpParserTest.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. 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.protocol.util;
9
10 import static org.hamcrest.CoreMatchers.containsString;
11 import static org.hamcrest.MatcherAssert.assertThat;
12 import static org.junit.Assert.assertEquals;
13 import static org.junit.Assert.fail;
14
15 import java.io.File;
16 import java.io.FileNotFoundException;
17 import java.util.List;
18 import org.junit.Test;
19
20 public class PCEPHexDumpParserTest {
21
22     private static final String HEX_DUMP_FILE_NAME = "pcep-hex.txt";
23     private static final int EXPECTED_SIZE = 6;
24
25     @Test
26     public void testParsing() throws Exception {
27         final List<byte[]> result = PCEPHexDumpParser.parseMessages(getClass().getClassLoader().getResourceAsStream(
28                 PCEPHexDumpParserTest.HEX_DUMP_FILE_NAME));
29         assertEquals(EXPECTED_SIZE, result.size());
30         final List<byte[]> result1 = PCEPHexDumpParser.parseMessages(new File(getClass().getClassLoader().getResource(
31                 PCEPHexDumpParserTest.HEX_DUMP_FILE_NAME).toURI()));
32         assertEquals(EXPECTED_SIZE, result1.size());
33     }
34
35     @Test
36     public void testParsingInvalidFile() throws Exception {
37         try {
38             PCEPHexDumpParser.parseMessages(new File("bad file name"));
39             fail("Exception should have occured.");
40         } catch (final FileNotFoundException e) {
41             assertThat(e.getMessage(), containsString("bad file name"));
42         }
43     }
44 }