package de.is24.deadcode4j.analyzer;

import mockit.Mock;
import mockit.MockUp;
import mockit.integration.junit4.JMockit;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.fail;

@RunWith(JMockit.class)
public final class A_SpringNamespaceHandlerAnalyzer extends AnAnalyzer<SpringNamespaceHandlerAnalyzer> {

    private static final String SPRING_HANDLER_FILE = "META-INF/spring.handlers";

    @Override
    protected SpringNamespaceHandlerAnalyzer createAnalyzer() {
        return new SpringNamespaceHandlerAnalyzer();
    }

    @Test
    public void shouldRecognizeDefinedNamespaceHandlers() {
        analyzeFile(SPRING_HANDLER_FILE);

        assertThatDependenciesAreReported("CustomNamespaceHandler", "AnotherNamespaceHandler");
    }

    @Test
    public void handlesException() throws Exception {
        new MockUp<FileInputStream>() {
            @Mock
            public void $init(File file) throws IOException {
                throw new IOException("JUnit");
            }
        };

        try {
            analyzeFile(SPRING_HANDLER_FILE);
            fail("Should abort analysis!");
        } catch (RuntimeException e) {
            assertThat(e.getMessage(), containsString(SPRING_HANDLER_FILE));
        }
    }

}

@@ -187,20 +187,27 @@
 java.io.
-File
+IOException
 ;%0Aimport
@@ -215,20 +215,16 @@
 java.io.
-File
 InputStr
@@ -240,30 +240,31 @@
 rt java.
-io.IOException
+util.Properties
 ;%0A%0Aimpor
@@ -1001,16 +1001,18 @@
  handles
+IO
 Exceptio
@@ -1016,27 +1016,27 @@
 tion
-() throws Exception
+WhenAnalyzingFile()
  %7B%0A 
@@ -1057,23 +1057,18 @@
 kUp%3C
-FileInputStream
+Properties
 %3E() 
@@ -1110,28 +1110,51 @@
 lic 
-void $init(File file
+synchronized void load(InputStream inStream
 ) th

fix some runtime-order issues