package net.ssehub.kernel_haven.test_utils;

import static org.junit.Assume.assumeTrue;

import org.junit.runner.notification.RunNotifier;
import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.model.InitializationError;

import net.ssehub.kernel_haven.util.Util;
import net.ssehub.kernel_haven.util.Util.OSType;

/**
 * May be used to specify that a certain test class runs only on specific operating systems.
 * Usage: <tt>@RunWith(value = AbstractOsSpecificTestRunner.class)</tt>
 * @author El-Sharkawy
 *
 */
abstract class AbstractOsSpecificTestRunner extends BlockJUnit4ClassRunner {
    
    /**
     * Creates a BlockJUnit4ClassRunner to run {@code clazz}.
     * @param clazz The test class.
     * @throws InitializationError if the test class is malformed.
     */
    public AbstractOsSpecificTestRunner(Class<?> clazz) throws InitializationError {
        super(clazz);
    }

    @Override
    public void run(RunNotifier notifier) {
        OSType os = Util.determineOS();
        boolean isSupported = isSupportedOS(os);
        assumeTrue(this.getTestClass().getName() + " skipped because of wrong OS used: " + os, isSupported);
        
        super.run(notifier);            
    }
    
    /**
     * Specification whether the given operating system is supported by the executed test.
     * 
     * @param os The operating system as determined by {@link Util#determineOS()}.
     * @return <tt>true</tt> if the test can be executed on the OS, <tt>false</tt> if the test shall be skipped.
     */
    protected abstract boolean isSupportedOS(OSType os);
}

@@ -49,45 +49,93 @@
 ort 
-static org.junit.Assume.assumeTru
+org.junit.AssumptionViolatedException;%0Aimport org.junit.runner.notification.Failur
 e;%0A
-%0A
 impo
@@ -1060,67 +1060,176 @@
     
-boolean isSupported = isSupportedOS(os);%0A        assumeTrue
+%0A        if (!isSupportedOS(os)) %7B%0A            notifier.fireTestAssumptionFailed(new Failure(super.getDescription(),%0A                    new AssumptionViolatedException
 (thi
@@ -1254,16 +1254,44 @@
 etName()
+%0A                           
  + %22 ski
@@ -1331,33 +1331,34 @@
 + os
-, isSupported);%0A        %0A
+)));%0A        %7D else %7B%0A    
     
@@ -1390,24 +1390,47 @@
            %0A
+            %0A        %7D%0A
     %7D%0A    %0A 

Fix AbstractOsSpecificTestRunner