You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@activemq.apache.org by GitBox <gi...@apache.org> on 2021/11/16 08:16:38 UTC

[GitHub] [activemq-artemis] brusdev commented on a change in pull request #3852: NO-JIRA Add AllClassesTest

brusdev commented on a change in pull request #3852:
URL: https://github.com/apache/activemq-artemis/pull/3852#discussion_r750016021



##########
File path: tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/AllClassesTest.java
##########
@@ -0,0 +1,139 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.activemq.artemis.tests.unit;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.common.reflect.ClassPath;
+import org.apache.activemq.artemis.tests.util.RandomUtil;
+import org.jboss.logging.Logger;
+import org.junit.Assume;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.mockito.Mockito;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Modifier;
+import java.lang.reflect.Parameter;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
+@RunWith(value = Parameterized.class)
+public class AllClassesTest {
+   private static final Logger log = Logger.getLogger(AllClassesTest.class);
+
+   private static ClassLoader classLoader = AllClassesTest.class.getClassLoader();
+
+   @Parameterized.Parameters(name = "classInfo={0}")
+   public static Collection getParameters() {
+      List<Class> parameters = new ArrayList<>();
+      ClassLoader classLoader = AllClassesTest.class.getClassLoader();
+
+      try {
+         ClassPath classPath = ClassPath.from(classLoader);
+         ImmutableSet<ClassPath.ClassInfo> classInfos = classPath.getTopLevelClassesRecursive("org.apache.activemq.artemis");
+
+         for (ClassPath.ClassInfo classInfo : classInfos) {
+            if (!classInfo.getPackageName().contains("tests")) {
+               try {
+                  Class loadedClass = classInfo.load();
+                  if (!loadedClass.isEnum() && !loadedClass.isInterface() && !Modifier.isAbstract(loadedClass.getModifiers())) {
+                     parameters.add(loadedClass);
+                  }
+               } catch (Throwable loadThrowable) {
+                  log.debug("cannot load " + classInfo.getName() + ": " + loadThrowable);
+               }
+            }
+         }
+         return parameters;
+      } catch (Exception e) {
+         log.warn("Exception on loading all classes: " + e);
+      }
+
+      return parameters;
+   }
+
+   private Class targetClass;
+
+   public AllClassesTest(Class targetClass) {
+      this.targetClass = targetClass;
+   }
+
+
+   @Test
+   public void testToString() {
+      Object targetInstance = newInstance(targetClass);
+      Assume.assumeTrue("cannot create " + targetClass.getName(), targetInstance != null);
+
+      try {
+         String targetOutput = targetInstance.toString();
+         log.debug("targetOutput: " + targetOutput == null ? "null" : targetOutput);
+      } catch (NullPointerException | UnsupportedOperationException ignore) {

Review comment:
       The `newInstance` try to call any constructor of the target classes starting from the one with more parameters to the one with less parameters.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org