private OngoingMockInjection(Set<Field> fields, Object fieldOwner) { this.fieldOwner = checkNotNull(fieldOwner, "fieldOwner"); this.fields.addAll(checkItemsNotNull(fields, "fields")); }
/** * Create a new InstanceField. * * @param field The field that should be accessed, note that no checks are performed to ensure * the field belong to this instance class. * @param instance The instance from which the field shall be accessed. */ public InstanceField(Field field, Object instance) { this.field = Checks.checkNotNull(field, "field"); this.instance = Checks.checkNotNull(instance, "instance"); }
/** * Adds the given {@link RunnableAssert}s to this <code>MultithreadingTester</code>, * returns <code>this</code> to allow method chaining. */ public MultithreadingTester add(@Nonnull Collection<RunnableAssert> runnableAsserts) { checkItemsNotNull(runnableAsserts, "runnableAsserts"); this.runnableAsserts.addAll(runnableAsserts); return this; }
public static <T extends Iterable<?>> T checkItemsNotNull(T iterable, String checkedIterable) { checkNotNull(iterable, checkedIterable); for (Object item : iterable) { checkNotNull(item, "item in " + checkedIterable); } return iterable; } }
/** * Adds the given {@link RunnableAssert}s to this <code>MultithreadingTester</code>, * returns <code>this</code> to allow method chaining. */ public MultithreadingTester add(@Nonnull Collection<RunnableAssert> runnableAsserts) { checkItemsNotNull(runnableAsserts, "runnableAsserts"); this.runnableAsserts.addAll(runnableAsserts); return this; }
@Override public MockSettings useConstructor(Object... constructorArgs) { Checks.checkNotNull(constructorArgs, "constructorArgs", "If you need to pass null, please cast it to the right type, e.g.: useConstructor((String) null)"); this.useConstructor = true; this.constructorArgs = constructorArgs; return this; }
private OngoingMockInjection(Set<Field> fields, Object fieldOwner) { this.fieldOwner = checkNotNull(fieldOwner, "fieldOwner"); this.fields.addAll(checkItemsNotNull(fields, "fields")); }
public static <T> T checkNotNull(T value, String checkedValue) { return checkNotNull(value, checkedValue, null); }
private OngoingMockInjection(Set<Field> fields, Object fieldOwner) { this.fieldOwner = checkNotNull(fieldOwner, "fieldOwner"); this.fields.addAll(checkItemsNotNull(fields, "fields")); }
public static <T extends Iterable> T checkItemsNotNull(T iterable, String checkedIterable) { checkNotNull(iterable, checkedIterable); for (Object item : iterable) { checkNotNull(item, "item in " + checkedIterable); } return iterable; } }
/** * Create a new InstanceField. * * @param field The field that should be accessed, note that no checks are performed to ensure * the field belong to this instance class. * @param instance The instance from which the field shall be accessed. */ public InstanceField(Field field, Object instance) { this.field = Checks.checkNotNull(field, "field"); this.instance = Checks.checkNotNull(instance, "instance"); }
public OngoingMockInjection withMocks(Set<Object> mocks) { this.mocks.addAll(checkNotNull(mocks, "mocks")); return this; }
public OngoingMockInjection withMocks(Set<Object> mocks) { this.mocks.addAll(checkNotNull(mocks, "mocks")); return this; }
public boolean isOut(InstanceField instanceField) { Checks.checkNotNull(annotations, "Provide at least one annotation class"); for (Class<? extends Annotation> annotation : annotations) { if(instanceField.isAnnotatedBy(annotation)) { return false; } } return true; } };
private HashSet<HashCodeAndEqualsMockWrapper> asWrappedMocks(Collection<?> mocks) { Checks.checkNotNull(mocks, "Passed collection should notify() be null"); HashSet<HashCodeAndEqualsMockWrapper> hashSet = new HashSet<HashCodeAndEqualsMockWrapper>(); for (Object mock : mocks) { assert ! (mock instanceof HashCodeAndEqualsMockWrapper) : "WRONG"; hashSet.add(HashCodeAndEqualsMockWrapper.of(mock)); } return hashSet; }
private HashSet<HashCodeAndEqualsMockWrapper> asWrappedMocks(Collection<?> mocks) { Checks.checkNotNull(mocks, "Passed collection should notify() be null"); HashSet<HashCodeAndEqualsMockWrapper> hashSet = new HashSet<HashCodeAndEqualsMockWrapper>(); for (Object mock : mocks) { assert ! (mock instanceof HashCodeAndEqualsMockWrapper) : "WRONG"; hashSet.add(HashCodeAndEqualsMockWrapper.of(mock)); } return hashSet; }
public boolean isOut(InstanceField instanceField) { Checks.checkNotNull(annotations, "Provide at least one annotation class"); for (Class<? extends Annotation> annotation : annotations) { if(instanceField.isAnnotatedBy(annotation)) { return false; } } return true; } };
public MockitoFramework addListener(MockitoListener listener) { Checks.checkNotNull(listener, "listener"); mockingProgress().addListener(listener); return this; }
public MockitoFramework removeListener(MockitoListener listener) { Checks.checkNotNull(listener, "listener"); mockingProgress().removeListener(listener); return this; }
/** * Create an new instance of {@link GenericMetadataSupport} inferred from a {@link Type}. * * <p> * At the moment <code>type</code> can only be a {@link Class} or a {@link ParameterizedType}, otherwise * it'll throw a {@link MockitoException}. * </p> * * @param type The class from which the {@link GenericMetadataSupport} should be built. * @return The new {@link GenericMetadataSupport}. * @throws MockitoException Raised if type is not a {@link Class} or a {@link ParameterizedType}. */ public static GenericMetadataSupport inferFrom(Type type) { Checks.checkNotNull(type, "type"); if (type instanceof Class) { return new FromClassGenericMetadataSupport((Class<?>) type); } if (type instanceof ParameterizedType) { return new FromParameterizedTypeGenericMetadataSupport((ParameterizedType) type); } throw new MockitoException("Type meta-data for this Type (" + type.getClass().getCanonicalName() + ") is not supported : " + type); }