mirror of
https://github.com/alibaba/testable-mock.git
synced 2025-01-27 04:40:25 +08:00
fix: verifier should compare arrays in deep
This commit is contained in:
parent
320ee632b7
commit
30570ae69d
@ -6,6 +6,7 @@ import com.alibaba.testable.core.util.MockContextUtil;
|
||||
import com.alibaba.testable.core.util.TestableUtil;
|
||||
|
||||
import java.security.InvalidParameterException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -145,9 +146,13 @@ public class InvocationVerifier {
|
||||
}
|
||||
|
||||
private boolean matches(Object expectValue, Object realValue) {
|
||||
return expectValue instanceof InvocationMatcher ?
|
||||
((InvocationMatcher) expectValue).matchFunction.check(realValue) :
|
||||
expectValue.equals(realValue);
|
||||
if (expectValue instanceof InvocationMatcher) {
|
||||
return ((InvocationMatcher) expectValue).matchFunction.check(realValue);
|
||||
} else if (expectValue.getClass().isArray() && realValue.getClass().isArray()) {
|
||||
return Arrays.deepEquals((Object[])expectValue, (Object[])realValue);
|
||||
} else {
|
||||
return expectValue.equals(realValue);
|
||||
}
|
||||
}
|
||||
|
||||
private String desc(Object[] args) {
|
||||
|
@ -0,0 +1,47 @@
|
||||
package com.alibaba.testable.core.matcher;
|
||||
|
||||
import com.alibaba.testable.core.tool.OmniConstructor;
|
||||
import com.alibaba.testable.core.tool.PrivateAccessor;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static com.alibaba.testable.core.tool.CollectionTool.listOf;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class InvocationVerifierTest {
|
||||
|
||||
private InvocationVerifier invocationVerifier = OmniConstructor.newInstance(InvocationVerifier.class);
|
||||
|
||||
@Test
|
||||
void should_matches_object() {
|
||||
assertTrue((Boolean)PrivateAccessor.invoke(invocationVerifier, "matches", "abc", "abc"));
|
||||
assertTrue((Boolean)PrivateAccessor.invoke(invocationVerifier, "matches", 1L, 1L));
|
||||
|
||||
assertFalse((Boolean)PrivateAccessor.invoke(invocationVerifier, "matches", "xyz", "abc"));
|
||||
assertFalse((Boolean)PrivateAccessor.invoke(invocationVerifier, "matches", 1L, "abc"));
|
||||
assertFalse((Boolean)PrivateAccessor.invoke(invocationVerifier, "matches", 1L, 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_matches_array() {
|
||||
assertTrue((Boolean)PrivateAccessor.invoke(invocationVerifier, "matches",
|
||||
new String[] {"abc", "xyz"}, new String[] {"abc", "xyz"}));
|
||||
|
||||
assertFalse((Boolean)PrivateAccessor.invoke(invocationVerifier, "matches",
|
||||
new String[] {"abc", "xyz"}, new String[] {"xyz", "abc"}));
|
||||
assertFalse((Boolean)PrivateAccessor.invoke(invocationVerifier, "matches",
|
||||
new String[] {"abc", "xyz"}, new String[] {"xyz"}));
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_matches_matcher() {
|
||||
assertTrue((Boolean)PrivateAccessor.invoke(invocationVerifier, "matches",
|
||||
InvocationMatcher.anyArray(), new String[] {"abc", "xyz"}));
|
||||
assertTrue((Boolean)PrivateAccessor.invoke(invocationVerifier, "matches",
|
||||
InvocationMatcher.anyString(), "abc"));
|
||||
|
||||
assertFalse((Boolean)PrivateAccessor.invoke(invocationVerifier, "matches",
|
||||
InvocationMatcher.anyString(), new String[] {"abc", "xyz"}));
|
||||
assertFalse((Boolean)PrivateAccessor.invoke(invocationVerifier, "matches",
|
||||
InvocationMatcher.anyArray(), "abc"));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user