fix ClassCastException when running tests from IntelliJ IDEA
authorDennis Kieselhorst <mail@dekies.de>
Mon, 21 Jan 2019 07:37:35 +0000 (08:37 +0100)
committerDennis Kieselhorst <dennis.kieselhorst@eventim.de>
Mon, 21 Jan 2019 07:37:35 +0000 (08:37 +0100)
geronimo-openapi-impl/src/test/java/org/apache/geronimo/microprofile/openapi/test/TckMetaInfBugWorkaround.java

index 5a60311..419abcc 100644 (file)
@@ -37,14 +37,17 @@ public class TckMetaInfBugWorkaround implements ConfigSourceProvider {
     }
 
     private ConfigSource create(final ClassLoader classLoader) {
-        final Context context = ParallelWebappClassLoader.class.cast(classLoader)
-                .getResources()
-                .getContext();
-        final File config = new File(new File(context.getCatalinaBase(), "webapps/" + context.getDocBase()), "META-INF/microprofile-config.properties");
-        try {
-            return config.exists() ? new PropertyFileConfigSource(config.toURI().toURL()) : null;
-        } catch (final MalformedURLException e) {
-            throw new IllegalStateException(e);
+        if (classLoader instanceof ParallelWebappClassLoader) {
+            final Context context = ParallelWebappClassLoader.class.cast(classLoader)
+                    .getResources()
+                    .getContext();
+            final File config = new File(new File(context.getCatalinaBase(), "webapps/" + context.getDocBase()), "META-INF/microprofile-config.properties");
+            try {
+                return config.exists() ? new PropertyFileConfigSource(config.toURI().toURL()) : null;
+            } catch (final MalformedURLException e) {
+                throw new IllegalStateException(e);
+            }
         }
+        return null;
     }
 }