provide abstract base test for IClipboard
Signed-off-by: Florian Thienel <florian@thienel.org>
diff --git a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/widget/BaseClipboardTest.java b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/widget/BaseClipboardTest.java
new file mode 100644
index 0000000..7883808
--- /dev/null
+++ b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/widget/BaseClipboardTest.java
@@ -0,0 +1,137 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Florian Thienel and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Florian Thienel - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.vex.core.internal.widget;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertNull;
+
+import org.eclipse.vex.core.internal.io.UniversalTestDocument;
+import org.eclipse.vex.core.provisional.dom.IElement;
+import org.eclipse.vex.core.provisional.dom.INode;
+import org.junit.Before;
+import org.junit.Test;
+
+public abstract class BaseClipboardTest {
+
+ private UniversalTestDocument document;
+ private DocumentEditor editor;
+ private IClipboard clipboard;
+
+ protected abstract IClipboard createClipboard();
+
+ @Before
+ public void setUp() throws Exception {
+ document = new UniversalTestDocument(1);
+ editor = new DocumentEditor(new FakeCursor(document.getDocument()));
+ editor.setDocument(document.getDocument());
+ clipboard = createClipboard();
+ }
+
+ @Test
+ public void givenFirstParagraphSelected_cutSelection_shouldRemoveFirstParagraphFromDocument() throws Exception {
+ final IElement section = document.getSection(0);
+ final INode firstParagraph = section.children().first();
+
+ select(firstParagraph);
+ clipboard.cutSelection(editor);
+
+ assertNotSame(firstParagraph, section.children().first());
+ assertNull(firstParagraph.getDocument());
+ }
+
+ @Test
+ public void givenFirstParagraphSelected_cutAndPasteAfterSecondParagraph_shouldInsertFirstParagraphAfterSecondParagraph() throws Exception {
+ final IElement section = document.getSection(0);
+ final INode firstParagraph = section.children().first();
+ final INode secondParagraph = section.children().last();
+ final String firstParagraphContent = firstParagraph.getText();
+
+ select(firstParagraph);
+ clipboard.cutSelection(editor);
+ editor.moveTo(secondParagraph.getEndPosition().moveBy(1));
+ clipboard.paste(editor);
+
+ assertEquals(firstParagraphContent, section.children().last().getText());
+ assertEquals(2, section.children().count());
+ }
+
+ @Test
+ public void givenFirstParagraphSelected_copyAndPasteAfterSecondParagraph_shouldInsertFirstParagraphAgainAfterSecondParagraph() throws Exception {
+ final IElement section = document.getSection(0);
+ final INode firstParagraph = section.children().first();
+ final INode secondParagraph = section.children().last();
+ final String firstParagraphContent = firstParagraph.getText();
+
+ select(firstParagraph);
+ clipboard.copySelection(editor);
+ editor.moveTo(secondParagraph.getEndPosition().moveBy(1));
+ clipboard.paste(editor);
+
+ assertEquals(firstParagraphContent, section.children().last().getText());
+ assertEquals(3, section.children().count());
+ }
+
+ @Test
+ public void givenNothingSelected_cutSelection_shouldNotChangeClipboardContent() throws Exception {
+ final IElement section = document.getSection(0);
+ final INode firstParagraph = section.children().first();
+ final INode secondParagraph = section.children().last();
+ final String firstParagraphContent = firstParagraph.getText();
+
+ select(firstParagraph);
+ clipboard.copySelection(editor);
+ editor.moveTo(secondParagraph.getEndPosition().moveBy(1));
+ clipboard.cutSelection(editor);
+ clipboard.paste(editor);
+
+ assertEquals(firstParagraphContent, section.children().last().getText());
+ assertEquals(3, section.children().count());
+ }
+
+ @Test
+ public void givenNothingSelected_copySelection_shouldNotChangeClipboardContent() throws Exception {
+ final IElement section = document.getSection(0);
+ final INode firstParagraph = section.children().first();
+ final INode secondParagraph = section.children().last();
+ final String firstParagraphContent = firstParagraph.getText();
+
+ select(firstParagraph);
+ clipboard.copySelection(editor);
+ editor.moveTo(secondParagraph.getEndPosition().moveBy(1));
+ clipboard.copySelection(editor);
+ clipboard.paste(editor);
+
+ assertEquals(firstParagraphContent, section.children().last().getText());
+ assertEquals(3, section.children().count());
+ }
+
+ @Test
+ public void givenFirstParagraphSelected_copyAndPasteTextIntoSecondParagraph_shouldInsertTextOfFirstParagraphIntoSecondParagraph() throws Exception {
+ final IElement section = document.getSection(0);
+ final INode firstParagraph = section.children().first();
+ final INode secondParagraph = section.children().last();
+ final String firstParagraphContent = firstParagraph.getText();
+
+ select(firstParagraph);
+ clipboard.copySelection(editor);
+ editor.moveTo(secondParagraph.getEndPosition());
+ clipboard.pasteText(editor);
+
+ assertEquals(firstParagraphContent, section.children().last().getText());
+ assertEquals(2, section.children().count());
+ }
+
+ private void select(final INode node) {
+ editor.moveTo(node.getStartPosition());
+ editor.moveBy(1, true);
+ }
+}
diff --git a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/widget/InMemoryClipboardTest.java b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/widget/InMemoryClipboardTest.java
index c5a7e90..5b21a74 100644
--- a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/widget/InMemoryClipboardTest.java
+++ b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/widget/InMemoryClipboardTest.java
@@ -10,126 +10,11 @@
*******************************************************************************/
package org.eclipse.vex.core.internal.widget;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertNull;
+public class InMemoryClipboardTest extends BaseClipboardTest {
-import org.eclipse.vex.core.internal.io.UniversalTestDocument;
-import org.eclipse.vex.core.provisional.dom.IElement;
-import org.eclipse.vex.core.provisional.dom.INode;
-import org.junit.Before;
-import org.junit.Test;
-
-public class InMemoryClipboardTest {
-
- private UniversalTestDocument document;
- private DocumentEditor editor;
- private InMemoryClipboard clipboard;
-
- @Before
- public void setUp() throws Exception {
- document = new UniversalTestDocument(1);
- editor = new DocumentEditor(new FakeCursor(document.getDocument()));
- editor.setDocument(document.getDocument());
- clipboard = new InMemoryClipboard();
+ @Override
+ protected IClipboard createClipboard() {
+ return new InMemoryClipboard();
}
- @Test
- public void givenFirstParagraphSelected_cutSelection_shouldRemoveFirstParagraphFromDocument() throws Exception {
- final IElement section = document.getSection(0);
- final INode firstParagraph = section.children().first();
-
- select(firstParagraph);
- clipboard.cutSelection(editor);
-
- assertNotSame(firstParagraph, section.children().first());
- assertNull(firstParagraph.getDocument());
- }
-
- @Test
- public void givenFirstParagraphSelected_cutAndPasteAfterSecondParagraph_shouldInsertFirstParagraphAfterSecondParagraph() throws Exception {
- final IElement section = document.getSection(0);
- final INode firstParagraph = section.children().first();
- final INode secondParagraph = section.children().last();
- final String firstParagraphContent = firstParagraph.getText();
-
- select(firstParagraph);
- clipboard.cutSelection(editor);
- editor.moveTo(secondParagraph.getEndPosition().moveBy(1));
- clipboard.paste(editor);
-
- assertEquals(firstParagraphContent, section.children().last().getText());
- assertEquals(2, section.children().count());
- }
-
- @Test
- public void givenFirstParagraphSelected_copyAndPasteAfterSecondParagraph_shouldInsertFirstParagraphAgainAfterSecondParagraph() throws Exception {
- final IElement section = document.getSection(0);
- final INode firstParagraph = section.children().first();
- final INode secondParagraph = section.children().last();
- final String firstParagraphContent = firstParagraph.getText();
-
- select(firstParagraph);
- clipboard.copySelection(editor);
- editor.moveTo(secondParagraph.getEndPosition().moveBy(1));
- clipboard.paste(editor);
-
- assertEquals(firstParagraphContent, section.children().last().getText());
- assertEquals(3, section.children().count());
- }
-
- @Test
- public void givenNothingSelected_cutSelection_shouldNotChangeClipboardContent() throws Exception {
- final IElement section = document.getSection(0);
- final INode firstParagraph = section.children().first();
- final INode secondParagraph = section.children().last();
- final String firstParagraphContent = firstParagraph.getText();
-
- select(firstParagraph);
- clipboard.copySelection(editor);
- editor.moveTo(secondParagraph.getEndPosition().moveBy(1));
- clipboard.cutSelection(editor);
- clipboard.paste(editor);
-
- assertEquals(firstParagraphContent, section.children().last().getText());
- assertEquals(3, section.children().count());
- }
-
- @Test
- public void givenNothingSelected_copySelection_shouldNotChangeClipboardContent() throws Exception {
- final IElement section = document.getSection(0);
- final INode firstParagraph = section.children().first();
- final INode secondParagraph = section.children().last();
- final String firstParagraphContent = firstParagraph.getText();
-
- select(firstParagraph);
- clipboard.copySelection(editor);
- editor.moveTo(secondParagraph.getEndPosition().moveBy(1));
- clipboard.copySelection(editor);
- clipboard.paste(editor);
-
- assertEquals(firstParagraphContent, section.children().last().getText());
- assertEquals(3, section.children().count());
- }
-
- @Test
- public void givenFirstParagraphSelected_copyAndPasteTextIntoSecondParagraph_shouldInsertTextOfFirstParagraphIntoSecondParagraph() throws Exception {
- final IElement section = document.getSection(0);
- final INode firstParagraph = section.children().first();
- final INode secondParagraph = section.children().last();
- final String firstParagraphContent = firstParagraph.getText();
-
- select(firstParagraph);
- clipboard.copySelection(editor);
- editor.moveTo(secondParagraph.getEndPosition());
- clipboard.pasteText(editor);
-
- assertEquals(firstParagraphContent, section.children().last().getText());
- assertEquals(2, section.children().count());
- }
-
- private void select(final INode node) {
- editor.moveTo(node.getStartPosition());
- editor.moveBy(1, true);
- }
}