Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.10 KB | None | 0 0
  1. package tests;
  2.  
  3. import static org.junit.Assert.*;
  4. import org.junit.Before;
  5. import org.junit.Test;
  6.  
  7. import undo.UndoManager;
  8. import video.*;
  9.  
  10. import java.util.Iterator;
  11.  
  12.  
  13. public class TrackTest {
  14.  
  15. private VideoTrack track; // used in most tests
  16. private UndoManager testUndo; // used in some tests
  17. private VideoTrack remove;
  18. private UndoManager removeUndo;
  19.  
  20.  
  21. VideoSection sectionA = new VideoSection("Part A",
  22. new TimeCode(0, 3, 0), new TimeCode(0, 5, 20));
  23.  
  24. VideoSection sectionB = new VideoSection("Part B",
  25. new TimeCode(0, 2, 0), new TimeCode(0, 4, 15));
  26.  
  27. @Before
  28. public void setUp() throws Exception {
  29. this.testUndo = new UndoManager();
  30. this.removeUndo = new UndoManager();
  31. this.track = new VideoTrack("Test Track", this.testUndo);
  32. this.remove = new VideoTrack("Test Track", this.removeUndo);
  33.  
  34. this.track.addSection(sectionA);
  35. this.track.addSection(sectionB);
  36.  
  37. }
  38.  
  39. /**
  40. * Adds a new video section on a track and tests that the starting and
  41. * ending time codes are correctly recalculated. The addition is then undone and
  42. * the track is tested to be empty again.
  43. *
  44. * As undoing might potentially leave the track/the action object in a
  45. * state where redo produces unexpected results, additional undo-redo
  46. * cycle with tests is performed in the end.
  47. */
  48.  
  49. @Test
  50. public void testAddVideoSection() {
  51.  
  52. // Here are the two sections prior to adding them on the track.
  53. // Notice that neither starts from 0:0:0
  54.  
  55.  
  56. // Test first that the section really was added on the track
  57. //
  58. // Basically we create an iterator to go through the sections
  59. // and test that the expected sections are there and that there are no extra sections
  60.  
  61. Iterator<VideoSection> sectionIterator = this.track.getSectionIterator();
  62.  
  63. assertTrue( "The track should hold the newly added section.", sectionIterator.hasNext());
  64. assertSame( "The newly added section - Part A - should have been on the track.", sectionA, sectionIterator.next());
  65. assertFalse(
  66. "All added sections should have been iterated over already. "
  67. + "There shouldn't be more sections on the track.",
  68. sectionIterator.hasNext());
  69.  
  70. assertSame( "The newly added section - Part B - should have been on the track.", sectionB, sectionIterator.next());
  71.  
  72. // If all test have passed this far, we can proceed to check if the time codes
  73. // were changed according to the documentation. (note that this only applies to addSection)
  74.  
  75. TimeCode expectedStart = new TimeCode(0, 0, 0);
  76. TimeCode expectedEnd = new TimeCode(0, 2, 20);
  77.  
  78. assertEquals("Start frame timecode was wrong after addSection", expectedStart,
  79. sectionA.getStart());
  80. assertEquals("End frame timecode was wrong after addSection", expectedEnd,
  81. sectionA.getEnd());
  82. assertEquals("Video track was incorrect after addSection", this.track,
  83. sectionA.getTrack());
  84.  
  85.  
  86.  
  87. // Now we undo the add and check if the track is really empty(testing Undo)
  88.  
  89. this.track.undo();
  90.  
  91. // Get a fresh new iterator
  92. sectionIterator = this.track.getSectionIterator();
  93. assertFalse("After this undo the track should have been empty.", sectionIterator.hasNext());
  94.  
  95. // Redo should give us again the state where the section added first is on the track
  96.  
  97. this.track.redo();
  98.  
  99. sectionIterator = this.track.getSectionIterator();
  100.  
  101. assertTrue( "After redo, the track should hold the section added first.", sectionIterator.hasNext());
  102. assertSame( "The first section - Part A - should have been on the track.", sectionA, sectionIterator.next());
  103. assertFalse(
  104. "All added sections should have been iterated over already. "
  105. + "There shouldn't be more sections on the track.",
  106. sectionIterator.hasNext());
  107.  
  108. // Now we undo the redo and check if the track is once again really empty
  109.  
  110. this.track.undo();
  111.  
  112. // Get a fresh new iterator
  113. sectionIterator = this.track.getSectionIterator();
  114. assertFalse("After this undo the track should have been empty.", sectionIterator.hasNext());
  115. }
  116.  
  117. /**
  118. * Tests that a redo operation cannot be done when there is nothing to redo.
  119. */
  120. @Test
  121. public void testImpossibleRedo() {
  122. assertFalse("No actions have been made so it should be impossible to redo.", this.testUndo.canRedo());
  123. assertFalse("No actions have been made so it should be impossible to redo.", this.track.redo());
  124. }
  125.  
  126. @Test
  127. public void testRemoveActionSection() {
  128.  
  129. Iterator<VideoSection> secIterator = this.remove.getSectionIterator();
  130.  
  131. this.remove.undo();
  132.  
  133.  
  134.  
  135. }
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement