Airblader commented on a change in pull request #17133:
URL: https://github.com/apache/flink/pull/17133#discussion_r705949937



##########
File path: 
flink-architecture-tests/src/test/java/org/apache/flink/architecture/common/Conditions.java
##########
@@ -0,0 +1,143 @@
+/*
+ * 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.flink.architecture.common;
+
+import com.tngtech.archunit.base.DescribedPredicate;
+import com.tngtech.archunit.core.domain.JavaClass;
+import com.tngtech.archunit.core.domain.JavaMethod;
+import com.tngtech.archunit.core.domain.JavaParameterizedType;
+import com.tngtech.archunit.core.domain.JavaType;
+import com.tngtech.archunit.core.domain.properties.HasName;
+import com.tngtech.archunit.lang.ArchCondition;
+import com.tngtech.archunit.lang.ConditionEvents;
+import com.tngtech.archunit.lang.SimpleConditionEvent;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import static 
org.apache.flink.architecture.common.SourcePredicates.isJavaClass;
+
+/** Common conditions for architecture tests. */
+public class Conditions {
+
+    /** Generic condition to check fulfillment of a predicate. */
+    public static <T extends HasName> ArchCondition<T> 
fulfill(DescribedPredicate<T> predicate) {
+        return new ArchCondition<T>(predicate.getDescription()) {
+            @Override
+            public void check(T item, ConditionEvents events) {
+                if (!predicate.apply(item)) {
+                    final String message =
+                            String.format(
+                                    "%s does not satisfy: %s",
+                                    item.getName(), 
predicate.getDescription());
+                    events.add(SimpleConditionEvent.violated(item, message));
+                }
+            }
+        };
+    }
+
+    /**
+     * Tests leaf return types of a method against the given predicate.
+     *
+     * <p>Given some {@link JavaType}, "leaf" types are recursively determined 
as follows:
+     *
+     * <ul>
+     *   <li>If the type is an array type, check its base component type.
+     *   <li>If the type is a generic type, check the type itself and all of 
its type arguments.
+     *   <li>Otherwise, check just the type itself.
+     * </ul>
+     */
+    public static ArchCondition<JavaMethod> haveLeafReturnTypes(

Review comment:
       I like to think that they are tested implicitly by the violations they 
produce (i.e. any change to the rule will inevitably be checked against the 
entire codebase and all frozen violations).
   
   Testing should be fairly easy, though, because you can create any sample 
code you want in a package and run the rule only on that package and assert the 
violations. I'll have to look if they could also be unit-tested, which only 
relies on the ability to instantiate `JavaClass` etc. as mocks.




-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to