Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package tests;
- import static org.junit.Assert.*;
- import org.junit.Before;
- import org.junit.Test;
- import undo.UndoManager;
- import video.*;
- import java.util.Iterator;
- public class TrackTest {
- private VideoTrack track; // used in most tests
- private UndoManager testUndo; // used in some tests
- private VideoTrack remove;
- private UndoManager removeUndo;
- VideoSection sectionA = new VideoSection("Part A",
- new TimeCode(0, 3, 0), new TimeCode(0, 5, 20));
- VideoSection sectionB = new VideoSection("Part B",
- new TimeCode(0, 2, 0), new TimeCode(0, 4, 15));
- @Before
- public void setUp() throws Exception {
- this.testUndo = new UndoManager();
- this.removeUndo = new UndoManager();
- this.track = new VideoTrack("Test Track", this.testUndo);
- this.remove = new VideoTrack("Test Track", this.removeUndo);
- this.track.addSection(sectionA);
- this.track.addSection(sectionB);
- }
- /**
- * Adds a new video section on a track and tests that the starting and
- * ending time codes are correctly recalculated. The addition is then undone and
- * the track is tested to be empty again.
- *
- * As undoing might potentially leave the track/the action object in a
- * state where redo produces unexpected results, additional undo-redo
- * cycle with tests is performed in the end.
- */
- @Test
- public void testAddVideoSection() {
- // Here are the two sections prior to adding them on the track.
- // Notice that neither starts from 0:0:0
- // Test first that the section really was added on the track
- //
- // Basically we create an iterator to go through the sections
- // and test that the expected sections are there and that there are no extra sections
- Iterator<VideoSection> sectionIterator = this.track.getSectionIterator();
- assertTrue( "The track should hold the newly added section.", sectionIterator.hasNext());
- assertSame( "The newly added section - Part A - should have been on the track.", sectionA, sectionIterator.next());
- assertFalse(
- "All added sections should have been iterated over already. "
- + "There shouldn't be more sections on the track.",
- sectionIterator.hasNext());
- assertSame( "The newly added section - Part B - should have been on the track.", sectionB, sectionIterator.next());
- // If all test have passed this far, we can proceed to check if the time codes
- // were changed according to the documentation. (note that this only applies to addSection)
- TimeCode expectedStart = new TimeCode(0, 0, 0);
- TimeCode expectedEnd = new TimeCode(0, 2, 20);
- assertEquals("Start frame timecode was wrong after addSection", expectedStart,
- sectionA.getStart());
- assertEquals("End frame timecode was wrong after addSection", expectedEnd,
- sectionA.getEnd());
- assertEquals("Video track was incorrect after addSection", this.track,
- sectionA.getTrack());
- // Now we undo the add and check if the track is really empty(testing Undo)
- this.track.undo();
- // Get a fresh new iterator
- sectionIterator = this.track.getSectionIterator();
- assertFalse("After this undo the track should have been empty.", sectionIterator.hasNext());
- // Redo should give us again the state where the section added first is on the track
- this.track.redo();
- sectionIterator = this.track.getSectionIterator();
- assertTrue( "After redo, the track should hold the section added first.", sectionIterator.hasNext());
- assertSame( "The first section - Part A - should have been on the track.", sectionA, sectionIterator.next());
- assertFalse(
- "All added sections should have been iterated over already. "
- + "There shouldn't be more sections on the track.",
- sectionIterator.hasNext());
- // Now we undo the redo and check if the track is once again really empty
- this.track.undo();
- // Get a fresh new iterator
- sectionIterator = this.track.getSectionIterator();
- assertFalse("After this undo the track should have been empty.", sectionIterator.hasNext());
- }
- /**
- * Tests that a redo operation cannot be done when there is nothing to redo.
- */
- @Test
- public void testImpossibleRedo() {
- assertFalse("No actions have been made so it should be impossible to redo.", this.testUndo.canRedo());
- assertFalse("No actions have been made so it should be impossible to redo.", this.track.redo());
- }
- @Test
- public void testRemoveActionSection() {
- Iterator<VideoSection> secIterator = this.remove.getSectionIterator();
- this.remove.undo();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement