Search in sources :

Example 76 with AssumptionViolatedException

use of org.junit.AssumptionViolatedException in project junit4 by junit-team.

the class TempFolderRuleTest method getPosixFilePermissions.

private Set<String> getPosixFilePermissions(File root) {
    try {
        Class<?> pathClass = Class.forName("java.nio.file.Path");
        Object linkOptionArray = Array.newInstance(Class.forName("java.nio.file.LinkOption"), 0);
        Class<?> filesClass = Class.forName("java.nio.file.Files");
        Object path = File.class.getDeclaredMethod("toPath").invoke(root);
        Method posixFilePermissionsMethod = filesClass.getDeclaredMethod("getPosixFilePermissions", pathClass, linkOptionArray.getClass());
        Set<?> permissions = (Set<?>) posixFilePermissionsMethod.invoke(null, path, linkOptionArray);
        SortedSet<String> convertedPermissions = new TreeSet<String>();
        for (Object item : permissions) {
            convertedPermissions.add(item.toString());
        }
        return convertedPermissions;
    } catch (Exception e) {
        throw new AssumptionViolatedException("Test requires at least Java 1.7", e);
    }
}
Also used : SortedSet(java.util.SortedSet) Set(java.util.Set) TreeSet(java.util.TreeSet) AssumptionViolatedException(org.junit.AssumptionViolatedException) TreeSet(java.util.TreeSet) Method(java.lang.reflect.Method) File(java.io.File) AssumptionViolatedException(org.junit.AssumptionViolatedException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 77 with AssumptionViolatedException

use of org.junit.AssumptionViolatedException in project zuul by Netflix.

the class SourceAddressChannelHandlerTest method ipv6AddressScopeNameRemoved.

@Test
public void ipv6AddressScopeNameRemoved() throws Exception {
    List<NetworkInterface> nics = Collections.list(NetworkInterface.getNetworkInterfaces());
    Assume.assumeTrue("No network interfaces", !nics.isEmpty());
    List<Throwable> failures = new ArrayList<>();
    for (NetworkInterface nic : nics) {
        Inet6Address address;
        try {
            address = Inet6Address.getByAddress("localhost", new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, nic);
        } catch (UnknownHostException e) {
            // skip, the nic doesn't match
            failures.add(e);
            continue;
        }
        assertTrue(address.toString(), address.toString().contains("%"));
        String addressString = SourceAddressChannelHandler.getHostAddress(new InetSocketAddress(address, 8080));
        assertEquals("0:0:0:0:0:0:0:1", addressString);
        return;
    }
    AssumptionViolatedException failure = new AssumptionViolatedException("No Compatible Nics were found");
    failures.forEach(failure::addSuppressed);
    throw failure;
}
Also used : UnknownHostException(java.net.UnknownHostException) AssumptionViolatedException(org.junit.AssumptionViolatedException) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) NetworkInterface(java.net.NetworkInterface) Inet6Address(java.net.Inet6Address) Test(org.junit.Test)

Example 78 with AssumptionViolatedException

use of org.junit.AssumptionViolatedException in project Java-Tutorial by gpcodervn.

the class CustomSuite method run.

@Override
public void run(RunNotifier notifier) {
    System.out.println("Executing run()");
    // Add Listener. This will register our JUnit Listener.
    notifier.addListener(new ExecutionListener());
    // Get each test notifier
    EachTestNotifier testNotifier = new EachTestNotifier(notifier, getDescription());
    try {
        // In order capture testRunStarted method
        // at the very beginning of the test run, we will add below code.
        // Invoke here the run testRunStarted() method
        notifier.fireTestRunStarted(getDescription());
        Statement statement = classBlock(notifier);
        statement.evaluate();
    } catch (AssumptionViolatedException e) {
        testNotifier.fireTestIgnored();
    } catch (StoppedByUserException e) {
        throw e;
    } catch (Throwable e) {
        testNotifier.addFailure(e);
    }
}
Also used : AssumptionViolatedException(org.junit.AssumptionViolatedException) Statement(org.junit.runners.model.Statement) EachTestNotifier(org.junit.internal.runners.model.EachTestNotifier) StoppedByUserException(org.junit.runner.notification.StoppedByUserException)

Example 79 with AssumptionViolatedException

use of org.junit.AssumptionViolatedException in project Java-Tutorial by gpcodervn.

the class CustomBlockJUnit4ClassRunner method run.

@Override
public void run(RunNotifier notifier) {
    System.out.println("Executing run()");
    // Add Listener. This will register our JUnit Listener.
    notifier.addListener(new ExecutionListener());
    // Get each test notifier
    EachTestNotifier testNotifier = new EachTestNotifier(notifier, getDescription());
    try {
        // In order capture testRunStarted method
        // at the very beginning of the test run, we will add below code.
        // Invoke here the run testRunStarted() method
        notifier.fireTestRunStarted(getDescription());
        Statement statement = classBlock(notifier);
        statement.evaluate();
    } catch (AssumptionViolatedException e) {
        testNotifier.fireTestIgnored();
    } catch (StoppedByUserException e) {
        throw e;
    } catch (Throwable e) {
        testNotifier.addFailure(e);
    }
}
Also used : AssumptionViolatedException(org.junit.AssumptionViolatedException) Statement(org.junit.runners.model.Statement) EachTestNotifier(org.junit.internal.runners.model.EachTestNotifier) StoppedByUserException(org.junit.runner.notification.StoppedByUserException)

Aggregations

AssumptionViolatedException (org.junit.AssumptionViolatedException)79 Test (org.junit.Test)26 IOException (java.io.IOException)16 Statement (org.junit.runners.model.Statement)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 Method (java.lang.reflect.Method)6 Set (java.util.Set)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 File (java.io.File)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 ZipEntry (java.util.zip.ZipEntry)5 ZipOutputStream (java.util.zip.ZipOutputStream)5 InputStream (java.io.InputStream)4 HashSet (java.util.HashSet)4 ZipInputStream (java.util.zip.ZipInputStream)4 FilterInputStream (java.io.FilterInputStream)3 UnknownHostException (java.net.UnknownHostException)3 JarInputStream (java.util.jar.JarInputStream)3 Configuration (org.apache.flink.configuration.Configuration)3 IInjectorProvider (org.eclipse.xtext.junit4.IInjectorProvider)3