author | Jaroslav Tulach <jtulach@netbeans.org> |
Sat, 14 Jun 2008 09:58:11 +0200 | |
changeset 154 | 0fd5e9c500b9 |
parent 153 | b5cbb797ec0a |
child 263 | 7e8e995065c5 |
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.JPanel; |
jtulach@105 | 9 |
import javax.swing.SwingUtilities; |
jtulach@105 | 10 |
import org.junit.Test; |
jtulach@105 | 11 |
import org.netbeans.junit.Log; |
jtulach@105 | 12 |
import org.netbeans.junit.NbTestCase; |
jtulach@105 | 13 |
import static org.junit.Assert.*; |
jtulach@105 | 14 |
|
jtulach@105 | 15 |
// BEGIN: deadlock.test |
jtulach@105 | 16 |
public class DeadlockTest extends NbTestCase { |
jtulach@154 | 17 |
static final Logger LOG = Logger.getLogger( |
jtulach@154 | 18 |
DeadlockTest.class.getName() |
jtulach@154 | 19 |
); |
jtulach@105 | 20 |
|
jtulach@105 | 21 |
public DeadlockTest(String n) { |
jtulach@105 | 22 |
super(n); |
jtulach@105 | 23 |
} |
jtulach@105 | 24 |
|
jtulach@105 | 25 |
@Override |
jtulach@105 | 26 |
protected int timeOut() { |
jtulach@105 | 27 |
return 10000; |
jtulach@105 | 28 |
} |
jtulach@105 | 29 |
|
jtulach@105 | 30 |
|
jtulach@105 | 31 |
public static class StrangePanel extends LabelProvider { |
jtulach@105 | 32 |
@Override |
jtulach@105 | 33 |
public Dimension getPreferredSize () { |
jtulach@105 | 34 |
try { |
jtulach@105 | 35 |
Thread.sleep(1000); |
jtulach@105 | 36 |
JLabel sampleLabel = createLabel(); |
jtulach@105 | 37 |
return sampleLabel.getPreferredSize(); |
jtulach@105 | 38 |
} catch (InterruptedException ex) { |
jtulach@154 | 39 |
Logger l = Logger.getLogger( |
jtulach@154 | 40 |
DeadlockTest.class.getName() |
jtulach@154 | 41 |
); |
jtulach@154 | 42 |
l.log(Level.SEVERE, null, ex); |
jtulach@105 | 43 |
return super.getPreferredSize(); |
jtulach@105 | 44 |
} |
jtulach@105 | 45 |
} |
jtulach@105 | 46 |
} |
jtulach@105 | 47 |
|
jtulach@105 | 48 |
|
jtulach@105 | 49 |
|
jtulach@105 | 50 |
|
jtulach@105 | 51 |
public void testCreateLabel() throws Exception { |
jtulach@105 | 52 |
final LabelProvider instance = new StrangePanel(); |
jtulach@105 | 53 |
|
jtulach@105 | 54 |
class R implements Runnable { |
jtulach@105 | 55 |
public void run() { |
jtulach@105 | 56 |
JFrame f = new JFrame(); |
jtulach@105 | 57 |
f.add(instance); |
jtulach@105 | 58 |
f.setVisible(true); |
jtulach@105 | 59 |
f.pack(); |
jtulach@105 | 60 |
} |
jtulach@105 | 61 |
} |
jtulach@105 | 62 |
|
jtulach@105 | 63 |
R showFrame = new R(); |
jtulach@105 | 64 |
SwingUtilities.invokeLater(showFrame); |
jtulach@105 | 65 |
|
jtulach@105 | 66 |
Thread.sleep(500); |
jtulach@105 | 67 |
JLabel result = instance.createLabel(); |
jtulach@105 | 68 |
assertNotNull("Creates the result", result); |
jtulach@105 | 69 |
} |
jtulach@105 | 70 |
|
jtulach@105 | 71 |
} |
jtulach@105 | 72 |
// END: deadlock.test |
jtulach@105 | 73 |