mirror of
https://github.com/google/nomulus.git
synced 2025-05-13 07:57:13 +02:00
Migrate away fully from MockitoJUnitRunner
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=192291786
This commit is contained in:
parent
8f1848e32e
commit
183dae6e80
14 changed files with 134 additions and 128 deletions
45
javatests/google/registry/testing/MockitoJUnitRule.java
Normal file
45
javatests/google/registry/testing/MockitoJUnitRule.java
Normal file
|
@ -0,0 +1,45 @@
|
|||
// Copyright 2018 The Nomulus Authors. All Rights Reserved.
|
||||
//
|
||||
// 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 google.registry.testing;
|
||||
|
||||
import org.junit.rules.MethodRule;
|
||||
import org.junit.runners.model.FrameworkMethod;
|
||||
import org.junit.runners.model.Statement;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
/** A rule that initializes Mockito-annotated fields (e.g. mocks and captors). */
|
||||
// TODO(b/77815684): Replace with native version from Mockito v1.10 once we upgrade to that.
|
||||
public class MockitoJUnitRule implements MethodRule {
|
||||
|
||||
public static MockitoJUnitRule create() {
|
||||
return new MockitoJUnitRule();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Statement apply(Statement base, FrameworkMethod method, Object target) {
|
||||
return new Statement() {
|
||||
@Override
|
||||
public void evaluate() throws Throwable {
|
||||
MockitoAnnotations.initMocks(target);
|
||||
try {
|
||||
base.evaluate();
|
||||
} finally {
|
||||
Mockito.validateMockitoUsage();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue