@Test public void testBookmarkInsideTextFile() throws Exception { // Given SWTBotEclipseEditor textEditor = textEditor(project, "LICENSE.txt"); textEditor.navigateTo(25, 0); waitUntil("cursor is not on line 25", () -> textEditor.cursorPosition().line == 25); Map<String, String> bookmarkProperties = new HashMap<>(); // When IWorkbenchPart part = getActivePart(); ISelection selection = getSelection(part); textEditorBookmarkPropertiesProvider.addBookmarkProperties(bookmarkProperties, part, selection, new NullProgressMonitor()); // Then assertThat(bookmarkProperties).containsEntry(PROP_LINE_NUMBER, "25") .containsEntry(PROP_PROJECT_NAME, PROJECT_NAME) .containsEntry(PROP_LINE_CONTENT, "\"Source\" form shall mean the preferred form for making modifications,") .containsEntry(PROPERTY_NAME, "LICENSE.txt : \"Source\" form shall mean the preferred form for making modifications,") .containsEntry(PROP_WORKSPACE_PATH, "/TextEditorBookmarkPropertiesProviderTest/LICENSE.txt") .containsKey(PROP_FILE_PATH); }
@Test public void testGotoInsideMethod() { // Given Bookmark bookmark = new Bookmark(new BookmarkId(), ImmutableMap.of(PROP_JAVA_DECLARING_TYPE, "org.apache.commons.cli.DefaultParser", PROP_JAVA_ELEMENT_KIND, KIND_METHOD, PROP_JAVA_ELEMENT_NAME, "handleProperties", PROP_LINE_NUMBER_INSIDE_ELEMENT, "7")); JavaTypeMemberBookmarkLocation location = javaBookmarkLocationProvider.getBookmarkLocation(bookmark, new NullProgressMonitor()); // When boolean result = gotoBookmark(bookmark, location); // Then assertTrue(result); SWTBotEclipseEditor textEditor = bot.activeEditor().toTextEditor(); assertEquals("DefaultParser.java", textEditor.getTitle()); assertEquals(146, textEditor.cursorPosition().line); }
@Test public void testBookmarkInsideMethod() throws Exception { // Given SWTBotEclipseEditor textEditor = textEditor("org.apache.commons.cli.BasicParser"); textEditor.navigateTo(48, 0); Map<String, String> bookmarkProperties = new HashMap<>(); // When IWorkbenchPart part = getActivePart(); ISelection selection = getSelection(part); javaEditorBookmarkPropertiesProvider.addBookmarkProperties(bookmarkProperties, part, selection, new NullProgressMonitor()); // Then assertThat(bookmarkProperties).containsEntry(PROP_LINE_NUMBER_INSIDE_ELEMENT, "5") .containsEntry(PROP_JAVA_DECLARING_TYPE, "org.apache.commons.cli.BasicParser") .containsEntry(PROP_JAVA_ELEMENT_NAME, "flatten").containsEntry(PROP_JAVA_ELEMENT_KIND, KIND_METHOD) .containsEntry(PROP_LINE_CONTENT, "return arguments;") .containsEntry(PROP_JAVA_METHOD_SIGNATURE, "String[] flatten(Options,String[],boolean)"); }
@Test public void testBookmarkBeforeDeclarationButOnSameLine() throws Exception { // Given SWTBotEclipseEditor textEditor = textEditor("org.apache.commons.cli.Parser"); textEditor.navigateTo(44, 0); Map<String, String> bookmarkProperties = new HashMap<>(); // When IWorkbenchPart part = getActivePart(); ISelection selection = getSelection(part); javaEditorBookmarkPropertiesProvider.addBookmarkProperties(bookmarkProperties, part, selection, new NullProgressMonitor()); // Then assertThat(bookmarkProperties).containsEntry(PROP_LINE_NUMBER_INSIDE_ELEMENT, "0") .containsEntry(PROP_JAVA_DECLARING_TYPE, "org.apache.commons.cli.Parser") .containsEntry(PROP_JAVA_ELEMENT_NAME, "setOptions").containsEntry(PROP_JAVA_ELEMENT_KIND, KIND_METHOD) .containsEntry(PROP_LINE_CONTENT, "protected void setOptions(Options options)") .containsEntry(PROP_JAVA_METHOD_SIGNATURE, "void setOptions(Options)"); }
private SWTBotEclipseEditor textEditor(String fullyQualifiedType) throws JavaModelException, PartInitException { IType type = javaProject.findType(fullyQualifiedType); IEditorPart editorPart = UIThreadRunnable.syncExec(new Result<IEditorPart>() { public IEditorPart run() { try { return JavaUI.openInEditor(type, true, true); } catch (PartInitException | JavaModelException e) { throw new RuntimeException(e); } } }); // IEditorPart editorPart = JavaUI.openInEditor(type, true, true); SWTBotEditor editor = bot.editorById(editorPart.getEditorSite().getId()); return editor.toTextEditor(); }
/** * Tests com.avaloq.test.swtbot.DE_CH. */ @Test public void testDeChKeyboardLayout() { SWTBotPreferences.KEYBOARD_LAYOUT = "com.avaloq.test.swtbot.DE_CH"; SWTBotPreferences.KEYBOARD_STRATEGY = "org.eclipse.swtbot.swt.finder.keyboard.MockKeyboardStrategy"; SwtWorkbenchBot bot = new SwtWorkbenchBot(); bot.closeWelcomePage(); bot.menu("File").menu("New").menu("Untitled Text File").click(); SWTBotEclipseEditor editor = bot.activeEditor().toTextEditor(); editor.setFocus(); editor.typeText(EXPECTED_RESULT); String actualResult = editor.getText(); bot.closeAllEditors(); assertEquals("Written and read characters must exactly match", EXPECTED_RESULT, actualResult); }
@Override protected void beforeAllTests() { super.beforeAllTests(); initializeSWTBot(); getBot().closeWelcomePage(); getBot().resetActivePerspective(); IEditorPart editor = openEditor(getTestSource().getUri(), true); SWTBotEditor swtBotEditor = getBot().editorByTitle(editor.getTitle()); getTestInformation().putTestObject(SWTBotEclipseEditor.class, new AcfSwtBotEclipseEditor(swtBotEditor.getReference(), getBot())); }
@Override protected void afterAllTests() { final SWTBotEclipseEditor editor = getEditor(); final IEditorPart editorPart = editor.getReference().getEditor(false); Object editorJobs = getTestUtil().getEditorJobFamily(editorPart); if (editor != null) { editor.close(); if (editorJobs != null) { waitForJobsOfFamily(editorJobs); } } super.afterAllTests(); }
public void editFile(final String fileName, final String contents) { if (Files.exists(filePath(fileName), LinkOption.NOFOLLOW_LINKS)) { bot.tree().getTreeItem(projectName).getNode(fileName).doubleClick(); } else { newFile(fileName); } final SWTBotEclipseEditor textEditor = bot.editorByTitle(fileName).toTextEditor(); textEditor.setText(""); textEditor.typeText(contents); textEditor.save(); }
public SWTBotEclipseEditor getEditor() { return (SWTBotEclipseEditor) getTestInformation().getTestObject(SWTBotEclipseEditor.class); }
public static String getEditorText(final SWTWorkbenchBot bot, String title) { SWTBotEclipseEditor te = bot.editorByTitle(title).toTextEditor(); return te.getText(); }
private void typeHAtTheBeginning() { SWTBotEclipseEditor textEditor = bot.activeEditor().toTextEditor(); textEditor.typeText(0, 0, "H"); }
/** * Performs a drag and drop operation from this widget to the target editor. * The drag start location will be chosen depending on this widget's default * implementation. * The exact drop position is calculated through the StyledText contained by the editor. * * @param source * the source widget to drag * @param target * Editor to perform the drop on * @see #dragAndDrop(Point) */ public void dragAndDrop(final AbstractSWTBot<? extends Widget> source, final SWTBotEclipseEditor target) { if (target != null) { dragAndDrop(source, on(target.getStyledText())); } }
/** * Returns background color at the given offset in the given document. * * @param eBot * editor bot, may be {@code null} * @param document * document, may be {@code null} * @param offset * offset in the document * @return color, may be {@code null} * @throws BadLocationException * if offset is not valid for the document */ private Color getColorAtOffset(final SWTBotEclipseEditor eBot, final IDocument document, final int offset) throws BadLocationException { int line = document.getLineOfOffset(offset); int column = offset - document.getLineOffset(line); return eBot.getStyle(line, column).background; }