history test fixed
This commit is contained in:
parent
08af58b18a
commit
b31498f959
@ -22,7 +22,7 @@ public class EditorHistoryState implements Cloneable{
|
|||||||
|
|
||||||
@Element(required = false)
|
@Element(required = false)
|
||||||
@Nullable
|
@Nullable
|
||||||
private String text;
|
private String text = "";
|
||||||
|
|
||||||
private EditorHistoryState() {
|
private EditorHistoryState() {
|
||||||
// for xml
|
// for xml
|
||||||
|
@ -6,9 +6,21 @@
|
|||||||
|
|
||||||
package org.solovyev.android.calculator.history;
|
package org.solovyev.android.calculator.history;
|
||||||
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
import junit.framework.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.solovyev.android.calculator.Editor;
|
import org.solovyev.android.calculator.CalculatorDisplayViewState;
|
||||||
|
import org.solovyev.android.calculator.CalculatorDisplayViewStateImpl;
|
||||||
|
import org.solovyev.android.calculator.CalculatorEditorViewState;
|
||||||
|
import org.solovyev.android.calculator.CalculatorEditorViewStateImpl;
|
||||||
|
import org.solovyev.android.calculator.jscl.JsclOperation;
|
||||||
|
import org.solovyev.common.equals.CollectionEqualizer;
|
||||||
|
import org.solovyev.common.equals.EqualsTool;
|
||||||
|
import org.solovyev.common.history.HistoryHelper;
|
||||||
|
import org.solovyev.common.history.SimpleHistoryHelper;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: serso
|
* User: serso
|
||||||
@ -36,7 +48,7 @@ public class HistoryUtilsTest {
|
|||||||
" </editorState>\n" +
|
" </editorState>\n" +
|
||||||
" <displayState>\n" +
|
" <displayState>\n" +
|
||||||
" <editorState>\n" +
|
" <editorState>\n" +
|
||||||
" <cursorPosition>1</cursorPosition>\n" +
|
" <cursorPosition>0</cursorPosition>\n" +
|
||||||
" <text>Error</text>\n" +
|
" <text>Error</text>\n" +
|
||||||
" </editorState>\n" +
|
" </editorState>\n" +
|
||||||
" <jsclOperation>simplify</jsclOperation>\n" +
|
" <jsclOperation>simplify</jsclOperation>\n" +
|
||||||
@ -55,7 +67,7 @@ public class HistoryUtilsTest {
|
|||||||
" </editorState>\n" +
|
" </editorState>\n" +
|
||||||
" <displayState>\n" +
|
" <displayState>\n" +
|
||||||
" <editorState>\n" +
|
" <editorState>\n" +
|
||||||
" <cursorPosition>1</cursorPosition>\n" +
|
" <cursorPosition>0</cursorPosition>\n" +
|
||||||
" <text>Error</text>\n" +
|
" <text>Error</text>\n" +
|
||||||
" </editorState>\n" +
|
" </editorState>\n" +
|
||||||
" <jsclOperation>simplify</jsclOperation>\n" +
|
" <jsclOperation>simplify</jsclOperation>\n" +
|
||||||
@ -79,11 +91,11 @@ public class HistoryUtilsTest {
|
|||||||
" <time>100000000</time>\n" +
|
" <time>100000000</time>\n" +
|
||||||
" <editorState>\n" +
|
" <editorState>\n" +
|
||||||
" <cursorPosition>1</cursorPosition>\n" +
|
" <cursorPosition>1</cursorPosition>\n" +
|
||||||
" <text>null</text>\n" +
|
" <text></text>\n" +
|
||||||
" </editorState>\n" +
|
" </editorState>\n" +
|
||||||
" <displayState>\n" +
|
" <displayState>\n" +
|
||||||
" <editorState>\n" +
|
" <editorState>\n" +
|
||||||
" <cursorPosition>1</cursorPosition>\n" +
|
" <cursorPosition>0</cursorPosition>\n" +
|
||||||
" <text>Error</text>\n" +
|
" <text>Error</text>\n" +
|
||||||
" </editorState>\n" +
|
" </editorState>\n" +
|
||||||
" <jsclOperation>elementary</jsclOperation>\n" +
|
" <jsclOperation>elementary</jsclOperation>\n" +
|
||||||
@ -108,19 +120,13 @@ public class HistoryUtilsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testToXml() throws Exception {
|
public void testToXml() throws Exception {
|
||||||
/*final Date date = new Date(100000000);
|
final Date date = new Date(100000000);
|
||||||
|
|
||||||
HistoryHelper<CalculatorHistoryState> history = new SimpleHistoryHelper<CalculatorHistoryState>();
|
HistoryHelper<CalculatorHistoryState> history = new SimpleHistoryHelper<CalculatorHistoryState>();
|
||||||
|
|
||||||
CalculatorDisplay calculatorDisplay = new TestCalculatorDisplay();
|
CalculatorDisplayViewState calculatorDisplay = CalculatorDisplayViewStateImpl.newErrorState(JsclOperation.simplify, "Error");
|
||||||
calculatorDisplay.setErrorMessage("error_msg1");
|
|
||||||
calculatorDisplay.setText("Error");
|
|
||||||
calculatorDisplay.setSelection(1);
|
|
||||||
calculatorDisplay.setJsclOperation(JsclOperation.simplify);
|
|
||||||
|
|
||||||
Editor calculatorEditor = new TestEditor();
|
CalculatorEditorViewState calculatorEditor = CalculatorEditorViewStateImpl.newInstance("1+1", 3);
|
||||||
calculatorEditor.setSelection(3);
|
|
||||||
calculatorEditor.setText("1+1");
|
|
||||||
|
|
||||||
CalculatorHistoryState state = CalculatorHistoryState.newInstance(calculatorEditor, calculatorDisplay);
|
CalculatorHistoryState state = CalculatorHistoryState.newInstance(calculatorEditor, calculatorDisplay);
|
||||||
state.setTime(date.getTime());
|
state.setTime(date.getTime());
|
||||||
@ -133,45 +139,27 @@ public class HistoryUtilsTest {
|
|||||||
|
|
||||||
Assert.assertEquals(toXml1, HistoryUtils.toXml(history.getStates()));
|
Assert.assertEquals(toXml1, HistoryUtils.toXml(history.getStates()));
|
||||||
|
|
||||||
calculatorDisplay = new TestCalculatorDisplay();
|
calculatorDisplay = CalculatorDisplayViewStateImpl.newValidState(JsclOperation.numeric, null, "5/6", 3);
|
||||||
calculatorDisplay.setErrorMessage(null);
|
|
||||||
calculatorDisplay.setText("5/6");
|
|
||||||
calculatorDisplay.setSelection(3);
|
|
||||||
calculatorDisplay.setJsclOperation(JsclOperation.numeric);
|
|
||||||
|
|
||||||
calculatorEditor = new TestEditor();
|
calculatorEditor = CalculatorEditorViewStateImpl.newInstance("5/6", 2);
|
||||||
calculatorEditor.setSelection(2);
|
|
||||||
calculatorEditor.setText("5/6");
|
|
||||||
|
|
||||||
state = CalculatorHistoryState.newInstance(calculatorEditor, calculatorDisplay);
|
state = CalculatorHistoryState.newInstance(calculatorEditor, calculatorDisplay);
|
||||||
state.setSaved(true);
|
state.setSaved(true);
|
||||||
state.setTime(date.getTime());
|
state.setTime(date.getTime());
|
||||||
history.addState(state);
|
history.addState(state);
|
||||||
|
|
||||||
calculatorDisplay = new TestCalculatorDisplay();
|
calculatorDisplay = CalculatorDisplayViewStateImpl.newErrorState(JsclOperation.elementary, "Error");
|
||||||
calculatorDisplay.setErrorMessage("error_msg2");
|
|
||||||
calculatorDisplay.setText("Error");
|
|
||||||
calculatorDisplay.setSelection(1);
|
|
||||||
calculatorDisplay.setJsclOperation(JsclOperation.elementary);
|
|
||||||
|
|
||||||
calculatorEditor = new TestEditor();
|
calculatorEditor = CalculatorEditorViewStateImpl.newInstance("", 1);
|
||||||
calculatorEditor.setSelection(1);
|
|
||||||
calculatorEditor.setText(null);
|
|
||||||
|
|
||||||
state = CalculatorHistoryState.newInstance(calculatorEditor, calculatorDisplay);
|
state = CalculatorHistoryState.newInstance(calculatorEditor, calculatorDisplay);
|
||||||
state.setSaved(true);
|
state.setSaved(true);
|
||||||
state.setTime(date.getTime());
|
state.setTime(date.getTime());
|
||||||
history.addState(state);
|
history.addState(state);
|
||||||
|
|
||||||
calculatorDisplay = new TestCalculatorDisplay();
|
calculatorDisplay = CalculatorDisplayViewStateImpl.newValidState(JsclOperation.numeric, null, "4+5/35sin(41)+dfdsfsdfs", 1);
|
||||||
calculatorDisplay.setErrorMessage(null);
|
|
||||||
calculatorDisplay.setText("4+5/35sin(41)+dfdsfsdfs");
|
|
||||||
calculatorDisplay.setSelection(1);
|
|
||||||
calculatorDisplay.setJsclOperation(JsclOperation.numeric);
|
|
||||||
|
|
||||||
calculatorEditor = new TestEditor();
|
calculatorEditor = CalculatorEditorViewStateImpl.newInstance("4+5/35sin(41)+dfdsfsdfs", 0);
|
||||||
calculatorEditor.setSelection(0);
|
|
||||||
calculatorEditor.setText("4+5/35sin(41)+dfdsfsdfs");
|
|
||||||
|
|
||||||
state = CalculatorHistoryState.newInstance(calculatorEditor, calculatorDisplay);
|
state = CalculatorHistoryState.newInstance(calculatorEditor, calculatorDisplay);
|
||||||
state.setSaved(true);
|
state.setSaved(true);
|
||||||
@ -198,144 +186,6 @@ public class HistoryUtilsTest {
|
|||||||
historyState.setId(0);
|
historyState.setId(0);
|
||||||
historyState.setSaved(true);
|
historyState.setSaved(true);
|
||||||
}
|
}
|
||||||
Assert.assertTrue(EqualsTool.areEqual(history.getStates(), historyFromXml.getStates(), new CollectionEqualizer<CalculatorHistoryState>(null)));*/
|
Assert.assertTrue(EqualsTool.areEqual(history.getStates(), historyFromXml.getStates(), new CollectionEqualizer<CalculatorHistoryState>(null)));
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* private static class TestCalculatorDisplay implements CalculatorDisplay {
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private final TestEditor testEditor = new TestEditor();
|
|
||||||
|
|
||||||
private boolean valid;
|
|
||||||
|
|
||||||
private String errorMessage;
|
|
||||||
|
|
||||||
private JsclOperation operation;
|
|
||||||
|
|
||||||
private Generic genericResult;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isValid() {
|
|
||||||
return this.valid;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setValid(boolean valid) {
|
|
||||||
this.valid = valid;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getErrorMessage() {
|
|
||||||
return this.errorMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setErrorMessage(@Nullable String errorMessage) {
|
|
||||||
this.errorMessage = errorMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setJsclOperation(@NotNull JsclOperation jsclOperation) {
|
|
||||||
this.operation = jsclOperation;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public JsclOperation getJsclOperation() {
|
|
||||||
return this.operation;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setGenericResult(@Nullable Generic genericResult) {
|
|
||||||
this.genericResult = genericResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Generic getGenericResult() {
|
|
||||||
return this.genericResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CharSequence getText() {
|
|
||||||
return this.testEditor.getText();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setText(@Nullable CharSequence text) {
|
|
||||||
this.testEditor.setText(text);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getSelection() {
|
|
||||||
return this.testEditor.getSelection();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setSelection(int selection) {
|
|
||||||
this.testEditor.setSelection(selection);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setView(@Nullable CalculatorDisplayView view) {
|
|
||||||
//To change body of implemented methods use File | Settings | File Templates.
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public CalculatorDisplayView getView() {
|
|
||||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public CalculatorDisplayViewState getViewState() {
|
|
||||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setViewState(@NotNull CalculatorDisplayViewState viewState) {
|
|
||||||
//To change body of implemented methods use File | Settings | File Templates.
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public CalculatorEventData getLastEventData() {
|
|
||||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCalculatorEvent(@NotNull CalculatorEventData calculatorEventData, @NotNull CalculatorEventType calculatorEventType, @Nullable Object data) {
|
|
||||||
//To change body of implemented methods use File | Settings | File Templates.
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
private static class TestEditor implements Editor {
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
private CharSequence text;
|
|
||||||
|
|
||||||
private int selection;
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public CharSequence getText() {
|
|
||||||
return this.text;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setText(@Nullable CharSequence text) {
|
|
||||||
this.text = text;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getSelection() {
|
|
||||||
return this.selection;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setSelection(int selection) {
|
|
||||||
this.selection = selection;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user