Skip to content

Commit 55fca04

Browse files
committed
Add unit test for LibUsbException class.
1 parent d4c250c commit 55fca04

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright (C) 2014 Klaus Reimer <k@ailis.de>
3+
* See LICENSE.md for licensing information.
4+
*/
5+
6+
package org.usb4java;
7+
8+
import static org.junit.Assert.assertEquals;
9+
10+
import org.junit.Test;
11+
12+
/**
13+
* Tests the {@link LibUsbException} class.
14+
*
15+
* @author Klaus Reimer (k@ailis.de)
16+
*/
17+
public class LibUsbExceptionTest
18+
{
19+
/**
20+
* Tests the constructor with only an error code.
21+
*/
22+
@Test
23+
public void testConstructorWithCode()
24+
{
25+
final LibUsbException e =
26+
new LibUsbException(LibUsb.ERROR_INVALID_PARAM);
27+
assertEquals(LibUsb.ERROR_INVALID_PARAM, e.getErrorCode());
28+
assertEquals("USB error 2: Invalid parameter", e.getMessage());
29+
30+
}
31+
32+
/**
33+
* Tests the constructor with an error code and a message.
34+
*/
35+
@Test
36+
public void testConstructorWithCodeAndMessage()
37+
{
38+
final LibUsbException e =
39+
new LibUsbException("Custom message", LibUsb.ERROR_INVALID_PARAM);
40+
assertEquals(LibUsb.ERROR_INVALID_PARAM, e.getErrorCode());
41+
assertEquals("USB error 2: Custom message: Invalid parameter",
42+
e.getMessage());
43+
44+
}
45+
}

0 commit comments

Comments
 (0)