org.mockito.Mockito.nullable()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(13.0k)|赞(0)|评价(0)|浏览(254)

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

Mockito.nullable介绍

暂无

代码示例

代码示例来源:origin: gocd/gocd

@Test
public void shouldCallMigratorForEveryVersionFromTheProvidedOneToTheLatest() throws Exception {
  handler.responseMessageForParseDirectory("{ \"target_version\": \"0\", \"something\": \"value\" }");
  verify(configRepoMigrator).migrate(anyString(), eq(1));
  verify(configRepoMigrator).migrate(nullable(String.class), eq(2));
  verify(configRepoMigrator, times(JsonMessageHandler1_0.CURRENT_CONTRACT_VERSION)).migrate(nullable(String.class), anyInt());
}

代码示例来源:origin: gocd/gocd

@Test
public void shouldExecuteTheTask() {
  ActionWithReturn actionWithReturn = mock(ActionWithReturn.class);
  when(actionWithReturn.execute(any(JsonBasedPluggableTask.class), nullable(GoPluginDescriptor.class))).thenReturn(ExecutionResult.success("yay"));
  ExecutionResult executionResult = extension.execute(pluginId, actionWithReturn);
  verify(actionWithReturn).execute(any(JsonBasedPluggableTask.class), nullable(GoPluginDescriptor.class));
  assertThat(executionResult.getMessagesForDisplay(), is("yay"));
  assertTrue(executionResult.isSuccessful());
}

代码示例来源:origin: blurpy/kouchat-android

@Test
public void savePropertiesShouldFlushAndCloseWriterEvenOnException() {
  final File filePath = getPathTo("");
  try {
    propertyTools.saveProperties(filePath.getAbsolutePath(), new Properties(), null);
    fail("Should fail to save properties");
  }
  catch (final IOException e) {
    verify(ioTools).flush(nullable(FileWriter.class));
    verify(ioTools).close(nullable(FileWriter.class));
  }
}

代码示例来源:origin: EvoSuite/evosuite

} else {
  GenericClass gc = new GenericClass(type);
  return Mockito.nullable(gc.getRawClass());

代码示例来源:origin: MegaMek/mekhq

private void initCampaign(){
    mockCampaign = Mockito.mock(Campaign.class);

    CampaignOptions mockCampaignOptions = Mockito.mock(CampaignOptions.class);
    Mockito.when(mockCampaignOptions.usePeacetimeCost()).thenReturn(true);
    Mockito.when(mockCampaignOptions.getUnitRatingMethod()).thenReturn(mekhq.campaign.rating.UnitRatingMethod.CAMPAIGN_OPS);

    JumpPath mockJumpPath = Mockito.mock(JumpPath.class);
    Mockito.when(mockJumpPath.getJumps()).thenReturn(2);

    Mockito.when(mockCampaign.calculateJumpPath(Mockito.nullable(Planet.class), Mockito.nullable(Planet.class))).thenReturn(mockJumpPath);
    Mockito.when(mockCampaign.calculateCostPerJump(Mockito.anyBoolean(), Mockito.anyBoolean())).thenReturn((long) 5);
    Mockito.when(mockCampaign.getUnitRatingMod()).thenReturn(10);

    Mockito.when(mockCampaign.getOverheadExpenses()).thenReturn((long) 1);
    Mockito.when(mockCampaign.getContractBase()).thenReturn((long) 10);
    Mockito.when(mockCampaign.getCampaignOptions()).thenReturn(mockCampaignOptions);
    Mockito.when(mockCampaign.getPeacetimeCost()).thenReturn(1L);
    Mockito.when(mockCampaign.getCalendar()).thenReturn(new GregorianCalendar(3067, Calendar.JANUARY, 1));
  }
}

代码示例来源:origin: apache/calcite-avatica

@Test public void noPreviousContextOnLogin() throws Exception {
 KerberosConnection krbUtil = mock(KerberosConnection.class);
 Subject subject = new Subject();
 Subject loggedInSubject = new Subject();
 Configuration conf = mock(Configuration.class);
 LoginContext context = mock(LoginContext.class);
 // Call the real login(LoginContext, Configuration, Subject) method
 when(krbUtil.login(nullable(LoginContext.class), any(Configuration.class), any(Subject.class)))
   .thenCallRealMethod();
 // Return a fake LoginContext
 when(krbUtil.createLoginContext(conf)).thenReturn(context);
 // Return a fake Subject from that fake LoginContext
 when(context.getSubject()).thenReturn(loggedInSubject);
 Entry<LoginContext, Subject> pair = krbUtil.login(null, conf, subject);
 // Verify we get the fake LoginContext and Subject
 assertEquals(context, pair.getKey());
 assertEquals(loggedInSubject, pair.getValue());
 // login should be called on the LoginContext
 verify(context).login();
}

代码示例来源:origin: org.apache.calcite.avatica/avatica-core

@Test public void noPreviousContextOnLogin() throws Exception {
 KerberosConnection krbUtil = mock(KerberosConnection.class);
 Subject subject = new Subject();
 Subject loggedInSubject = new Subject();
 Configuration conf = mock(Configuration.class);
 LoginContext context = mock(LoginContext.class);
 // Call the real login(LoginContext, Configuration, Subject) method
 when(krbUtil.login(nullable(LoginContext.class), any(Configuration.class), any(Subject.class)))
   .thenCallRealMethod();
 // Return a fake LoginContext
 when(krbUtil.createLoginContext(conf)).thenReturn(context);
 // Return a fake Subject from that fake LoginContext
 when(context.getSubject()).thenReturn(loggedInSubject);
 Entry<LoginContext, Subject> pair = krbUtil.login(null, conf, subject);
 // Verify we get the fake LoginContext and Subject
 assertEquals(context, pair.getKey());
 assertEquals(loggedInSubject, pair.getValue());
 // login should be called on the LoginContext
 verify(context).login();
}

代码示例来源:origin: blurpy/kouchat-android

@Test
public void currentDateToStringShouldUseDateToStringWithNull() {
  when(dateTools.dateToString(nullable(Date.class), anyString())).thenReturn("the date");
  final String dateAsString = dateTools.currentDateToString("EEEE, d MMMM yyyy");
  assertEquals("the date", dateAsString);
  verify(dateTools).dateToString(null, "EEEE, d MMMM yyyy");
}

代码示例来源:origin: blurpy/kouchat-android

@Test
public void loadPropertiesShouldCloseInputStreamEvenOnException() {
  try {
    propertyTools.loadProperties("nothing");
    fail("Should fail to load properties");
  }
  catch (final IOException e) {
    verify(ioTools).close(nullable(InputStream.class));
  }
}

代码示例来源:origin: org.apache.calcite.avatica/avatica-core

@Test public void testFailedResponseSerialization() throws IOException {
 @SuppressWarnings("unchecked")
 final AbstractHandler<String> handler = Mockito.mock(AbstractHandler.class);
 final Request request = Mockito.mock(Request.class);
 final Response response = Mockito.mock(Response.class);
 final IOException exception = new IOException();
 final ErrorResponse errorResponse = Mockito.mock(ErrorResponse.class);
 final String serializedErrorResponse = "An ErrorResponse";
 // Accept a serialized request
 Mockito.when(handler.apply(Mockito.anyString())).thenCallRealMethod();
 // Deserialize it back into a POJO
 Mockito.when(handler.decode(Mockito.anyString())).thenReturn(request);
 // Construct the Response for that Request
 Mockito.when(request.accept(Mockito.nullable(Service.class))).thenReturn(response);
 // Throw an IOException when serializing the Response.
 Mockito.when(handler.encode(response)).thenThrow(exception);
 Mockito.when(handler.convertToErrorResponse(exception)).thenCallRealMethod();
 // Convert the IOException into an ErrorResponse
 Mockito.when(handler.unwrapException(exception)).thenReturn(errorResponse);
 Mockito.when(handler.encode(errorResponse)).thenReturn(serializedErrorResponse);
 HandlerResponse<String> handlerResp = handler.apply("this is mocked out");
 assertEquals(500, handlerResp.getStatusCode());
 assertEquals(serializedErrorResponse, handlerResp.getResponse());
}

代码示例来源:origin: apache/calcite-avatica

@Test public void testFailedResponseSerialization() throws IOException {
 @SuppressWarnings("unchecked")
 final AbstractHandler<String> handler = Mockito.mock(AbstractHandler.class);
 final Request request = Mockito.mock(Request.class);
 final Response response = Mockito.mock(Response.class);
 final IOException exception = new IOException();
 final ErrorResponse errorResponse = Mockito.mock(ErrorResponse.class);
 final String serializedErrorResponse = "An ErrorResponse";
 // Accept a serialized request
 Mockito.when(handler.apply(Mockito.anyString())).thenCallRealMethod();
 // Deserialize it back into a POJO
 Mockito.when(handler.decode(Mockito.anyString())).thenReturn(request);
 // Construct the Response for that Request
 Mockito.when(request.accept(Mockito.nullable(Service.class))).thenReturn(response);
 // Throw an IOException when serializing the Response.
 Mockito.when(handler.encode(response)).thenThrow(exception);
 Mockito.when(handler.convertToErrorResponse(exception)).thenCallRealMethod();
 // Convert the IOException into an ErrorResponse
 Mockito.when(handler.unwrapException(exception)).thenReturn(errorResponse);
 Mockito.when(handler.encode(errorResponse)).thenReturn(serializedErrorResponse);
 HandlerResponse<String> handlerResp = handler.apply("this is mocked out");
 assertEquals(500, handlerResp.getStatusCode());
 assertEquals(serializedErrorResponse, handlerResp.getResponse());
}

代码示例来源:origin: MegaMek/megamek

Mockito.nullable(LogLevel.class),
Mockito.anyString(),
Mockito.anyInt());

代码示例来源:origin: MegaMek/mekhq

Mockito.when(testCampaign.getTechs()).thenCallRealMethod();
Mockito.when(testCampaign.getTechs(Mockito.anyBoolean())).thenCallRealMethod();
Mockito.when(testCampaign.getTechs(Mockito.anyBoolean(), Mockito.nullable(UUID.class), Mockito.anyBoolean(), Mockito.anyBoolean())).thenCallRealMethod();
Mockito.when(testCampaign.getPerson(Mockito.eq(testId))).thenReturn(mockTechActiveTwo);

代码示例来源:origin: MegaMek/megamek

Mockito.doReturn(10.0).when(testRanker).getMaxDamageAtRange(Mockito.nullable(FireControl.class),
                              Mockito.eq(mockMyUnit), Mockito.anyInt(),
                              Mockito.anyBoolean(), Mockito.anyBoolean());
Mockito.doReturn(8.5)
    .when(testRanker)
    .getMaxDamageAtRange(Mockito.nullable(FireControl.class), Mockito.eq(mockEnemyMech), Mockito.anyInt(),
              Mockito.anyBoolean(), Mockito.anyBoolean());
Mockito.doReturn(false)
Mockito.doReturn(8.5)
    .when(testRanker)
    .getMaxDamageAtRange(Mockito.nullable(FireControl.class), Mockito.eq(mockEnemyMech), Mockito.anyInt(),
              Mockito.anyBoolean(), Mockito.anyBoolean());
Mockito.doReturn(false)
Mockito.doReturn(8.5)
    .when(testRanker)
    .getMaxDamageAtRange(Mockito.nullable(FireControl.class), Mockito.eq(mockEnemyMech), Mockito.anyInt(),
              Mockito.anyBoolean(), Mockito.anyBoolean());
Mockito.doReturn(true)

代码示例来源:origin: MegaMek/megamek

.when(testFireControl)
    .getAttackerMovementModifier(Mockito.any(IGame.class), Mockito.anyInt(),
                  Mockito.nullable(EntityMovementType.class));
Mockito.doReturn(mockTargetMoveMod)
    .when(testFireControl)

代码示例来源:origin: MegaMek/megamek

.distanceToClosestEnemy(Mockito.any(Entity.class), Mockito.nullable(Coords.class),
                   Mockito.nullable(IGame.class)))
.thenReturn(10.0);

代码示例来源:origin: MegaMek/megamek

Mockito.doReturn(3)
    .when(boardCenter)
    .direction(Mockito.nullable(Coords.class));
Mockito.doReturn(3)
    .when(enemyMech1Position)
    .direction(Mockito.nullable(Coords.class));
final Entity mockEnemyMech1 = Mockito.mock(BipedMech.class);
Mockito.when(mockEnemyMech1.isOffBoard()).thenReturn(false);
Mockito.doReturn(mockEnemyMech1)
    .when(testRanker)
    .findClosestEnemy(Mockito.eq(mockMover), Mockito.nullable(Coords.class), Mockito.any(IGame.class));
    .distanceToHomeEdge(Mockito.nullable(Coords.class), Mockito.any(CardinalEdge.class), Mockito.any(IGame.class));
Mockito.when(mockPrincess.wantsToFallBack(Mockito.eq(mockMover))).thenReturn(false);
Mockito.when(mockMover.isCrippled()).thenReturn(false);
    .findClosestEnemy(Mockito.eq(mockMover), Mockito.nullable(Coords.class), Mockito.any(IGame.class));
expected = new RankedPath(-51.25, mockPath, "Calculation: " +
                      "{fall mod [" + LOG_DECIMAL.format(0) + " = " + LOG_DECIMAL
Mockito.doReturn(mockEnemyMech1)
    .when(testRanker)
    .findClosestEnemy(Mockito.eq(mockMover), Mockito.nullable(Coords.class), Mockito.any(IGame.class));

代码示例来源:origin: apache/calcite-avatica

@Test public void testHostnameVerification() throws Exception {
  AvaticaCommonsHttpClientImpl client = mock(AvaticaCommonsHttpClientImpl.class);
  // Call the real method
  when(client.getHostnameVerifier(nullable(HostnameVerification.class)))
    .thenCallRealMethod();

  // No verification should give the default (strict) verifier
  HostnameVerifier actualVerifier = client.getHostnameVerifier(null);
  assertNotNull(actualVerifier);
  assertTrue(actualVerifier instanceof DefaultHostnameVerifier);

  actualVerifier = client.getHostnameVerifier(HostnameVerification.STRICT);
  assertNotNull(actualVerifier);
  assertTrue(actualVerifier instanceof DefaultHostnameVerifier);

  actualVerifier = client.getHostnameVerifier(HostnameVerification.NONE);
  assertNotNull(actualVerifier);
  assertTrue(actualVerifier instanceof NoopHostnameVerifier);
 }
}

代码示例来源:origin: org.apache.calcite.avatica/avatica-core

@Test public void testHostnameVerification() throws Exception {
  AvaticaCommonsHttpClientImpl client = mock(AvaticaCommonsHttpClientImpl.class);
  // Call the real method
  when(client.getHostnameVerifier(nullable(HostnameVerification.class)))
    .thenCallRealMethod();

  // No verification should give the default (strict) verifier
  HostnameVerifier actualVerifier = client.getHostnameVerifier(null);
  assertNotNull(actualVerifier);
  assertTrue(actualVerifier instanceof DefaultHostnameVerifier);

  actualVerifier = client.getHostnameVerifier(HostnameVerification.STRICT);
  assertNotNull(actualVerifier);
  assertTrue(actualVerifier instanceof DefaultHostnameVerifier);

  actualVerifier = client.getHostnameVerifier(HostnameVerification.NONE);
  assertNotNull(actualVerifier);
  assertTrue(actualVerifier instanceof NoopHostnameVerifier);
 }
}

代码示例来源:origin: MegaMek/megamek

testPhysicalInfo.setTarget(mockTarget);
Mockito.doNothing().when(testPhysicalInfo).setDamageDirection(Mockito.any(EntityState.class),
                               Mockito.nullable(Coords.class));
Mockito.doReturn(1).when(testPhysicalInfo).getDamageDirection();

相关文章