use of org.mockito.internal.creation.MockSettingsImpl in project mockito by mockito.
the class AbstractByteBuddyMockMakerTest method settingsWithSuperCall.
private static <T> MockCreationSettings<T> settingsWithSuperCall(Class<T> type) {
MockSettingsImpl<T> mockSettings = new MockSettingsImpl<T>();
mockSettings.setTypeToMock(type);
mockSettings.defaultAnswer(new CallsRealMethods());
return mockSettings;
}
use of org.mockito.internal.creation.MockSettingsImpl in project che by eclipse.
the class DebuggerTest method testAddBreakpoint.
@Test
public void testAddBreakpoint() throws Exception {
MockSettings mockSettings = new MockSettingsImpl<>().defaultAnswer(RETURNS_SMART_NULLS).extraInterfaces(Resource.class);
Project project = mock(Project.class);
when(optional.isPresent()).thenReturn(true);
when(optional.get()).thenReturn(project);
when(project.getPath()).thenReturn(PATH);
VirtualFile virtualFile = mock(VirtualFile.class, mockSettings);
Path path = mock(Path.class);
when(path.toString()).thenReturn(PATH);
when(virtualFile.getLocation()).thenReturn(path);
when(virtualFile.toString()).thenReturn(PATH);
Resource resource = (Resource) virtualFile;
when(resource.getRelatedProject()).thenReturn(optional);
doReturn(promiseVoid).when(service).addBreakpoint(SESSION_ID, breakpointDto);
doReturn(promiseVoid).when(promiseVoid).then((Operation<Void>) any());
when(locationDto.withLineNumber(LINE_NUMBER + 1)).thenReturn(locationDto);
when(locationDto.withResourcePath(PATH)).thenReturn(locationDto);
when(locationDto.withResourceProjectPath(PATH)).thenReturn(locationDto);
when(locationDto.withTarget(anyString())).thenReturn(locationDto);
when(breakpointDto.withLocation(locationDto)).thenReturn(breakpointDto);
when(breakpointDto.withEnabled(true)).thenReturn(breakpointDto);
debugger.addBreakpoint(virtualFile, LINE_NUMBER);
verify(locationDto).withLineNumber(LINE_NUMBER + 1);
verify(locationDto).withTarget(FQN);
verify(locationDto).withResourcePath(PATH);
verify(locationDto).withResourceProjectPath(PATH);
verify(breakpointDto).withLocation(locationDto);
verify(breakpointDto).withEnabled(true);
verify(promiseVoid).then(operationVoidCaptor.capture());
operationVoidCaptor.getValue().apply(null);
verify(observer).onBreakpointAdded(breakpointCaptor.capture());
assertEquals(breakpointCaptor.getValue(), TEST_BREAKPOINT);
verify(promiseVoid).catchError(operationPromiseErrorCaptor.capture());
operationPromiseErrorCaptor.getValue().apply(promiseError);
verify(promiseError).getMessage();
}
use of org.mockito.internal.creation.MockSettingsImpl in project torodb by torodb.
the class DefaultToBackendFunctionTest method testApply_newField.
@Test
public void testApply_newField() {
MockSettings settings = new MockSettingsImpl().defaultAnswer((t) -> {
throw new AssertionError("Method " + t.getMethod() + " was not expected to be called");
});
BatchMetaDocPart withNewFieldsDocPart = mock(BatchMetaDocPart.class, settings);
doReturn(false).when(withNewFieldsDocPart).isCreatedOnCurrentBatch();
doReturn(Lists.newArrayList(new ImmutableMetaField("newFieldName", "newFieldId", FieldType.INTEGER))).when(withNewFieldsDocPart).getOnBatchModifiedMetaFields();
doReturn(Collections.emptyList()).when(withNewFieldsDocPart).getOnBatchModifiedMetaScalars();
DocPartData withNewData = mock(DocPartData.class);
given(withNewData.getMetaDocPart()).willReturn(withNewFieldsDocPart);
CollectionData collectionData = mock(CollectionData.class);
given(collectionData.orderedDocPartData()).willReturn(Lists.<DocPartData>newArrayList(withNewData));
//when
Iterable<BackendTransactionJob> result = fun.apply(collectionData);
ArrayList<BackendTransactionJob> resultList = Lists.newArrayList(result);
//then
assertEquals("Expected 2 jobs to do, but " + resultList.size() + " were recived", 2, resultList.size());
{
Optional<BackendTransactionJob> insertJob = resultList.stream().filter((job) -> job instanceof InsertBackendJob && ((InsertBackendJob) job).getDataToInsert().equals(withNewData)).findAny();
assertTrue(insertJob.isPresent());
Optional<BackendTransactionJob> addFieldJob = resultList.stream().filter((job) -> {
if (!(job instanceof AddFieldDdlJob)) {
return false;
}
AddFieldDdlJob castedJob = (AddFieldDdlJob) job;
return castedJob.getDocPart().equals(withNewFieldsDocPart) && castedJob.getField().getName().equals("newFieldName") && castedJob.getField().getIdentifier().equals("newFieldId");
}).findAny();
assertTrue(addFieldJob.isPresent());
int addFieldIndex = resultList.indexOf(addFieldJob.get());
int insertIndex = resultList.indexOf(insertJob.get());
assert addFieldIndex >= 0;
assert insertIndex >= 0;
assertTrue("For a given doc part, all related add fields jobs must be executed before insert " + "jobs, but in this case the add field job has index " + addFieldIndex + " and the insert job has index " + insertIndex, addFieldIndex < insertIndex);
}
}
use of org.mockito.internal.creation.MockSettingsImpl in project powermock by powermock.
the class MockCreatorTest method testMock_shouldReturnClassNameWhenSettingsHaveNoName.
@Test
public void testMock_shouldReturnClassNameWhenSettingsHaveNoName() throws NoSuchMethodException, SecurityException {
final MockSettingsImpl<List<?>> settings = new MockSettingsImpl<List<?>>();
final List<?> result = DefaultMockCreator.mock(List.class, false, false, null, settings, List.class.getMethod("add", Object.class));
final MockName mockName = MockUtil.getMockName(result);
assertNotNull(mockName);
assertEquals("list", mockName.toString());
}
use of org.mockito.internal.creation.MockSettingsImpl in project powermock by powermock.
the class MockCreatorTest method testMock_shouldReturnMockNameWhenSettingsHaveName.
@Test
public void testMock_shouldReturnMockNameWhenSettingsHaveName() throws NoSuchMethodException, SecurityException {
final MockSettingsImpl<List<?>> settings = new MockSettingsImpl<List<?>>();
settings.name("mylist");
final List<?> result = DefaultMockCreator.mock(List.class, false, false, null, settings, List.class.getMethod("add", Object.class));
final MockName mockName = MockUtil.getMockName(result);
assertNotNull(mockName);
assertEquals("mylist", mockName.toString());
}
Aggregations