jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fschumac...@apache.org
Subject svn commit: r1783697 - in /jmeter/trunk: src/jorphan/org/apache/jorphan/reflect/ClassFinder.java test/src/org/apache/jorphan/reflect/TestClassFinder.java
Date Sun, 19 Feb 2017 21:32:32 GMT
Author: fschumacher
Date: Sun Feb 19 21:32:32 2017
New Revision: 1783697

URL: http://svn.apache.org/viewvc?rev=1783697&view=rev
Log:
Catch more Exceptions that can occur when searching for classes and add tests.

Added:
    jmeter/trunk/test/src/org/apache/jorphan/reflect/TestClassFinder.java   (with props)
Modified:
    jmeter/trunk/src/jorphan/org/apache/jorphan/reflect/ClassFinder.java

Modified: jmeter/trunk/src/jorphan/org/apache/jorphan/reflect/ClassFinder.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/jorphan/org/apache/jorphan/reflect/ClassFinder.java?rev=1783697&r1=1783696&r2=1783697&view=diff
==============================================================================
--- jmeter/trunk/src/jorphan/org/apache/jorphan/reflect/ClassFinder.java (original)
+++ jmeter/trunk/src/jorphan/org/apache/jorphan/reflect/ClassFinder.java Sun Feb 19 21:32:32
2017
@@ -384,8 +384,8 @@ public final class ClassFinder {
                     }
                 }
             } catch (UnsupportedClassVersionError | ClassNotFoundException
-                    | NoClassDefFoundError e) {
-                log.debug(e.getLocalizedMessage());
+                    | NoClassDefFoundError | VerifyError e) {
+                log.debug(e.getLocalizedMessage(), e);
             }
         return false;
     }
@@ -401,8 +401,8 @@ public final class ClassFinder {
                     }
                 }
             }
-        } catch (NoClassDefFoundError | ClassNotFoundException ignored) {
-            log.debug(ignored.getLocalizedMessage());
+        } catch (NoClassDefFoundError | ClassNotFoundException | UnsupportedClassVersionError
| VerifyError ignored) {
+            log.debug(ignored.getLocalizedMessage(), ignored);
         }
         return false;
     }

Added: jmeter/trunk/test/src/org/apache/jorphan/reflect/TestClassFinder.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jorphan/reflect/TestClassFinder.java?rev=1783697&view=auto
==============================================================================
--- jmeter/trunk/test/src/org/apache/jorphan/reflect/TestClassFinder.java (added)
+++ jmeter/trunk/test/src/org/apache/jorphan/reflect/TestClassFinder.java Sun Feb 19 21:32:32
2017
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+*/
+
+package org.apache.jorphan.reflect;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.apache.jmeter.util.JMeterUtils;
+import org.apache.logging.log4j.LoggingException;
+import org.hamcrest.CoreMatchers;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestClassFinder {
+
+    private static final String[] LIB_DIRS = new String[] { getJMeterHome() };
+
+    private static String getJMeterHome() {
+        if (JMeterUtils.getJMeterHome() == null) {
+            return "./lib";
+        }
+        return JMeterUtils.getJMeterHome() + "/lib";
+    }
+    @Test
+    public void testFindClassesThatExtendStringArrayClassOfQArray() throws IOException {
+        List<String> findClassesThatExtend = ClassFinder.findClassesThatExtend(LIB_DIRS,
+                new Class<?>[] { Exception.class });
+        Assert.assertThat(findClassesThatExtend, CoreMatchers.hasItem(LoggingException.class.getName()));
+    }
+
+    @Test
+    public void testFindClassesThatExtendStringArrayClassOfQArrayTrue() throws Exception
{
+        List<String> findClassesThatExtend = ClassFinder.findClassesThatExtend(LIB_DIRS,
+                new Class<?>[] { Object.class }, true);
+        Assert.assertFalse(
+                findClassesThatExtend.stream().filter(s -> s.contains("$")).collect(Collectors.toList()).isEmpty());
+    }
+
+    @Test
+    public void testFindClassesThatExtendStringArrayClassOfQArrayFalse() throws Exception
{
+        List<String> findClassesThatExtend = ClassFinder.findClassesThatExtend(LIB_DIRS,
+                new Class<?>[] { Exception.class }, false);
+        Assert.assertTrue(
+                findClassesThatExtend.stream().filter(s -> s.contains("$")).collect(Collectors.toList()).isEmpty());
+        Assert.assertThat(findClassesThatExtend, CoreMatchers.hasItem(LoggingException.class.getName()));
+    }
+
+    @Test
+    public void testFindClassesThatExtendStringArrayClassOfQArrayBooleanStringString() throws
Exception {
+        List<String> findClassesThatExtend = ClassFinder.findClassesThatExtend(LIB_DIRS,
+                new Class<?>[] { Exception.class }, false, "org.apache.log", "core");
+        Assert.assertTrue(
+                findClassesThatExtend.stream().filter(s -> s.contains("core")).collect(Collectors.toList()).isEmpty());
+        Assert.assertFalse(findClassesThatExtend.isEmpty());
+    }
+
+    @Test
+    public void testFindClasses() throws IOException {
+        Assert.assertFalse(ClassFinder.findClasses(LIB_DIRS, className -> true).isEmpty());
+    }
+
+    @Test
+    public void testFindClassesNone() throws IOException {
+        Assert.assertTrue(ClassFinder.findClasses(LIB_DIRS, className -> false).isEmpty());
+    }
+
+}

Propchange: jmeter/trunk/test/src/org/apache/jorphan/reflect/TestClassFinder.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message