author | Jaroslav Tulach <jtulach@netbeans.org> |
Mon, 28 Jun 2010 09:29:30 +0200 | |
changeset 356 | 23511f8a9718 |
parent 105 | 5c7a65ed657a |
permissions | -rw-r--r-- |
jtulach@105 | 1 |
package org.apidesign.deadlock; |
jtulach@105 | 2 |
|
jtulach@105 | 3 |
import java.awt.Dimension; |
jtulach@105 | 4 |
import java.util.logging.Level; |
jtulach@105 | 5 |
import java.util.logging.Logger; |
jtulach@105 | 6 |
import javax.swing.JFrame; |
jtulach@105 | 7 |
import javax.swing.JLabel; |
jtulach@105 | 8 |
import javax.swing.SwingUtilities; |
jtulach@105 | 9 |
import org.netbeans.junit.NbTestCase; |
jtulach@105 | 10 |
import static org.junit.Assert.*; |
jtulach@105 | 11 |
|
jtulach@105 | 12 |
public class DeadlockSyncOnTest extends NbTestCase { |
jtulach@105 | 13 |
static final Logger LOG = Logger.getLogger(DeadlockSyncOnTest.class.getName()); |
jtulach@356 | 14 |
private static final JLabel preLoadClasses = new JLabel(); |
jtulach@105 | 15 |
|
jtulach@105 | 16 |
public DeadlockSyncOnTest(String n) { |
jtulach@105 | 17 |
super(n); |
jtulach@105 | 18 |
} |
jtulach@105 | 19 |
|
jtulach@105 | 20 |
@Override |
jtulach@105 | 21 |
protected int timeOut() { |
jtulach@356 | 22 |
return 30000; |
jtulach@105 | 23 |
} |
jtulach@105 | 24 |
|
jtulach@105 | 25 |
|
jtulach@105 | 26 |
public static class StrangePanel extends LabelProviderSyncOnTreeLock { |
jtulach@105 | 27 |
@Override |
jtulach@105 | 28 |
public Dimension getPreferredSize () { |
jtulach@105 | 29 |
try { |
jtulach@105 | 30 |
Thread.sleep(1000); |
jtulach@105 | 31 |
JLabel sampleLabel = createLabel(); |
jtulach@105 | 32 |
return sampleLabel.getPreferredSize(); |
jtulach@105 | 33 |
} catch (InterruptedException ex) { |
jtulach@105 | 34 |
Logger.getLogger(DeadlockSyncOnTest.class.getName()).log(Level.SEVERE, null, ex); |
jtulach@105 | 35 |
return super.getPreferredSize(); |
jtulach@105 | 36 |
} |
jtulach@105 | 37 |
} |
jtulach@105 | 38 |
} |
jtulach@105 | 39 |
|
jtulach@105 | 40 |
|
jtulach@105 | 41 |
|
jtulach@105 | 42 |
|
jtulach@105 | 43 |
public void testCreateLabel() throws Exception { |
jtulach@105 | 44 |
final LabelProviderSyncOnTreeLock instance = new StrangePanel(); |
jtulach@105 | 45 |
|
jtulach@105 | 46 |
class R implements Runnable { |
jtulach@105 | 47 |
public void run() { |
jtulach@105 | 48 |
JFrame f = new JFrame(); |
jtulach@105 | 49 |
f.add(instance); |
jtulach@105 | 50 |
f.setVisible(true); |
jtulach@105 | 51 |
f.pack(); |
jtulach@105 | 52 |
} |
jtulach@105 | 53 |
} |
jtulach@105 | 54 |
|
jtulach@105 | 55 |
R showFrame = new R(); |
jtulach@105 | 56 |
SwingUtilities.invokeLater(showFrame); |
jtulach@105 | 57 |
|
jtulach@105 | 58 |
Thread.sleep(500); |
jtulach@105 | 59 |
JLabel result = instance.createLabel(); |
jtulach@105 | 60 |
assertNotNull("Creates the result", result); |
jtulach@105 | 61 |
} |
jtulach@105 | 62 |
|
jtulach@105 | 63 |
} |
jtulach@105 | 64 |