|
|
|
|
@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
|
|
|
|
|
/* |
|
|
|
|
* Copyright 2002-2020 the original author or authors. |
|
|
|
|
* Copyright 2002-2023 the original author or authors. |
|
|
|
|
* |
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
|
@ -28,6 +28,7 @@ import org.springframework.core.testfixture.io.SerializationTestUtils;
@@ -28,6 +28,7 @@ import org.springframework.core.testfixture.io.SerializationTestUtils;
|
|
|
|
|
import org.springframework.lang.Nullable; |
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
|
import static org.mockito.Mockito.mock; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @author Juergen Hoeller |
|
|
|
|
@ -35,6 +36,8 @@ import static org.assertj.core.api.Assertions.assertThat;
@@ -35,6 +36,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
|
*/ |
|
|
|
|
public class MethodMatchersTests { |
|
|
|
|
|
|
|
|
|
private final static Method TEST_METHOD = mock(Method.class); |
|
|
|
|
|
|
|
|
|
private final Method EXCEPTION_GETMESSAGE; |
|
|
|
|
|
|
|
|
|
private final Method ITESTBEAN_SETAGE; |
|
|
|
|
@ -111,6 +114,65 @@ public class MethodMatchersTests {
@@ -111,6 +114,65 @@ public class MethodMatchersTests {
|
|
|
|
|
assertThat(second.equals(first)).isTrue(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void negateMethodMatcher() { |
|
|
|
|
MethodMatcher getterMatcher = new StartsWithMatcher("get"); |
|
|
|
|
MethodMatcher negate = MethodMatchers.negate(getterMatcher); |
|
|
|
|
assertThat(negate.matches(ITESTBEAN_SETAGE, int.class)).isTrue(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void negateTrueMethodMatcher() { |
|
|
|
|
MethodMatcher negate = MethodMatchers.negate(MethodMatcher.TRUE); |
|
|
|
|
assertThat(negate.matches(TEST_METHOD, String.class)).isFalse(); |
|
|
|
|
assertThat(negate.matches(TEST_METHOD, Object.class)).isFalse(); |
|
|
|
|
assertThat(negate.matches(TEST_METHOD, Integer.class)).isFalse(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void negateTrueMethodMatcherAppliedTwice() { |
|
|
|
|
MethodMatcher negate = MethodMatchers.negate(MethodMatchers.negate(MethodMatcher.TRUE)); |
|
|
|
|
assertThat(negate.matches(TEST_METHOD, String.class)).isTrue(); |
|
|
|
|
assertThat(negate.matches(TEST_METHOD, Object.class)).isTrue(); |
|
|
|
|
assertThat(negate.matches(TEST_METHOD, Integer.class)).isTrue(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void negateIsNotEqualsToOriginalMatcher() { |
|
|
|
|
MethodMatcher original = MethodMatcher.TRUE; |
|
|
|
|
MethodMatcher negate = MethodMatchers.negate(original); |
|
|
|
|
assertThat(original).isNotEqualTo(negate); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void negateOnSameMatcherIsEquals() { |
|
|
|
|
MethodMatcher original = MethodMatcher.TRUE; |
|
|
|
|
MethodMatcher first = MethodMatchers.negate(original); |
|
|
|
|
MethodMatcher second = MethodMatchers.negate(original); |
|
|
|
|
assertThat(first).isEqualTo(second); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void negateHasNotSameHashCodeAsOriginalMatcher() { |
|
|
|
|
MethodMatcher original = MethodMatcher.TRUE; |
|
|
|
|
MethodMatcher negate = MethodMatchers.negate(original); |
|
|
|
|
assertThat(original).doesNotHaveSameHashCodeAs(negate); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void negateOnSameMatcherHasSameHashCode() { |
|
|
|
|
MethodMatcher original = MethodMatcher.TRUE; |
|
|
|
|
MethodMatcher first = MethodMatchers.negate(original); |
|
|
|
|
MethodMatcher second = MethodMatchers.negate(original); |
|
|
|
|
assertThat(first).hasSameHashCodeAs(second); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void toStringIncludesRepresentationOfOriginalMatcher() { |
|
|
|
|
MethodMatcher original = MethodMatcher.TRUE; |
|
|
|
|
assertThat(MethodMatchers.negate(original)).hasToString("Negate " + original); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static class StartsWithMatcher extends StaticMethodMatcher { |
|
|
|
|
|
|
|
|
|
|