1 33 34 package edu.rice.cs.drjava.model.repl; 35 36 import edu.rice.cs.drjava.DrJavaTestCase; 37 import edu.rice.cs.drjava.model.GlobalModel; 38 import edu.rice.cs.drjava.ui.InteractionsPane; 39 import edu.rice.cs.drjava.ui.MainFrame; 40 import edu.rice.cs.util.text.EditDocumentException; 41 42 import java.io.File ; 43 44 45 public final class InteractionsDJDocumentTest extends DrJavaTestCase { 46 47 protected InteractionsDJDocument _adapter; 48 protected InteractionsModel _model; 49 protected InteractionsDocument _doc; 50 protected InteractionsPane _pane; 51 protected MainFrame mf; 52 53 54 protected void setUp() throws Exception { 55 super.setUp(); 56 mf = new MainFrame(); 57 GlobalModel gm = mf.getModel(); 58 _model = gm.getInteractionsModel(); 59 _adapter = gm.getSwingInteractionsDocument(); 60 _doc = gm.getInteractionsDocument(); 61 } 62 63 private boolean _interpreterRestarted = false; 64 65 66 public void testStylesListContentAndReset() throws EditDocumentException, InterruptedException { 67 70 71 final Object _restartLock = new Object (); 72 73 assertEquals("StylesList before insert should contain 2 pairs", 2, _adapter.getStylesList().size()); 74 75 int blen = _model.getStartUpBanner().length(); 76 77 78 String styleElt1 = "((0, " + blen + "), object.return.style)"; 79 String styleElt2 = "((" + blen + ", " + (blen + 2) + "), default)"; 80 81 assertEquals("The first element pushed on StylesList before insertion should be", styleElt1, 82 _adapter.getStylesList().get(1).toString()); 83 assertEquals("The second element pushed on StylesList before insertion should be", styleElt2, 84 _adapter.getStylesList().get(0).toString()); 85 86 _doc.insertText(_doc.getLength(), "5", InteractionsDocument.NUMBER_RETURN_STYLE); 88 89 90 String styleElt3 = "((" + (blen + 2) + ", " + (blen + 3) + "), number.return.style)"; 91 92 assertEquals("StylesList before reset should contain 3 pairs", 3, _adapter.getStylesList().size()); 93 94 assertEquals("The first element pushed on StylesList before reset should be", styleElt1, 95 _adapter.getStylesList().get(2).toString()); 96 assertEquals("The second element pushed on StylesList before reset should be", styleElt2, 97 _adapter.getStylesList().get(1).toString()); 98 assertEquals("The last element pushed on StylesList before reset should be", styleElt3, 99 _adapter.getStylesList().get(0).toString()); 100 101 105 106 107 InteractionsListener restartCommand = new DummyInteractionsListener() { 108 public void interpreterReady(File wd) { 109 synchronized(_restartLock) { 110 _interpreterRestarted = true; 111 _restartLock.notify(); 112 } 113 }}; 114 _model.addListener(restartCommand); 115 116 _model.setWaitingForFirstInterpreter(false); 118 119 synchronized(_restartLock) { _interpreterRestarted = false; } 120 121 File f = _model.getWorkingDirectory(); 123 _model.resetInterpreter(f); 124 125 synchronized(_restartLock) { while (! _interpreterRestarted) _restartLock.wait(); } 127 _model.removeListener(restartCommand); 128 129 133 assertEquals("StylesList after reset should contain 2 pairs", 2, _adapter.getStylesList().size()); 134 135 assertEquals("The first element pushed on StylesList after reset should be", styleElt1, 136 _adapter.getStylesList().get(1).toString()); 137 assertEquals("The second element pushed on StylesList after reset should be", styleElt2, 138 _adapter.getStylesList().get(0).toString()); 139 140 141 142 } 143 144 147 public void testCannotAddNullStyleToList() throws EditDocumentException { 148 assertEquals("StylesList before insert should contain 2 pairs", 150 2, _adapter.getStylesList().size()); 151 152 _doc.insertText(_doc.getLength(), "5", InteractionsDocument.NUMBER_RETURN_STYLE); 154 155 assertEquals("StylesList should contain 3 pairs", 156 3, _adapter.getStylesList().size()); 157 158 _doc.insertText(_doc.getLength(), "6", null); 160 161 assertEquals("StylesList should still contain 3 pairs - null string should not have been inserted", 162 3, _adapter.getStylesList().size()); 163 } 164 } | Popular Tags |