本文整理汇总了Java中org.mockito.AdditionalAnswers类的典型用法代码示例。如果您正苦于以下问题:Java AdditionalAnswers类的具体用法?Java AdditionalAnswers怎么用?Java AdditionalAnswers使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AdditionalAnswers类属于org.mockito包,在下文中一共展示了AdditionalAnswers类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setUp
import org.mockito.AdditionalAnswers; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
configureForThemes();
configureForUIThread();
mMockContext = mock(Context.class, AdditionalAnswers.delegatesTo(getContext()));
doReturn(InstrumentationRegistry.getTargetContext().getMainLooper())
.when(mMockContext).getMainLooper();
mHelper = new WorkspaceHelper(mMockContext);
mViewFactory = new TestableBlockViewFactory(mMockContext, mHelper);
mController = new BlocklyController.Builder(mMockContext)
.setWorkspaceHelper(mHelper)
.setBlockViewFactory(mViewFactory)
.addBlockDefinitionsFromAsset("default/test_blocks.json")
.build();
mController.addCallback(mCallback);
mController.setVariableCallback(mVariableCallback);
mBlockFactory = mController.getBlockFactory();
mWorkspace = mController.getWorkspace();
mConnectionManager = mController.getWorkspace().getConnectionManager();
mWorkspaceView = new WorkspaceView(getContext());
}
示例2: update
import org.mockito.AdditionalAnswers; //导入依赖的package包/类
@Test
public void update() throws Exception {
// data
String id = UUID.randomUUID().toString();
int ratingAdjustment = 32;
int newGames = 1;
int newWins = 1;
int newLosses = 0;
PlayerRecord existingRecord = PlayerRecord.builder()
.id(id)
.currentRating(1200)
.gamesPlayed(1)
.wins(1)
.losses(0)
.build();
// mocks
PlayerDao playerDao = Mockito.mock(PlayerDao.class);
Mockito.when(playerDao.update(Mockito.any(PlayerRecord.class))).then(AdditionalAnswers.returnsFirstArg());
Mockito.when(playerDao.findOne(id)).thenReturn(existingRecord);
PlayerService instance = new PlayerService(playerDao);
Player updated = instance.update(id, ratingAdjustment, newGames, newWins, newLosses);
Assert.assertEquals(existingRecord.getCurrentRating() + ratingAdjustment, updated.getCurrentRating());
}
示例3: setUp
import org.mockito.AdditionalAnswers; //导入依赖的package包/类
@Before
public void setUp() throws CoreException {
when(launchConfiguration.getAttribute(anyString(), anyString()))
.thenAnswer(AdditionalAnswers.returnsSecondArg());
when(launchConfiguration.getAttribute(anyString(), anyInt()))
.thenAnswer(AdditionalAnswers.returnsSecondArg());
when(launchConfiguration.getAttribute(anyString(), anyBoolean()))
.thenAnswer(AdditionalAnswers.returnsSecondArg());
when(server.getAttribute(anyString(), anyString()))
.thenAnswer(AdditionalAnswers.returnsSecondArg());
when(server.getAttribute(anyString(), anyInt()))
.thenAnswer(AdditionalAnswers.returnsSecondArg());
when(server.getAttribute(anyString(), anyBoolean()))
.thenAnswer(AdditionalAnswers.returnsSecondArg());
when(server.loadAdapter(any(Class.class), any(IProgressMonitor.class)))
.thenReturn(serverBehavior);
}
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-eclipse,代码行数:19,代码来源:LocalAppEngineServerLaunchConfigurationDelegateTest.java
示例4: testGenerateRunConfiguration
import org.mockito.AdditionalAnswers; //导入依赖的package包/类
@Test
public void testGenerateRunConfiguration() throws CoreException {
when(launchConfiguration.getAttribute(anyString(), anyString()))
.thenAnswer(AdditionalAnswers.returnsSecondArg());
when(launchConfiguration.getAttribute(anyString(), anyInt()))
.thenAnswer(AdditionalAnswers.returnsSecondArg());
when(server.getAttribute(anyString(), anyString()))
.thenAnswer(AdditionalAnswers.returnsSecondArg());
when(server.getAttribute(anyString(), anyInt()))
.thenAnswer(AdditionalAnswers.returnsSecondArg());
DefaultRunConfiguration config = new LocalAppEngineServerLaunchConfigurationDelegate()
.generateServerRunConfiguration(launchConfiguration, server, ILaunchManager.RUN_MODE);
assertNull(config.getHost());
assertEquals((Integer) LocalAppEngineServerBehaviour.DEFAULT_SERVER_PORT, config.getPort());
assertNull(config.getApiPort());
assertNull(config.getJvmFlags());
verify(server, atLeastOnce()).getHost();
verify(launchConfiguration, atLeastOnce()).getAttribute(anyString(), anyInt());
verify(server, atLeastOnce()).getAttribute(anyString(), anyInt());
}
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-eclipse,代码行数:22,代码来源:LocalAppEngineServerLaunchConfigurationDelegateTest.java
示例5: testGenerateRunConfiguration_withServerPort
import org.mockito.AdditionalAnswers; //导入依赖的package包/类
@Test
public void testGenerateRunConfiguration_withServerPort() throws CoreException {
when(launchConfiguration.getAttribute(anyString(), anyString()))
.thenAnswer(AdditionalAnswers.returnsSecondArg());
when(launchConfiguration
.getAttribute(eq(LocalAppEngineServerBehaviour.SERVER_PORT_ATTRIBUTE_NAME), anyInt()))
.thenReturn(9999);
DefaultRunConfiguration config = new LocalAppEngineServerLaunchConfigurationDelegate()
.generateServerRunConfiguration(launchConfiguration, server, ILaunchManager.RUN_MODE);
assertNotNull(config.getPort());
assertEquals(9999, (int) config.getPort());
verify(launchConfiguration)
.getAttribute(eq(LocalAppEngineServerBehaviour.SERVER_PORT_ATTRIBUTE_NAME), anyInt());
verify(server, never()).getAttribute(anyString(), anyInt());
}
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-eclipse,代码行数:18,代码来源:LocalAppEngineServerLaunchConfigurationDelegateTest.java
示例6: testGenerateRunConfiguration_withAdminPortWhenDevAppserver2
import org.mockito.AdditionalAnswers; //导入依赖的package包/类
@Test
public void testGenerateRunConfiguration_withAdminPortWhenDevAppserver2() throws CoreException {
Assume.assumeTrue(LocalAppEngineServerLaunchConfigurationDelegate.DEV_APPSERVER2);
when(launchConfiguration.getAttribute(anyString(), anyString()))
.thenAnswer(AdditionalAnswers.returnsSecondArg());
when(launchConfiguration
.getAttribute(eq(LocalAppEngineServerBehaviour.ADMIN_PORT_ATTRIBUTE_NAME), anyInt()))
.thenReturn(9999);
DefaultRunConfiguration config = new LocalAppEngineServerLaunchConfigurationDelegate()
.generateServerRunConfiguration(launchConfiguration, server, ILaunchManager.RUN_MODE);
assertNull(config.getAdminPort());
verify(launchConfiguration, never())
.getAttribute(eq(LocalAppEngineServerBehaviour.ADMIN_PORT_ATTRIBUTE_NAME), anyInt());
verify(server, never())
.getAttribute(eq(LocalAppEngineServerBehaviour.ADMIN_PORT_ATTRIBUTE_NAME), anyInt());
}
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-eclipse,代码行数:20,代码来源:LocalAppEngineServerLaunchConfigurationDelegateTest.java
示例7: registrationShouldWork
import org.mockito.AdditionalAnswers; //导入依赖的package包/类
@Test
public void registrationShouldWork() {
final RegistrationService service = new RegistrationService(eventRepository, registrationRepository, mailSender, null, messageSource, "[email protected]");
final EventEntity event = mock(EventEntity.class);
when(event.isNeedsRegistration()).thenReturn(true);
when(event.isOpenForRegistration()).thenReturn(true);
when(this.eventRepository.findOne(23)).thenReturn(Optional.of(event));
when(this.registrationRepository.findByEventAndEmail(event, "[email protected]")).thenReturn(Optional.empty());
when(this.registrationRepository.save(any(RegistrationEntity.class))).thenAnswer(AdditionalAnswers.returnsFirstArg());
final Registration registration = new Registration();
registration.setFirstName("Michael");
registration.setName("Simons");
registration.setEmail("[email protected]");
final RegistrationEntity registrationEntity = service.register(23, registration);
assertThat(registrationEntity.getEvent(), is(event));
assertThat(registrationEntity.getFirstName(), is(registration.getFirstName()));
assertThat(registrationEntity.getName(), is(registration.getName()));
assertThat(registrationEntity.getEmail(), is(registration.getEmail()));
verify(this.eventRepository).findOne(23);
verify(this.registrationRepository).findByEventAndEmail(event, "[email protected]");
verify(this.registrationRepository).save(any(RegistrationEntity.class));
verifyNoMoreInteractions(this.eventRepository, this.registrationRepository);
}
示例8: initSpyOnWaitFunction
import org.mockito.AdditionalAnswers; //导入依赖的package包/类
/**
* Creates spy on wait function. Spy won't wait and the system time returned will be build from
* the given used time millis. So you only need to specify how long each call to the system will
* take.
*
* @param configuredProbe probe to configure wait function for
* @param usedTimeMillis array of used times in milliseconds
*/
private void initSpyOnWaitFunction(
ProbeBuilderImpl<SystemUnderTest_SUT, SystemState> configuredProbe,
Iterable<Long> usedTimeMillis) {
final List<Long> timeMillis = ConcurrentTestUtil.getTimeMillis(usedTimeMillis);
configuredProbe.preProcessWaitFunction(
new Function<Function<SystemUnderTest_SUT, SystemState>, Function<SystemUnderTest_SUT, SystemState>>() {
@Override
public Function<SystemUnderTest_SUT, SystemState> apply(
Function<SystemUnderTest_SUT, SystemState> input) {
WaitFunction<SystemUnderTest_SUT, SystemState> spy =
(WaitFunction<SystemUnderTest_SUT, SystemState>) Mockito.spy(input);
try {
Mockito.doNothing().when(spy).sleep(anyLong());
Mockito.doAnswer(
AdditionalAnswers.returnsElementsOf(timeMillis)).when(spy).nowMillis();
} catch (InterruptedException ignored) {
}
waitFunction = spy;
return spy;
}
});
}
示例9: setup
import org.mockito.AdditionalAnswers; //导入依赖的package包/类
@Before
public void setup() {
commercialUsageResource = new CommercialUsageResource();
commercialUsageResource.affiliateRepository = affiliateRepository;
commercialUsageResource.authorizationChecker = authorizationChecker;
commercialUsageResource.commercialUsageRepository = commercialUsageRepository;
commercialUsageResource.commercialUsageAuditEvents = commercialUsageAuditEvents;
commercialUsageResource.commercialUsageResetter = commercialUsageResetter;
this.restCommercialUsageResource = MockMvcBuilders
.standaloneSetup(commercialUsageResource)
.setMessageConverters(new MockMvcJacksonTestSupport().getConfiguredMessageConverters())
.build();
Mockito.when(commercialUsageRepository.save(Mockito.any(CommercialUsage.class))).then(AdditionalAnswers.returnsFirstArg());
Mockito.when(commercialUsageRepository.saveAndFlush(Mockito.any(CommercialUsage.class))).then(AdditionalAnswers.returnsFirstArg());
withCommercialUsageResetter();
affiliate = new Affiliate(1L);
affiliate.setType(AffiliateType.COMMERCIAL);
Mockito.when(affiliateRepository.findOne(affiliate.getAffiliateId())).thenReturn(affiliate);
}
示例10: create
import org.mockito.AdditionalAnswers; //导入依赖的package包/类
@Test
public void create() throws Exception {
PlayerDao playerDao = Mockito.mock(PlayerDao.class);
Mockito.when(playerDao.create(Mockito.any(PlayerRecord.class))).then(AdditionalAnswers.returnsFirstArg());
Player toCreate = Player.builder()
.userId(UUID.randomUUID().toString())
.build();
PlayerService instance = new PlayerService(playerDao);
Player created = instance.create(toCreate);
Assert.assertEquals("user id is saved", toCreate.getUserId(), created.getUserId());
Assert.assertNotNull("id is generated", created.getId());
}
示例11: setMockClientReturnStatusCode
import org.mockito.AdditionalAnswers; //导入依赖的package包/类
private void setMockClientReturnStatusCode(int [] returnStatusCodes) throws Exception {
List<ListenableFuture> futures = new ArrayList<>();
for (int returnStatusCode: returnStatusCodes) {
com.ning.http.client.Response response = mock(com.ning.http.client.Response.class);
when(response.getStatusCode()).thenReturn(returnStatusCode);
ListenableFuture future = mock(ListenableFuture.class);
when(future.get()).thenReturn(response);
futures.add(future);
}
when(mockClient.executeRequest(request.getNingRequest()))
.thenAnswer(AdditionalAnswers.returnsElementsOf(futures));
}
示例12: testGenerateRunConfiguration_withHost
import org.mockito.AdditionalAnswers; //导入依赖的package包/类
@Test
public void testGenerateRunConfiguration_withHost() throws CoreException {
when(launchConfiguration.getAttribute(anyString(), anyString()))
.thenAnswer(AdditionalAnswers.returnsSecondArg());
when(server.getHost()).thenReturn("example.com");
DefaultRunConfiguration config = new LocalAppEngineServerLaunchConfigurationDelegate()
.generateServerRunConfiguration(launchConfiguration, server, ILaunchManager.RUN_MODE);
assertEquals("example.com", config.getHost());
verify(server, atLeastOnce()).getHost();
}
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-eclipse,代码行数:11,代码来源:LocalAppEngineServerLaunchConfigurationDelegateTest.java
示例13: testGetAttribute_defaultValue
import org.mockito.AdditionalAnswers; //导入依赖的package包/类
@Test
public void testGetAttribute_defaultValue() throws CoreException {
when(launchConfig.getAttribute(anyString(), anyString()))
.then(AdditionalAnswers.returnsLastArg());
String value = GcpLocalRunTab.getAttribute(launchConfig, "non-existing-key", "default");
assertEquals("default", value);
}
示例14: testPerformApply_updatesEnvironmentTab
import org.mockito.AdditionalAnswers; //导入依赖的package包/类
@Test
public void testPerformApply_updatesEnvironmentTab() throws CoreException {
when(launchConfig.getAttribute(anyString(), anyString()))
.thenAnswer(AdditionalAnswers.returnsSecondArg());
tab.activated(launchConfig);
tab.deactivated(launchConfig);
verify(environmentTab).initializeFrom(any(ILaunchConfiguration.class));
verify(environmentTab).performApply(any(ILaunchConfigurationWorkingCopy.class));
}
示例15: testInterfaceWithDefaultAnswer
import org.mockito.AdditionalAnswers; //导入依赖的package包/类
/**
* When you mock an interface(or a Class), you can specify a default Answer as well, which
* handles interactions you do not declare.
* @throws Exception
*/
@Test
public void testInterfaceWithDefaultAnswer() throws Exception {
Service mockedObject = mock(Service.class, AdditionalAnswers.delegatesTo(new ServiceImpl()));
assertEquals(mockedObject.sayHello(), "hello world");
//still throws a MockitoException
//when(mockedObject.sayHello()).thenCallRealMethod();
}