Basic API Structure #2
@ -1,8 +1,8 @@
|
||||
package dev.kske.undoredo;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.*;
|
||||
|
||||
/**
|
||||
* @author Kai S. K. Engelbart
|
||||
@ -10,67 +10,95 @@ import org.junit.jupiter.api.Test;
|
||||
*/
|
||||
class ChangeManagerTest {
|
||||
|
||||
ChangeManager<IntChange> manager;
|
||||
IntWrapper wrapper;
|
||||
IntChange change;
|
||||
|
||||
@BeforeEach
|
||||
void prepareChangeManager() {
|
||||
manager = new ChangeManager<>();
|
||||
wrapper = new IntWrapper();
|
||||
change = new IntChange(wrapper, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link dev.kske.undoredo.ChangeManager#addChange(dev.kske.undoredo.Change)}.
|
||||
* Tests adding a change.
|
||||
*
|
||||
* @since 0.0.1
|
||||
*/
|
||||
@Test
|
||||
@Order(1)
|
||||
void testAddChange() {
|
||||
fail("Not yet implemented");
|
||||
assertSame(0, wrapper.value);
|
||||
manager.addChange(change);
|
||||
assertSame(1, wrapper.value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test method for {@link dev.kske.undoredo.ChangeManager#undo()}.
|
||||
*/
|
||||
@Test
|
||||
void testUndo() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link dev.kske.undoredo.ChangeManager#redo()}.
|
||||
*/
|
||||
@Test
|
||||
void testRedo() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link dev.kske.undoredo.ChangeManager#mark()}.
|
||||
*/
|
||||
@Test
|
||||
void testMark() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link dev.kske.undoredo.ChangeManager#isAtMarkedIndex()}.
|
||||
*/
|
||||
@Test
|
||||
void testIsAtMarkedIndex() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link dev.kske.undoredo.ChangeManager#isUndoAvailable()}.
|
||||
*/
|
||||
@Test
|
||||
void testIsUndoAvailable() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link dev.kske.undoredo.ChangeManager#isRedoAvailable()}.
|
||||
*/
|
||||
@Test
|
||||
void testIsRedoAvailable() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link dev.kske.undoredo.ChangeManager#getChanges()}.
|
||||
* Tests the consistency of the change list.
|
||||
*
|
||||
* @since 0.0.1
|
||||
*/
|
||||
@Test
|
||||
@Order(2)
|
||||
void testGetChanges() {
|
||||
fail("Not yet implemented");
|
||||
assertTrue(manager.getChanges().isEmpty());
|
||||
manager.addChange(change);
|
||||
assertSame(1, manager.getChanges().size());
|
||||
assertEquals(change, manager.getChanges().get(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test undoing a change.
|
||||
*
|
||||
* @since 0.0.1
|
||||
*/
|
||||
@Test
|
||||
@Order(2)
|
||||
void testUndo() {
|
||||
assertFalse(manager.isUndoAvailable());
|
||||
assertFalse(manager.undo());
|
||||
manager.addChange(change);
|
||||
assertTrue(manager.isUndoAvailable());
|
||||
assertTrue(manager.undo());
|
||||
assertFalse(manager.isUndoAvailable());
|
||||
assertFalse(manager.undo());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests redoing a change.
|
||||
*
|
||||
* @since 0.0.1
|
||||
*/
|
||||
@Test
|
||||
@Order(4)
|
||||
void testRedo() {
|
||||
assertFalse(manager.isRedoAvailable());
|
||||
assertFalse(manager.redo());
|
||||
manager.addChange(change);
|
||||
assertFalse(manager.isRedoAvailable());
|
||||
assertFalse(manager.redo());
|
||||
manager.undo();
|
||||
assertTrue(manager.isRedoAvailable());
|
||||
assertTrue(manager.redo());
|
||||
assertFalse(manager.isRedoAvailable());
|
||||
assertFalse(manager.redo());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests marking a change.
|
||||
*
|
||||
* @since 0.0.1
|
||||
*/
|
||||
@Test
|
||||
@Order(5)
|
||||
void testMark() {
|
||||
assertTrue(manager.isAtMarkedIndex());
|
||||
manager.addChange(change);
|
||||
assertFalse(manager.isAtMarkedIndex());
|
||||
manager.mark();
|
||||
assertTrue(manager.isAtMarkedIndex());
|
||||
manager.undo();
|
||||
assertFalse(manager.isAtMarkedIndex());
|
||||
}
|
||||
}
|
||||
|
31
src/test/java/dev/kske/undoredo/IntChange.java
Normal file
31
src/test/java/dev/kske/undoredo/IntChange.java
Normal file
@ -0,0 +1,31 @@
|
||||
package dev.kske.undoredo;
|
||||
|
||||
/**
|
||||
* @author Kai S. K. Engelbart
|
||||
* @since 0.0.1
|
||||
*/
|
||||
class IntChange implements Change {
|
||||
|
||||
private final IntWrapper wrapper;
|
||||
private final int value;
|
||||
|
||||
IntChange(IntWrapper wrapper, int value) {
|
||||
this.wrapper = wrapper;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
wrapper.value += value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Change invert() {
|
||||
return new IntChange(wrapper, -value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isIdentity() {
|
||||
return value == 0;
|
||||
}
|
||||
}
|
10
src/test/java/dev/kske/undoredo/IntWrapper.java
Normal file
10
src/test/java/dev/kske/undoredo/IntWrapper.java
Normal file
@ -0,0 +1,10 @@
|
||||
package dev.kske.undoredo;
|
||||
|
||||
/**
|
||||
* @author Kai S. K. Engelbart
|
||||
* @since 0.0.1
|
||||
*/
|
||||
class IntWrapper {
|
||||
|
||||
int value;
|
||||
}
|
Reference in New Issue
Block a user