Skip to content

Commit 603f50e

Browse files
committed
Add unit test for RootHubInterface class.
1 parent 049c69d commit 603f50e

File tree

1 file changed

+216
-0
lines changed

1 file changed

+216
-0
lines changed
Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
/*
2+
* Copyright (C) 2014 Klaus Reimer <k@ailis.de>
3+
* See LICENSE.md for licensing information.
4+
*/
5+
6+
package org.usb4java.javax;
7+
8+
import static org.junit.Assert.assertEquals;
9+
import static org.junit.Assert.assertFalse;
10+
import static org.junit.Assert.assertNull;
11+
import static org.junit.Assert.assertSame;
12+
import static org.junit.Assert.assertTrue;
13+
14+
import java.util.List;
15+
16+
import javax.usb.UsbConfiguration;
17+
import javax.usb.UsbConst;
18+
import javax.usb.UsbEndpoint;
19+
import javax.usb.UsbException;
20+
import javax.usb.UsbInterface;
21+
import javax.usb.UsbInterfaceDescriptor;
22+
23+
import org.junit.Before;
24+
import org.junit.Test;
25+
import org.mockito.Mockito;
26+
27+
/**
28+
* Tests the {@link RootHubInterface} class.
29+
*
30+
* @author Klaus Reimer (k@ailis.de)
31+
*/
32+
public class RootHubInterfaceTest
33+
{
34+
/** The USB configuration. */
35+
private UsbConfiguration config;
36+
37+
/** The test subject. */
38+
private RootHubInterface iface;
39+
40+
/**
41+
* Initialize the test.
42+
*/
43+
@Before
44+
public void init()
45+
{
46+
this.config = Mockito.mock(UsbConfiguration.class);
47+
this.iface = new RootHubInterface(this.config);
48+
}
49+
50+
/**
51+
* Tests the {@link RootHubInterface#claim()} method.
52+
*
53+
* @throws UsbException
54+
* Excepted exception.
55+
*/
56+
@Test(expected = UsbException.class)
57+
public void testClaim() throws UsbException
58+
{
59+
this.iface.claim();
60+
}
61+
62+
/**
63+
* Tests the {@link RootHubInterface#claim(javax.usb.UsbInterfacePolicy)}
64+
* method.
65+
*
66+
* @throws UsbException
67+
* Excepted exception.
68+
*/
69+
@Test(expected = UsbException.class)
70+
public void testClaimWithPolicy() throws UsbException
71+
{
72+
this.iface.claim(null);
73+
}
74+
75+
/**
76+
* Tests the {@link RootHubInterface#release()} method.
77+
*
78+
* @throws UsbException
79+
* Excepted exception.
80+
*/
81+
@Test(expected = UsbException.class)
82+
public void testRelese() throws UsbException
83+
{
84+
this.iface.release();
85+
}
86+
87+
/**
88+
* Tests the {@link RootHubInterface#isClaimed()} method.
89+
*/
90+
@Test
91+
public void testIsClaimed()
92+
{
93+
assertTrue(this.iface.isClaimed());
94+
}
95+
96+
/**
97+
* Tests the {@link RootHubInterface#isActive()} method.
98+
*/
99+
@Test
100+
public void testIsActive()
101+
{
102+
assertTrue(this.iface.isActive());
103+
}
104+
105+
/**
106+
* Tests the {@link RootHubInterface#getNumSettings()} method.
107+
*/
108+
@Test
109+
public void testGetNumSettings()
110+
{
111+
assertEquals(0, this.iface.getNumSettings());
112+
}
113+
114+
/**
115+
* Tests the {@link RootHubInterface#getActiveSettingNumber()} method.
116+
*/
117+
@Test
118+
public void testGetActiveSettingNumber()
119+
{
120+
assertEquals(0, this.iface.getActiveSettingNumber());
121+
}
122+
123+
/**
124+
* Tests the {@link RootHubInterface#getActiveSetting()} method.
125+
*/
126+
@Test
127+
public void testGetActiveSetting()
128+
{
129+
assertSame(this.iface, this.iface.getActiveSetting());
130+
}
131+
132+
/**
133+
* Tests the {@link RootHubInterface#containsSetting(byte)} method.
134+
*/
135+
@Test
136+
public void testContainsSetting()
137+
{
138+
assertFalse(this.iface.containsSetting((byte) 0));
139+
}
140+
141+
/**
142+
* Tests the {@link RootHubInterface#getSettings()} method.
143+
*/
144+
@Test
145+
public void testGetSettings()
146+
{
147+
final List<UsbInterface> settings = this.iface.getSettings();
148+
assertEquals(0, settings.size());
149+
}
150+
151+
/**
152+
* Tests the {@link RootHubInterface#getUsbEndpoints()} method.
153+
*/
154+
@Test
155+
public void testGetUsbEndpoints()
156+
{
157+
final List<UsbEndpoint> endpoints = this.iface.getUsbEndpoints();
158+
assertEquals(0, endpoints.size());
159+
}
160+
161+
/**
162+
* Tests the {@link RootHubInterface#getUsbEndpoint(byte)} method.
163+
*/
164+
@Test
165+
public void testGetUsbEndpoint()
166+
{
167+
assertNull(this.iface.getUsbEndpoint((byte) 0));
168+
}
169+
170+
/**
171+
* Tests the {@link RootHubInterface#containsUsbEndpoint(byte)} method.
172+
*/
173+
@Test
174+
public void testContainsUsbEndpoint()
175+
{
176+
assertFalse(this.iface.containsUsbEndpoint((byte) 0));
177+
}
178+
179+
/**
180+
* Tests the {@link RootHubInterface#getUsbConfiguration()} method.
181+
*/
182+
@Test
183+
public void testGetUsbConfiguration()
184+
{
185+
assertSame(this.config, this.iface.getUsbConfiguration());
186+
}
187+
188+
/**
189+
* Tests the {@link RootHubInterface#getUsbInterfaceDescriptor()} method.
190+
*/
191+
@Test
192+
public void testGetUsbInterfaceDescriptor()
193+
{
194+
final UsbInterfaceDescriptor desc =
195+
this.iface.getUsbInterfaceDescriptor();
196+
assertEquals(UsbConst.DESCRIPTOR_MIN_LENGTH_INTERFACE, desc.bLength());
197+
assertEquals(UsbConst.DESCRIPTOR_TYPE_INTERFACE,
198+
desc.bDescriptorType());
199+
assertEquals(0, desc.bInterfaceNumber());
200+
assertEquals(0, desc.bAlternateSetting());
201+
assertEquals(0, desc.bNumEndpoints());
202+
assertEquals(UsbConst.HUB_CLASSCODE, desc.bInterfaceClass());
203+
assertEquals(0, desc.bInterfaceSubClass());
204+
assertEquals(0, desc.bInterfaceProtocol());
205+
assertEquals(0, desc.iInterface());
206+
}
207+
208+
/**
209+
* Tests the {@link RootHubInterface#getInterfaceString()} method.
210+
*/
211+
@Test
212+
public void testGetInterfaceString()
213+
{
214+
assertNull(this.iface.getInterfaceString());
215+
}
216+
}

0 commit comments

Comments
 (0)