1 19 20 21 package org.openide.text; 22 23 24 25 import java.io.IOException ; 26 import org.netbeans.junit.*; 27 import org.openide.util.Exceptions; 28 29 30 36 public class Starvation37045SecondTest extends NbTestCase implements CloneableEditorSupport.Env { 37 38 private CES support; 39 private String content = ""; 41 private boolean valid = true; 42 private boolean modified = false; 43 44 private String cannotBeModified; 45 private java.util.Date date = new java.util.Date (); 46 private java.util.List propL = new java.util.ArrayList (); 47 private java.beans.VetoableChangeListener vetoL; 48 49 50 public Starvation37045SecondTest (String s) { 51 super(s); 52 } 53 54 protected void setUp () { 55 support = new CES (this, org.openide.util.Lookup.EMPTY); 56 } 57 58 59 public void testTheStarvation37045 () throws Exception { 60 org.openide.util.Task task; 61 62 synchronized (this) { 63 support.prepareDocument ().waitFinished (); 64 65 task = org.openide.util.RequestProcessor.getDefault ().post (support); 66 74 notify (); 76 } 77 78 for (int i = 0; i < 5; i++) { 80 if (task.isFinished ()) break; 81 Thread.sleep (500); 82 } 83 84 task.waitFinished (); 86 assertTrue ("Should be finished, but there is a starvation", task.isFinished ()); 87 } 88 89 93 public synchronized void addPropertyChangeListener(java.beans.PropertyChangeListener l) { 94 propL.add (l); 95 } 96 public synchronized void removePropertyChangeListener(java.beans.PropertyChangeListener l) { 97 propL.remove (l); 98 } 99 100 public synchronized void addVetoableChangeListener(java.beans.VetoableChangeListener l) { 101 assertNull ("This is the first veto listener", vetoL); 102 vetoL = l; 103 } 104 public void removeVetoableChangeListener(java.beans.VetoableChangeListener l) { 105 assertEquals ("Removing the right veto one", vetoL, l); 106 vetoL = null; 107 } 108 109 public org.openide.windows.CloneableOpenSupport findCloneableOpenSupport() { 110 return support; 111 } 112 113 public String getMimeType() { 114 return "text/plain"; 115 } 116 117 public java.util.Date getTime() { 118 return date; 119 } 120 121 public java.io.InputStream inputStream() throws java.io.IOException { 122 throw new OutOfMemoryError ("Ha ha ha"); 123 } 125 public java.io.OutputStream outputStream() throws java.io.IOException { 126 class ContentStream extends java.io.ByteArrayOutputStream { 127 public void close () throws java.io.IOException { 128 super.close (); 129 content = new String (toByteArray ()); 130 } 131 } 132 133 return new ContentStream (); 134 } 135 136 public boolean isValid() { 137 return valid; 138 } 139 140 public boolean isModified() { 141 return modified; 142 } 143 144 public void markModified() throws java.io.IOException { 145 if (cannotBeModified != null) { 146 IOException e = new IOException (); 147 Exceptions.attachLocalizedMessage(e, cannotBeModified); 148 throw e; 149 } 150 151 modified = true; 152 } 153 154 public void unmarkModified() { 155 modified = false; 156 } 157 158 159 private final class CES extends CloneableEditorSupport 160 implements Runnable { 161 private boolean wait = false; 162 163 public CES (Env env, org.openide.util.Lookup l) { 164 super (env, l); 165 } 166 167 protected String messageName() { 168 return "Name"; 169 } 170 171 protected String messageOpened() { 172 return "Opened"; 173 } 174 175 protected String messageOpening() { 176 return "Opening"; 177 } 178 179 protected String messageSave() { 180 return "Save"; 181 } 182 183 protected String messageToolTip() { 184 return "ToolTip"; 185 } 186 187 public void run () { 188 boolean firstTime = wait; 189 try { 190 edit (); 191 if (firstTime) { 192 fail ("It should throw an exception"); 193 } 194 } catch (IllegalStateException ex) { 195 if (!firstTime) throw ex; 196 assertEquals ("Name of exception is correct", "Let's pretend that I am broken!!!", ex.getMessage ()); 197 } 198 } 199 200 } } 202 | Popular Tags |