Fix conditional execution of unit tests
This commit is contained in:
parent
b05594758b
commit
8eec66545d
7
pom.xml
7
pom.xml
@ -275,13 +275,6 @@
|
||||
<version>1.2.0-SNAPSHOT</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.usb4java</groupId>
|
||||
<artifactId>libusb4java</artifactId>
|
||||
<classifier>linux-x86</classifier>
|
||||
<version>1.2.0-SNAPSHOT</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
|
||||
@ -6,12 +6,11 @@
|
||||
package org.usb4java;
|
||||
|
||||
import static org.usb4java.test.UsbAssume.assumeUsbTestsEnabled;
|
||||
import static org.usb4java.test.UsbAssume.isUsbTestsEnabled;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.usb4java.BosDescriptor;
|
||||
import org.usb4java.LibUsb;
|
||||
|
||||
/**
|
||||
* Tests the {@link BosDescriptor} class.
|
||||
@ -29,9 +28,11 @@ public class BosDescriptorTest
|
||||
@Before
|
||||
public void setUp()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
LibUsb.init(null);
|
||||
this.descriptor = new BosDescriptor();
|
||||
if (isUsbTestsEnabled())
|
||||
{
|
||||
LibUsb.init(null);
|
||||
this.descriptor = new BosDescriptor();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -40,7 +41,10 @@ public class BosDescriptorTest
|
||||
@After
|
||||
public void tearDown()
|
||||
{
|
||||
LibUsb.exit(null);
|
||||
if (isUsbTestsEnabled())
|
||||
{
|
||||
LibUsb.exit(null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
package org.usb4java;
|
||||
|
||||
import static org.usb4java.test.UsbAssume.assumeUsbTestsEnabled;
|
||||
import static org.usb4java.test.UsbAssume.isUsbTestsEnabled;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@ -29,9 +30,11 @@ public class BosDevCapabilityDescriptorTest
|
||||
@Before
|
||||
public void setUp()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
LibUsb.init(null);
|
||||
this.descriptor = new BosDevCapabilityDescriptor();
|
||||
if (isUsbTestsEnabled())
|
||||
{
|
||||
LibUsb.init(null);
|
||||
this.descriptor = new BosDevCapabilityDescriptor();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -40,7 +43,10 @@ public class BosDevCapabilityDescriptorTest
|
||||
@After
|
||||
public void tearDown()
|
||||
{
|
||||
LibUsb.exit(null);
|
||||
if (isUsbTestsEnabled())
|
||||
{
|
||||
LibUsb.exit(null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
package org.usb4java;
|
||||
|
||||
import static org.usb4java.test.UsbAssume.assumeUsbTestsEnabled;
|
||||
import static org.usb4java.test.UsbAssume.isUsbTestsEnabled;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@ -29,9 +30,11 @@ public class ConfigDescriptorTest
|
||||
@Before
|
||||
public void setUp()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
LibUsb.init(null);
|
||||
this.descriptor = new ConfigDescriptor();
|
||||
if (isUsbTestsEnabled())
|
||||
{
|
||||
LibUsb.init(null);
|
||||
this.descriptor = new ConfigDescriptor();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -40,7 +43,10 @@ public class ConfigDescriptorTest
|
||||
@After
|
||||
public void tearDown()
|
||||
{
|
||||
LibUsb.exit(null);
|
||||
if (isUsbTestsEnabled())
|
||||
{
|
||||
LibUsb.exit(null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
package org.usb4java;
|
||||
|
||||
import static org.usb4java.test.UsbAssume.assumeUsbTestsEnabled;
|
||||
import static org.usb4java.test.UsbAssume.isUsbTestsEnabled;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@ -29,9 +30,11 @@ public class ContainerIdDescriptorTest
|
||||
@Before
|
||||
public void setUp()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
LibUsb.init(null);
|
||||
this.descriptor = new ContainerIdDescriptor();
|
||||
if (isUsbTestsEnabled())
|
||||
{
|
||||
LibUsb.init(null);
|
||||
this.descriptor = new ContainerIdDescriptor();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -40,7 +43,10 @@ public class ContainerIdDescriptorTest
|
||||
@After
|
||||
public void tearDown()
|
||||
{
|
||||
LibUsb.exit(null);
|
||||
if (isUsbTestsEnabled())
|
||||
{
|
||||
LibUsb.exit(null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
package org.usb4java;
|
||||
|
||||
import static org.usb4java.test.UsbAssume.assumeUsbTestsEnabled;
|
||||
import static org.usb4java.test.UsbAssume.isUsbTestsEnabled;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@ -29,9 +30,11 @@ public class DeviceDescriptorTest
|
||||
@Before
|
||||
public void setUp()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
LibUsb.init(null);
|
||||
this.descriptor = new DeviceDescriptor();
|
||||
if (isUsbTestsEnabled())
|
||||
{
|
||||
LibUsb.init(null);
|
||||
this.descriptor = new DeviceDescriptor();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -40,7 +43,10 @@ public class DeviceDescriptorTest
|
||||
@After
|
||||
public void tearDown()
|
||||
{
|
||||
LibUsb.exit(null);
|
||||
if (isUsbTestsEnabled())
|
||||
{
|
||||
LibUsb.exit(null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
package org.usb4java;
|
||||
|
||||
import static org.usb4java.test.UsbAssume.assumeUsbTestsEnabled;
|
||||
import static org.usb4java.test.UsbAssume.isUsbTestsEnabled;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@ -29,9 +30,11 @@ public class EndpointDescriptorTest
|
||||
@Before
|
||||
public void setUp()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
LibUsb.init(null);
|
||||
this.descriptor = new EndpointDescriptor();
|
||||
if (isUsbTestsEnabled())
|
||||
{
|
||||
LibUsb.init(null);
|
||||
this.descriptor = new EndpointDescriptor();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -40,7 +43,10 @@ public class EndpointDescriptorTest
|
||||
@After
|
||||
public void tearDown()
|
||||
{
|
||||
LibUsb.exit(null);
|
||||
if (isUsbTestsEnabled())
|
||||
{
|
||||
LibUsb.exit(null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
package org.usb4java;
|
||||
|
||||
import static org.usb4java.test.UsbAssume.assumeUsbTestsEnabled;
|
||||
import static org.usb4java.test.UsbAssume.isUsbTestsEnabled;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@ -29,9 +30,11 @@ public class InterfaceDescriptorTest
|
||||
@Before
|
||||
public void setUp()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
LibUsb.init(null);
|
||||
this.descriptor = new InterfaceDescriptor();
|
||||
if (isUsbTestsEnabled())
|
||||
{
|
||||
LibUsb.init(null);
|
||||
this.descriptor = new InterfaceDescriptor();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -40,7 +43,10 @@ public class InterfaceDescriptorTest
|
||||
@After
|
||||
public void tearDown()
|
||||
{
|
||||
LibUsb.exit(null);
|
||||
if (isUsbTestsEnabled())
|
||||
{
|
||||
LibUsb.exit(null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
package org.usb4java;
|
||||
|
||||
import static org.usb4java.test.UsbAssume.assumeUsbTestsEnabled;
|
||||
import static org.usb4java.test.UsbAssume.isUsbTestsEnabled;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@ -29,9 +30,11 @@ public class InterfaceTest
|
||||
@Before
|
||||
public void setUp()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
LibUsb.init(null);
|
||||
this.descriptor = new Interface();
|
||||
if (isUsbTestsEnabled())
|
||||
{
|
||||
LibUsb.init(null);
|
||||
this.descriptor = new Interface();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -40,7 +43,10 @@ public class InterfaceTest
|
||||
@After
|
||||
public void tearDown()
|
||||
{
|
||||
LibUsb.exit(null);
|
||||
if (isUsbTestsEnabled())
|
||||
{
|
||||
LibUsb.exit(null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
package org.usb4java;
|
||||
|
||||
import static org.usb4java.test.UsbAssume.assumeUsbTestsEnabled;
|
||||
import static org.usb4java.test.UsbAssume.isUsbTestsEnabled;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@ -62,20 +63,23 @@ public class LibUSBDeviceTest
|
||||
@Before
|
||||
public void setUp()
|
||||
{
|
||||
this.context = new Context();
|
||||
LibUsb.init(this.context);
|
||||
try
|
||||
if (isUsbTestsEnabled())
|
||||
{
|
||||
this.device = this.findTestDevice();
|
||||
if (this.device == null)
|
||||
this.context = new Context();
|
||||
LibUsb.init(this.context);
|
||||
try
|
||||
{
|
||||
throw new IllegalStateException("Need at least one USB device "
|
||||
+ "with at least one endpoint to execute this test");
|
||||
this.device = this.findTestDevice();
|
||||
if (this.device == null)
|
||||
{
|
||||
throw new IllegalStateException("Need at least one USB device "
|
||||
+ "with at least one endpoint to execute this test");
|
||||
}
|
||||
}
|
||||
catch (final Throwable e)
|
||||
{
|
||||
this.device = null;
|
||||
}
|
||||
}
|
||||
catch (final Throwable e)
|
||||
{
|
||||
this.device = null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -145,13 +149,16 @@ public class LibUSBDeviceTest
|
||||
@After
|
||||
public void tearDown()
|
||||
{
|
||||
if (this.device != null)
|
||||
if (isUsbTestsEnabled())
|
||||
{
|
||||
LibUsb.unrefDevice(this.device);
|
||||
}
|
||||
if (this.context != null)
|
||||
{
|
||||
LibUsb.exit(this.context);
|
||||
if (this.device != null)
|
||||
{
|
||||
LibUsb.unrefDevice(this.device);
|
||||
}
|
||||
if (this.context != null)
|
||||
{
|
||||
LibUsb.exit(this.context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
package org.usb4java;
|
||||
|
||||
import static org.usb4java.test.UsbAssume.assumeUsbTestsEnabled;
|
||||
import static org.usb4java.test.UsbAssume.isUsbTestsEnabled;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@ -29,9 +30,11 @@ public class SsEndpointCompanionDescriptorTest
|
||||
@Before
|
||||
public void setUp()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
LibUsb.init(null);
|
||||
this.descriptor = new SsEndpointCompanionDescriptor();
|
||||
if (isUsbTestsEnabled())
|
||||
{
|
||||
LibUsb.init(null);
|
||||
this.descriptor = new SsEndpointCompanionDescriptor();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -40,7 +43,10 @@ public class SsEndpointCompanionDescriptorTest
|
||||
@After
|
||||
public void tearDown()
|
||||
{
|
||||
LibUsb.exit(null);
|
||||
if (isUsbTestsEnabled())
|
||||
{
|
||||
LibUsb.exit(null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
package org.usb4java;
|
||||
|
||||
import static org.usb4java.test.UsbAssume.assumeUsbTestsEnabled;
|
||||
import static org.usb4java.test.UsbAssume.isUsbTestsEnabled;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@ -29,9 +30,11 @@ public class SsUsbDeviceCapabilityDescriptorTest
|
||||
@Before
|
||||
public void setUp()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
LibUsb.init(null);
|
||||
this.descriptor = new SsUsbDeviceCapabilityDescriptor();
|
||||
if (isUsbTestsEnabled())
|
||||
{
|
||||
LibUsb.init(null);
|
||||
this.descriptor = new SsUsbDeviceCapabilityDescriptor();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -40,7 +43,10 @@ public class SsUsbDeviceCapabilityDescriptorTest
|
||||
@After
|
||||
public void tearDown()
|
||||
{
|
||||
LibUsb.exit(null);
|
||||
if (isUsbTestsEnabled())
|
||||
{
|
||||
LibUsb.exit(null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
package org.usb4java;
|
||||
|
||||
import static org.usb4java.test.UsbAssume.assumeUsbTestsEnabled;
|
||||
import static org.usb4java.test.UsbAssume.isUsbTestsEnabled;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@ -29,9 +30,11 @@ public class Usb20ExtensionDescriptorTest
|
||||
@Before
|
||||
public void setUp()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
LibUsb.init(null);
|
||||
this.descriptor = new Usb20ExtensionDescriptor();
|
||||
if (isUsbTestsEnabled())
|
||||
{
|
||||
LibUsb.init(null);
|
||||
this.descriptor = new Usb20ExtensionDescriptor();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -40,7 +43,10 @@ public class Usb20ExtensionDescriptorTest
|
||||
@After
|
||||
public void tearDown()
|
||||
{
|
||||
LibUsb.exit(null);
|
||||
if (isUsbTestsEnabled())
|
||||
{
|
||||
LibUsb.exit(null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
package org.usb4java;
|
||||
|
||||
import static org.usb4java.test.UsbAssume.assumeUsbTestsEnabled;
|
||||
import static org.usb4java.test.UsbAssume.isUsbTestsEnabled;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@ -29,9 +30,11 @@ public class VersionTest
|
||||
@Before
|
||||
public void setUp()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
LibUsb.init(null);
|
||||
this.version = new Version();
|
||||
if (isUsbTestsEnabled())
|
||||
{
|
||||
LibUsb.init(null);
|
||||
this.version = new Version();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -40,7 +43,10 @@ public class VersionTest
|
||||
@After
|
||||
public void tearDown()
|
||||
{
|
||||
LibUsb.exit(null);
|
||||
if (isUsbTestsEnabled())
|
||||
{
|
||||
LibUsb.exit(null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -23,19 +23,19 @@ public class UsbAssume
|
||||
|
||||
/** If TCK tests are to be executed. */
|
||||
private static Boolean tckTests;
|
||||
|
||||
|
||||
/**
|
||||
* Assume that USB tests are enabled. Call this in the first line of
|
||||
* tests method or preparation methods when you want to ignore the
|
||||
* tests when the system is not able to run the tests anyway.
|
||||
* Check if USB tests are enabled.
|
||||
*
|
||||
* USB tests can be controlled with the system property USB_TESTS. When
|
||||
* set to true then USB tests are always run, if set to false then they
|
||||
* are never run. If this property is not set then the command-line tool
|
||||
* lsusb is called. If this tool returned at least two lines of text then
|
||||
* USB tests are enabled. In all other cases they are disabled.
|
||||
*
|
||||
* @return True if USB tests are enabled, false if not.
|
||||
*/
|
||||
public static void assumeUsbTestsEnabled()
|
||||
public static boolean isUsbTestsEnabled()
|
||||
{
|
||||
if (usbTests == null && System.getProperty("USB_TESTS") != null)
|
||||
usbTests = Boolean.valueOf(System.getProperty("USB_TESTS"));
|
||||
@ -77,8 +77,27 @@ public class UsbAssume
|
||||
// not be run.
|
||||
}
|
||||
}
|
||||
assumeTrue("This test is ignored when USB_TESTS property is not set",
|
||||
usbTests);
|
||||
return usbTests;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assume that USB tests are enabled. Call this in the first line of
|
||||
* tests method or preparation methods when you want to ignore the
|
||||
* tests when the system is not able to run the tests anyway.
|
||||
*
|
||||
* USB tests can be controlled with the system property USB_TESTS. When
|
||||
* set to true then USB tests are always run, if set to false then they
|
||||
* are never run. If this property is not set then the command-line tool
|
||||
* lsusb is called. If this tool returned at least two lines of text then
|
||||
* USB tests are enabled. In all other cases they are disabled.
|
||||
*/
|
||||
public static void assumeUsbTestsEnabled()
|
||||
{
|
||||
if (!isUsbTestsEnabled())
|
||||
{
|
||||
assumeTrue("This test is ignored when USB_TESTS property is not set",
|
||||
usbTests);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
Reference in New Issue
Block a user