/* * Copyright (C) 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.modules.utils.testing; import com.android.modules.utils.testing.AbstractExtendedMockitoRule.AbstractBuilder; import com.android.modules.utils.testing.ExtendedMockitoRule.Builder; import java.lang.annotation.ElementType; import java.lang.annotation.Repeatable; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * Rule to make it easier to use Extended Mockito: * * *

Typical usage: *

 * @Rule
 * public final ExtendedMockitoRule mExtendedMockitoRule = new ExtendedMockitoRule.Builder(this)
 *     .spyStatic(SomeClassWithStaticMethodsToBeMocked)
 *     .build();
 * 
*/ public final class ExtendedMockitoRule extends AbstractExtendedMockitoRule { public ExtendedMockitoRule(Builder builder) { super(builder); } /** * Builder for the rule. */ public static final class Builder extends AbstractBuilder { /** * Constructs a builder for the giving test instance (typically {@code this}) and initialize * mocks on it. */ public Builder(Object testClassInstance) { super(testClassInstance); } /** * Constructs a builder that doesn't initialize mocks. * *

Typically used on test classes that already initialize mocks somewhere else. */ public Builder() { super(); } /** * Builds the rule. */ public ExtendedMockitoRule build() { return new ExtendedMockitoRule(this); } } @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.METHOD, ElementType.TYPE}) @Repeatable(SpyStaticClasses.class) public @interface SpyStatic { Class value(); } @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.METHOD, ElementType.TYPE}) public @interface SpyStaticClasses { SpyStatic[] value(); } @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.METHOD, ElementType.TYPE}) @Repeatable(MockStaticClasses.class) public @interface MockStatic { Class value(); } @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.METHOD, ElementType.TYPE}) public @interface MockStaticClasses { MockStatic[] value(); } }