Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add test for DocumentHandler

  • Loading branch information...
commit 075568f9f2a618eb1065441287c2b87e85bfc8e0 1 parent 74634e2
@koentsje koentsje authored
View
3  plugins/org.jboss.tools.aesh.core/src/org/jboss/tools/aesh/core/internal/ansi/DefaultCommandFactory.java
@@ -1,8 +1,5 @@
package org.jboss.tools.aesh.core.internal.ansi;
-
-
-
public class DefaultCommandFactory implements CommandFactory {
public static final DefaultCommandFactory INSTANCE = new DefaultCommandFactory();
View
68 tests/org.jboss.tools.aesh.core.test/src/org/jboss/tools/aesh/core/internal/io/DocumentHandlerTest.java
@@ -0,0 +1,68 @@
+package org.jboss.tools.aesh.core.internal.io;
+
+import org.jboss.tools.aesh.core.document.Document;
+import org.jboss.tools.aesh.core.document.Style;
+import org.jboss.tools.aesh.core.internal.ansi.Command;
+import org.jboss.tools.aesh.core.test.util.TestDocument;
+import org.jboss.tools.aesh.core.test.util.TestStyle;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class DocumentHandlerTest {
+
+ private int styleLength = 0;
+ private int documentLength = 0;
+ private int cursorOffset = 0;
+
+ private int replacedOffset = 0;
+ private int replacedLength = 0;
+ private String replacedText = null;
+ private Document handledDocument = null;
+
+ private Style testStyle = new TestStyle() {
+ @Override public int getLength() { return styleLength; }
+ @Override public void setLength(int length) { styleLength = length; }
+ };
+
+ private Document testDocument = new TestDocument() {
+ @Override public Style getCurrentStyle() { return testStyle; }
+ @Override public int getCursorOffset() { return cursorOffset; }
+ @Override public int getLength() { return documentLength; }
+ @Override public void moveCursorTo(int offset) { cursorOffset = offset; }
+ @Override public void replace(int offset, int length, String text) {
+ replacedOffset = offset;
+ replacedLength = length;
+ replacedText = text;
+ }
+ };
+
+ private Command testCommand = new Command() {
+ @Override
+ public void handle(Document document) {
+ handledDocument = document;
+ }
+ };
+
+ private DocumentHandler testHandler = new DocumentHandler();
+
+ private String testOutput = "foobar";
+
+ @Test
+ public void testHandleOutput() {
+ testHandler.setDocument(testDocument);
+ testHandler.handleOutput(testOutput);
+ Assert.assertEquals("style length", testOutput.length(), styleLength);
+ Assert.assertEquals("replaced offset", 0, replacedOffset);
+ Assert.assertEquals("replaced lenght", 0, replacedLength);
+ Assert.assertEquals("replaced text", testOutput, replacedText);
+ Assert.assertEquals("cursor offset", testOutput.length(), cursorOffset);
+ }
+
+ @Test
+ public void testHandleCommand() {
+ testHandler.setDocument(testDocument);
+ testHandler.handleCommand(testCommand);
+ Assert.assertEquals("handled document", testDocument, handledDocument);
+ }
+
+}
View
71 tests/org.jboss.tools.aesh.core.test/src/org/jboss/tools/aesh/core/test/util/TestDocument.java
@@ -0,0 +1,71 @@
+package org.jboss.tools.aesh.core.test.util;
+
+import org.jboss.tools.aesh.core.document.Document;
+import org.jboss.tools.aesh.core.document.Style;
+
+public class TestDocument implements Document {
+
+ @Override
+ public int getCursorOffset() {
+ return 0;
+ }
+
+ @Override
+ public int getLineOfOffset(int offset) {
+ return 0;
+ }
+
+ @Override
+ public int getLineOffset(int line) {
+ return 0;
+ }
+
+ @Override
+ public int getLineLength(int line) {
+ return 0;
+ }
+
+ @Override
+ public int getLength() {
+ return 0;
+ }
+
+ @Override
+ public void moveCursorTo(int offset) {
+ }
+
+ @Override
+ public void restoreCursor() {
+ }
+
+ @Override
+ public void saveCursor() {
+ }
+
+ @Override
+ public void reset() {
+ }
+
+ @Override
+ public void replace(int cursorOffset, int length, String str) {
+ }
+
+ @Override
+ public Style newStyleFromCurrent() {
+ return null;
+ }
+
+ @Override
+ public void setCurrentStyle(Style style) {
+ }
+
+ @Override
+ public Style getCurrentStyle() {
+ return null;
+ }
+
+ @Override
+ public void setDefaultStyle() {
+ }
+
+}
View
144 tests/org.jboss.tools.aesh.core.test/src/org/jboss/tools/aesh/core/test/util/TestStyle.java
@@ -0,0 +1,144 @@
+package org.jboss.tools.aesh.core.test.util;
+
+import org.jboss.tools.aesh.core.document.Style;
+
+public class TestStyle implements Style {
+
+ @Override
+ public void resetToNormal() {
+ }
+
+ @Override
+ public void setBoldOn() {
+ }
+
+ @Override
+ public void setFaintOn() {
+ }
+
+ @Override
+ public void setItalicOn() {
+ }
+
+ @Override
+ public void setUnderlineSingle() {
+ }
+
+ @Override
+ public void setImageNegative() {
+ }
+
+ @Override
+ public void setCrossedOut() {
+ }
+
+ @Override
+ public void setBoldOrFaintOff() {
+ }
+
+ @Override
+ public void setItalicOff() {
+ }
+
+ @Override
+ public void setUnderlineNone() {
+ }
+
+ @Override
+ public void setImagePositive() {
+ }
+
+ @Override
+ public void setNotCrossedOut() {
+ }
+
+ @Override
+ public void setForegroundBlack() {
+ }
+
+ @Override
+ public void setForegroundRed() {
+ }
+
+ @Override
+ public void setForegroundGreen() {
+ }
+
+ @Override
+ public void setForegroundYellow() {
+ }
+
+ @Override
+ public void setForegroundBlue() {
+ }
+
+ @Override
+ public void setForegroundMagenta() {
+ }
+
+ @Override
+ public void setForegroundCyan() {
+ }
+
+ @Override
+ public void setForegroundWhite() {
+ }
+
+ @Override
+ public void setForegroundXTerm(int colour) {
+ }
+
+ @Override
+ public void setForegroundDefault() {
+ }
+
+ @Override
+ public void setBackgroundBlack() {
+ }
+
+ @Override
+ public void setBackgroundRed() {
+ }
+
+ @Override
+ public void setBackgroundGreen() {
+ }
+
+ @Override
+ public void setBackgroundYellow() {
+ }
+
+ @Override
+ public void setBackgroundBlue() {
+ }
+
+ @Override
+ public void setBackgroundMagenta() {
+ }
+
+ @Override
+ public void setBackgroundCyan() {
+ }
+
+ @Override
+ public void setBackgroundWhite() {
+ }
+
+ @Override
+ public void setBackgroundXTerm(int colour) {
+ }
+
+ @Override
+ public void setBackgroundDefault() {
+ }
+
+ @Override
+ public void setLength(int length) {
+ }
+
+ @Override
+ public int getLength() {
+ return 0;
+ }
+
+}
Please sign in to comment.
Something went wrong with that request. Please try again.