Skip to content

Commit

Permalink
add test for DocumentHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
koentsje committed Mar 10, 2014
1 parent 74634e2 commit 075568f
Show file tree
Hide file tree
Showing 4 changed files with 283 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package org.jboss.tools.aesh.core.internal.ansi;




public class DefaultCommandFactory implements CommandFactory {

public static final DefaultCommandFactory INSTANCE = new DefaultCommandFactory();
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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() {
}

}
Original file line number Diff line number Diff line change
@@ -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;
}

}

0 comments on commit 075568f

Please sign in to comment.