View Javadoc
1   /*
2    * Copyright (c) 2006 JMockit developers
3    * This file is subject to the terms of the MIT license (see LICENSE.txt).
4    */
5   package mockit.internal.expectations.invocation;
6   
7   import edu.umd.cs.findbugs.annotations.NonNull;
8   
9   import java.util.Map;
10  
11  import mockit.internal.expectations.argumentMatching.ArgumentMatcher;
12  import mockit.internal.expectations.argumentMatching.EqualityMatcher;
13  import mockit.internal.expectations.argumentMatching.LenientEqualityMatcher;
14  
15  final class ArgumentValuesAndMatchersWithoutVarargs extends ArgumentValuesAndMatchers {
16      ArgumentValuesAndMatchersWithoutVarargs(@NonNull InvocationArguments signature, @NonNull Object[] values) {
17          super(signature, values);
18      }
19  
20      @Override
21      boolean isMatch(@NonNull Object[] replayArgs, @NonNull Map<Object, Object> instanceMap) {
22          if (matchers == null) {
23              return areEqual(values, replayArgs, replayArgs.length, instanceMap);
24          }
25  
26          for (int i = 0; i < replayArgs.length; i++) {
27              Object actual = replayArgs[i];
28              ArgumentMatcher<?> expected = getArgumentMatcher(i);
29  
30              if (expected == null) {
31                  Object arg = values[i];
32                  if (arg == null) {
33                      continue;
34                  }
35                  expected = new LenientEqualityMatcher(arg, instanceMap);
36              }
37  
38              if (!expected.matches(actual)) {
39                  return false;
40              }
41          }
42  
43          return true;
44      }
45  
46      @Override
47      boolean hasEquivalentMatchers(@NonNull ArgumentValuesAndMatchers other) {
48          @SuppressWarnings("unchecked")
49          int i = indexOfFirstValueAfterEquivalentMatchers(other);
50  
51          if (i < 0) {
52              return false;
53          }
54  
55          while (i < values.length) {
56              if (!EqualityMatcher.areEqual(values[i], other.values[i])) {
57                  return false;
58              }
59  
60              i++;
61          }
62  
63          return true;
64      }
65  }