mirror of https://github.com/rusefi/usb4java.git
Added some unit tests.
This commit is contained in:
parent
7ff6023685
commit
91e2742830
14
pom.xml
14
pom.xml
|
@ -54,6 +54,7 @@
|
|||
<properties>
|
||||
<releasesUrl>http://www.ailis.de/nexus/content/repositories/releases/de/ailis/${project.artifactId}/${project.artifactId}/${project.version}</releasesUrl>
|
||||
<snapshotsUrl>http://www.ailis.de/nexus/content/repositories/snapshots/de/ailis/${project.artifactId}/${project.artifactId}</snapshotsUrl>
|
||||
<powermock.version>1.4.7</powermock.version>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
|
@ -138,6 +139,19 @@
|
|||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.8.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-module-junit4</artifactId>
|
||||
<version>${powermock.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-api-mockito</artifactId>
|
||||
<version>${powermock.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.usb</groupId>
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Copyright (C) 2011 Klaus Reimer <k@ailis.de>
|
||||
* See LICENSE.txt for licensing information.
|
||||
*/
|
||||
|
||||
package de.ailis.usb4java;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
|
||||
/**
|
||||
* Tests the Services class.
|
||||
*
|
||||
* @author Klaus Reimer (k@ailis.de)
|
||||
*/
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest( { Services.class })
|
||||
public class ServicesTest
|
||||
{
|
||||
@Test
|
||||
public void testConstructor()
|
||||
{
|
||||
}
|
||||
}
|
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* Copyright (C) 2011 Klaus Reimer <k@ailis.de>
|
||||
* See LICENSE.txt for licensing information.
|
||||
*/
|
||||
|
||||
package de.ailis.usb4java.descriptors;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.powermock.api.mockito.PowerMockito.when;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import de.ailis.usb4java.jni.USB_Descriptor_Header;
|
||||
import de.ailis.usb4java.jni.USB_Endpoint_Descriptor;
|
||||
|
||||
|
||||
/**
|
||||
* Tests the LibUsbEndpointDescriptor class.
|
||||
*
|
||||
* @author Klaus Reimer (k@ailis.de)
|
||||
*/
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest( { USB_Endpoint_Descriptor.class, USB_Descriptor_Header.class })
|
||||
public class LibUsbEndpointDescriptorTest
|
||||
{
|
||||
/** The descriptor to test. */
|
||||
private static LibUsbEndpointDescriptor descriptor;
|
||||
|
||||
|
||||
/**
|
||||
* Prepares the test subject.
|
||||
*/
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass()
|
||||
{
|
||||
final USB_Endpoint_Descriptor mock = PowerMockito.mock(USB_Endpoint_Descriptor.class);
|
||||
when(mock.bEndpointAddress()).thenReturn(200);
|
||||
when(mock.bmAttributes()).thenReturn(201);
|
||||
when(mock.wMaxPacketSize()).thenReturn(40000);
|
||||
when(mock.bInterval()).thenReturn(202);
|
||||
descriptor = new LibUsbEndpointDescriptor(mock);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests the bEndpointAddress() method.
|
||||
*/
|
||||
|
||||
@Test
|
||||
public void testBEndpointAddress()
|
||||
{
|
||||
assertEquals((byte) 200, descriptor.bEndpointAddress());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests the bmAttributes() method.
|
||||
*/
|
||||
|
||||
@Test
|
||||
public void testBmAttributes()
|
||||
{
|
||||
assertEquals((byte) 201, descriptor.bmAttributes());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests the wMaxPacketSize() method.
|
||||
*/
|
||||
|
||||
@Test
|
||||
public void testWMaxPacketSize()
|
||||
{
|
||||
assertEquals((short) 40000, descriptor.wMaxPacketSize());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests the bInterval() method.
|
||||
*/
|
||||
|
||||
@Test
|
||||
public void testBInterval()
|
||||
{
|
||||
assertEquals((byte) 202, descriptor.bInterval());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* Copyright (C) 2011 Klaus Reimer <k@ailis.de>
|
||||
* See LICENSE.txt for licensing information.
|
||||
*/
|
||||
|
||||
package de.ailis.usb4java.jni;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.powermock.api.mockito.PowerMockito.mock;
|
||||
import static org.powermock.api.mockito.PowerMockito.when;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
|
||||
/**
|
||||
* Tests the Services class.
|
||||
*
|
||||
* @author Klaus Reimer (k@ailis.de)
|
||||
*/
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({ USB_Endpoint_Descriptor.class })
|
||||
public class USB_Endpoint_Descriptor_Test
|
||||
{
|
||||
/** The descriptor to test. */
|
||||
private static USB_Endpoint_Descriptor descriptor;
|
||||
|
||||
|
||||
/**
|
||||
* Prepares the test class.
|
||||
*/
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass()
|
||||
{
|
||||
descriptor = new USB_Endpoint_Descriptor(ByteBuffer.allocateDirect(18));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests the dump method.
|
||||
* @throws Exception
|
||||
*/
|
||||
|
||||
@Test
|
||||
public void testDump() throws Exception
|
||||
{
|
||||
final USB_Endpoint_Descriptor descriptor = mock(USB_Endpoint_Descriptor.class);
|
||||
when(descriptor.bDescriptorType()).thenReturn(1);
|
||||
when(descriptor.bEndpointAddress()).thenReturn(2);
|
||||
when(descriptor.bInterval()).thenReturn(3);
|
||||
when(descriptor.bLength()).thenReturn(4);
|
||||
when(descriptor.bmAttributes()).thenReturn(5);
|
||||
when(descriptor.bRefresh()).thenReturn(6);
|
||||
when(descriptor.bSynchAddress()).thenReturn(7);
|
||||
when(descriptor.extra()).thenReturn(ByteBuffer.allocateDirect(4));
|
||||
when(descriptor.extralen()).thenReturn(2);
|
||||
when(descriptor.dump()).thenCallRealMethod();
|
||||
final String actual = descriptor.dump();
|
||||
assertNotNull(actual);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue