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