use of org.mockito.Mock in project kie-wb-common by kiegroup.
the class GeneralSettingsPresenterTest method testExecuteValidationFailing.
@Test
public void testExecuteValidationFailing() {
final POM pom = mock(POM.class);
doReturn(false).when(validationService).validate(eq(pom));
generalSettingsPresenter.executeValidation(s -> s.validate(pom), "Test message").then(valid -> {
Assert.fail("Promise should've been resolved!");
return promises.resolve();
}).catch_(e -> {
verify(validationService).validate(eq(pom));
Assert.assertEquals(e, "Test message");
return promises.resolve();
});
}
use of org.mockito.Mock in project kie-wb-common by kiegroup.
the class GeneralSettingsPresenterTest method testExecuteValidation.
@Test
public void testExecuteValidation() {
final POM pom = mock(POM.class);
doReturn(true).when(validationService).validate(eq(pom));
generalSettingsPresenter.executeValidation(s -> s.validate(pom), "Test message").then(valid -> {
verify(validationService).validate(eq(pom));
Assert.assertEquals(valid, true);
return promises.resolve();
}).catch_(e -> {
Assert.fail("Promise should've been resolved!");
return promises.resolve();
});
}
use of org.mockito.Mock in project kie-wb-common by kiegroup.
the class JavaRoasterModelDriverTest method modelReadTest.
@Test
public void modelReadTest() {
try {
final SourceFilter pojo1Filter = javaType -> false;
final NestedClassFilter nestedClassFilter = javaType -> javaType.isClass() && javaType.getAnnotation(Generated.class) != null;
final MethodFilter methodFilter = method -> !method.isConstructor() && method.getAnnotation(Generated.class) != null;
FilterHolder filterHolder = mock(FilterHolder.class);
when(filterHolder.getSourceFilters()).thenReturn(Collections.singleton(pojo1Filter));
when(filterHolder.getNestedClassFilters()).thenReturn(Collections.singleton(nestedClassFilter));
when(filterHolder.getMethodFilters()).thenReturn(Collections.singleton(methodFilter));
JavaRoasterModelDriver javaRoasterModelDriver = new JavaRoasterModelDriver(ioService, rootPath, getClass().getClassLoader(), filterHolder);
ModelDriverResult modelDriverResult = javaRoasterModelDriver.loadModel();
DataModel dataModelOriginal = createModel();
assertNotNull(modelDriverResult);
assertNotNull(modelDriverResult.getDataModel());
assertEquals(dataModelOriginal.getDataObjects().size(), modelDriverResult.getDataModel().getDataObjects().size());
for (DataObject dataObject : dataModelOriginal.getDataObjects()) {
DataModelerAssert.assertEqualsDataObject(dataObject, modelDriverResult.getDataModel().getDataObject(dataObject.getClassName()));
}
for (JavaEnum javaEnum : dataModelOriginal.getJavaEnums()) {
DataModelerAssert.assertEqualsJavaEnum(javaEnum, modelDriverResult.getDataModel().getJavaEnum(javaEnum.getClassName()));
}
org.uberfire.backend.vfs.Path errorFile1 = Paths.convert(rootPath.resolve(ERROR_FILE1));
org.uberfire.backend.vfs.Path errorFile2 = Paths.convert(rootPath.resolve(ERROR_FILE2));
verifyErrorFilesWereDetected(modelDriverResult, errorFile1, errorFile2);
} catch (Exception e) {
e.printStackTrace();
fail("Test failed: " + e.getMessage());
}
}
use of org.mockito.Mock in project kie-wb-common by kiegroup.
the class JavaRoasterModelDriverTest method importsUpdateTest.
@Test
public void importsUpdateTest() throws Exception {
Path importsUpdateTestFilePath = rootPath.resolve("package6").resolve("ImportsUpdateTest.java");
String source = ioService.readAllString(importsUpdateTestFilePath);
JavaClassSource importsUpdateTestJavaClassSource = (JavaClassSource) Roaster.parse(source);
ClassLoader classLoader = getClass().getClassLoader();
ClassTypeResolver classTypeResolver = DriverUtils.createClassTypeResolver(importsUpdateTestJavaClassSource, classLoader);
final SourceFilter pojo1Filter = javaType -> false;
final NestedClassFilter nestedClassFilter = javaType -> javaType.isClass() && javaType.getAnnotation(Generated.class) != null;
final MethodFilter methodFilter = method -> !method.isConstructor() && method.getAnnotation(Generated.class) != null;
FilterHolder filterHolder = mock(FilterHolder.class);
when(filterHolder.getSourceFilters()).thenReturn(Collections.singleton(pojo1Filter));
when(filterHolder.getNestedClassFilters()).thenReturn(Collections.singleton(nestedClassFilter));
when(filterHolder.getMethodFilters()).thenReturn(Collections.singleton(methodFilter));
JavaRoasterModelDriver javaRoasterModelDriver = new JavaRoasterModelDriver(ioService, rootPath, classLoader, filterHolder);
ModelDriverResult result = javaRoasterModelDriver.loadDataObject(source, importsUpdateTestFilePath);
DataObject importsUpdateTest = result.getDataModel().getDataObject("org.kie.workbench.common.services.datamodeller.driver.package6.ImportsUpdateTest");
importsUpdateTest.addImport(new ImportImpl(List.class.getName()));
importsUpdateTest.addImport(new ImportImpl(ArrayList.class.getName()));
importsUpdateTest.setName("ImportsUpdateTestResult");
Path expectedFilePath = rootPath.resolve("package6").resolve("ImportsUpdateTestResult.java");
String expectedSource = ioService.readAllString(expectedFilePath);
ModelDriverResult expectedResult = javaRoasterModelDriver.loadDataObject(expectedSource, expectedFilePath);
DataObject importsUpdateTestResult = expectedResult.getDataModel().getDataObject("org.kie.workbench.common.services.datamodeller.driver.package6.ImportsUpdateTestResult");
DataModelerAssert.assertEqualsDataObject(importsUpdateTestResult, importsUpdateTest);
DataModelerAssert.assertEqualsImports(importsUpdateTestResult.getImports(), importsUpdateTest.getImports());
javaRoasterModelDriver.updateSource(importsUpdateTestJavaClassSource, importsUpdateTest, new UpdateInfo(), classTypeResolver);
ModelDriverResult updatedResult = javaRoasterModelDriver.loadDataObject(importsUpdateTestJavaClassSource.toString(), importsUpdateTestFilePath);
DataModelerAssert.assertEqualsDataObject(importsUpdateTestResult, updatedResult.getDataModel().getDataObject("org.kie.workbench.common.services.datamodeller.driver.package6.ImportsUpdateTestResult"));
DataModelerAssert.assertEqualsImports(importsUpdateTestResult.getImports(), updatedResult.getDataModel().getDataObject("org.kie.workbench.common.services.datamodeller.driver.package6.ImportsUpdateTestResult").getImports());
}
use of org.mockito.Mock in project kie-wb-common by kiegroup.
the class DeleteNodeToolboxActionTest method testSkipAction.
@Test
@SuppressWarnings("unchecked")
public void testSkipAction() {
this.tested = new DeleteNodeToolboxAction(translationService, sessionCommandManager, commandFactories, definitionUtils, action -> false, clearSelectionEventEventSourceMock);
final MouseClickEvent event = mock(MouseClickEvent.class);
final ToolboxAction<AbstractCanvasHandler> cascade = tested.onMouseClick(canvasHandler, E_UUID, event);
assertEquals(tested, cascade);
verify(sessionCommandManager, never()).execute(eq(canvasHandler), any(CanvasCommand.class));
verify(clearSelectionEventEventSourceMock, never()).fire(any(CanvasClearSelectionEvent.class));
}
Aggregations