Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
mutianf committed Dec 9, 2021
1 parent f86251b commit 9cb143a
Showing 1 changed file with 9 additions and 6 deletions.
Expand Up @@ -17,21 +17,24 @@

import com.google.common.truth.Correspondence;
import java.lang.reflect.Method;
import java.util.Arrays;

/**
* A {@link Correspondence} to compare methods names and parameters in different classes. An example
* usage is to make sure a child class is implementing all the methods in the non-abstract parent
* class.
* A {@link Correspondence} to compare methods names, parameters and return types in different
* classes. An example usage is to make sure a child class is implementing all the methods in the
* non-abstract parent class.
*/
public class MethodComparator {

public static final Correspondence<Method, Method> METHOD_CORRESPONDENCE =
Correspondence.from(MethodComparator::compareMethods, "compare method names and parameters");
Correspondence.from(
MethodComparator::compareMethods, "compare method names, parameters and return types");

private static boolean compareMethods(Method actual, Method expected) {
if (!actual.getName().equals(expected.getName())
|| actual.getParameters().equals(expected.getParameters())
|| actual.getModifiers() != expected.getModifiers()) {
|| !Arrays.equals(actual.getParameterTypes(), expected.getParameterTypes())
|| actual.getModifiers() != expected.getModifiers()
|| !actual.getReturnType().equals(expected.getReturnType())) {
return false;
}
return true;
Expand Down

0 comments on commit 9cb143a

Please sign in to comment.