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.argumentMatching;
6   
7   import edu.umd.cs.findbugs.annotations.NonNull;
8   import edu.umd.cs.findbugs.annotations.Nullable;
9   
10  import java.util.List;
11  
12  public final class CaptureMatcher<T> implements ArgumentMatcher<CaptureMatcher<T>> {
13      @NonNull
14      private final List<T> valueHolder;
15      @Nullable
16      private Class<?> expectedType;
17  
18      public CaptureMatcher(@NonNull List<T> valueHolder) {
19          this.valueHolder = valueHolder;
20      }
21  
22      public void setExpectedType(@NonNull Class<?> expectedType) {
23          this.expectedType = expectedType;
24      }
25  
26      @Override
27      public boolean same(@NonNull CaptureMatcher<T> other) {
28          return false;
29      }
30  
31      @Override
32      public boolean matches(@Nullable Object argValue) {
33          if (expectedType == null || expectedType.isInstance(argValue)
34                  || argValue == null && !expectedType.isPrimitive()) {
35              // noinspection unchecked
36              valueHolder.add((T) argValue);
37          }
38  
39          return true;
40      }
41  
42      @Override
43      public void writeMismatchPhrase(@NonNull ArgumentMismatch argumentMismatch) {
44      }
45  }