org.mockito.Spy类的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(6.4k)|赞(0)|评价(0)|浏览(151)

本文整理了Java中org.mockito.Spy类的一些代码示例,展示了Spy类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Spy类的具体详情如下:
包路径:org.mockito.Spy
类名称:Spy

Spy介绍

暂无

代码示例

代码示例来源:origin: koral--/android-gif-drawable

@RunWith(RobolectricTestRunner.class)
public class MultiCallbackTest {
  @Mock View view;
  @Spy Drawable drawable;
  private Runnable action;
  private MultiCallback simpleMultiCallback;

代码示例来源:origin: pwittchen/ReactiveNetwork

@RunWith(RobolectricTestRunner.class)
@SuppressWarnings("NullAway") public class DefaultErrorHandlerTest {

 @Rule public MockitoRule rule = MockitoJUnit.rule();
 @Spy private DefaultErrorHandler handler = new DefaultErrorHandler();

 @Test public void shouldHandleErrorDuringClosingSocket() {
  // given
  final String errorMsg = "Could not close the socket";
  final Exception exception = new Exception(errorMsg);

  // when
  handler.handleError(exception, errorMsg);

  // then
  verify(handler, times(1)).handleError(exception, errorMsg);
 }
}

代码示例来源:origin: Netflix/hollow

@Spy
private HollowProducerListener listener;
@Mock
private SingleProducerEnforcer singleProducerEnforcer;

代码示例来源:origin: apache/hive

public MockitoRule a = MockitoJUnit.rule();
@Spy
OpTreeSignatureFactory f = OpTreeSignatureFactory.newCache();

代码示例来源:origin: googleapis/google-cloud-java

@RunWith(MockitoJUnitRunner.class)
public class CollectionReferenceTest {
 @Spy
 private FirestoreImpl firestoreMock =
   new FirestoreImpl(

代码示例来源:origin: i2p/i2p.i2p

public abstract class TaskSchedulerTestBase {

  @Rule
  public MockitoRule rule = MockitoJUnit.rule();

  @Spy protected I2PAppContext context = I2PAppContext.getGlobalContext();
  @Mock protected Clock clock;
  @Mock protected SimpleTimer2 timer;

  protected TaskScheduler scheduler;

  @Before
  public void setUp() {
    when(context.clock()).thenReturn(clock);
    when(context.simpleTimer2()).thenReturn(timer);

    scheduler = createScheduler();
  }

  protected abstract TaskScheduler createScheduler();

  @Test
  public void testAccept_null() {
    assertFalse(scheduler.accept(null));
  }
}

代码示例来源:origin: arquillian/arquillian-graphene

public class TestInstantiation {

  @Spy
  TestingDriverStub executor = new TestingDriverStub();

  @JavaScript
  public interface TestingInterface {
  }

  @Test
  public void factory_should_create_valid_instance_of_given_interface() {
    TestingInterface instance = JSInterfaceFactory.create(GrapheneContext.getContextFor(Default.class), TestingInterface.class);
    assertTrue("instance should implement the provided interface", instance instanceof TestingInterface);
  }

  @JavaScript
  public class InvalidClass {
  }

  @Test(expected = IllegalArgumentException.class)
  public void factory_should_fail_when_class_provided() {
    InvalidClass instance = JSInterfaceFactory.create(GrapheneContext.getContextFor(Default.class), InvalidClass.class);
  }
}

代码示例来源:origin: pwittchen/ReactiveNetwork

@RunWith(RobolectricTestRunner.class)
@SuppressWarnings({ "PMD", "NullAway" }) public class PreLollipopNetworkObservingStrategyTest {
 @Spy private PreLollipopNetworkObservingStrategy strategy =
   new PreLollipopNetworkObservingStrategy();
 @Mock private BroadcastReceiver broadcastReceiver;

代码示例来源:origin: pwittchen/ReactiveNetwork

@RunWith(RobolectricTestRunner.class)
@SuppressWarnings("NullAway") public class LollipopNetworkObservingStrategyTest {
 @Spy private NetworkObservingStrategy strategy = new LollipopNetworkObservingStrategy();

代码示例来源:origin: pedrovgs/Renderers

@Spy private ObjectRenderer renderer;
@Mock private Object mockedContent;
@Mock private LayoutInflater mockedLayoutInflater;
@Mock private ViewGroup mockedParent;
@Mock private View mockedView;

代码示例来源:origin: advanced-android-book/samples

@Spy
private BmiCalculator calculator = new BmiCalculator();

代码示例来源:origin: pwittchen/ReactiveNetwork

@RunWith(RobolectricTestRunner.class)
@SuppressWarnings({ "PMD", "NullAway" }) public class MarshmallowNetworkObservingStrategyTest {
 @Spy private MarshmallowNetworkObservingStrategy strategy =
   new MarshmallowNetworkObservingStrategy();
 @Mock private PowerManager powerManager;
 @Mock private ConnectivityManager connectivityManager;
 @Mock private Context contextMock;
 @Mock private Intent intent;
 @Mock private Network network;
 @Spy private Context context;

代码示例来源:origin: googleapis/google-cloud-java

@RunWith(MockitoJUnitRunner.class)
public class WriteBatchTest {
 @Spy
 private FirestoreImpl firestoreMock =
   new FirestoreImpl(

代码示例来源:origin: openmrs/openmrs-core

@Mock
AdministrationService administrationService;
@Mock
ApplicationContext applicationContext;
@Mock
Context context;
ServiceContext serviceContext;
@Spy
OpenmrsObjectSaveHandler saveHandler;
@Spy
BaseVoidHandler voidHandler;

代码示例来源:origin: entando/entando-core

public class EntandoMessageCodesResolverTest {

  @Spy
  private Map<String, String> validationErrorCodeMapping = new HashMap<>();

  @InjectMocks
  private EntandoMessageCodesResolver messageCodesResolver;

  @Before
  public void setUp() throws Exception {
    validationErrorCodeMapping.put("NotNull", "51");
    validationErrorCodeMapping.put("Size", "52");
    validationErrorCodeMapping.put("Min", "53");
    MockitoAnnotations.initMocks(this);

  }

  @Test
  public void testResolveCode() {
    String[] codes = messageCodesResolver.resolveMessageCodes("Size", "test");
    assertThat(codes[codes.length - 1], is("52"));
  }
}

代码示例来源:origin: pwittchen/ReactiveNetwork

@RunWith(RobolectricTestRunner.class)
@SuppressWarnings({ "PMD", "NullAway" }) public class SocketInternetObservingStrategyTest {
 @Spy private SocketInternetObservingStrategy strategy;
 @Mock private ErrorHandler errorHandler;
 @Mock private Socket socket;

代码示例来源:origin: googleapis/google-cloud-java

@RunWith(MockitoJUnitRunner.class)
public class FirestoreTest {
 @Spy
 private FirestoreImpl firestoreMock =
   new FirestoreImpl(

代码示例来源:origin: org.jbpm/jbpm-console-ng-process-runtime-client

public abstract class BaseProcessDefDetailsMultiPresenterTest {
  @Mock
  PlaceManager placeManager;
  @Spy
  Event<ChangeTitleWidgetEvent> changeTitleWidgetEvent = new EventSourceMock<ChangeTitleWidgetEvent>();

代码示例来源:origin: bonigarcia/mastering-junit5

@ExtendWith(MockitoExtension.class)
class LoginServiceSpyTest {

  @InjectMocks
  LoginService loginService;

  @Spy
  LoginRepository loginRepository;

  UserForm userOk = new UserForm("user1", "p1");
  UserForm userKo = new UserForm("foo", "bar");

  @Test
  void testLoginOk() {
    assertTrue(loginService.login(userOk));
  }

  @Test
  void testLoginKo() {
    assertFalse(loginService.login(userKo));
  }

}

代码示例来源:origin: pwittchen/ReactiveNetwork

@RunWith(RobolectricTestRunner.class)
@SuppressWarnings("NullAway") public class WalledGardenInternetObservingStrategyTest {
 @Spy private WalledGardenInternetObservingStrategy strategy;
 @Mock private ErrorHandler errorHandler;

相关文章

Spy类方法