author | Jaroslav Tulach <jtulach@netbeans.org> |
Sat, 14 Jun 2008 09:56:12 +0200 | |
changeset 132 | 3bc4c54f4bcc |
parent 105 | 5c7a65ed657a |
child 133 | 50bf1b976c0d |
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@132 | 17 |
static final Logger LOG = Logger.getLogger( |
jtulach@132 | 18 |
DeadlockTest.class.getName() |
jtulach@132 | 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@132 | 39 |
Logger.getLogger( |
jtulach@132 | 40 |
DeadlockTest.class.getName()).log(Level.SEVERE, null, ex |
jtulach@132 | 41 |
); |
jtulach@105 | 42 |
return super.getPreferredSize(); |
jtulach@105 | 43 |
} |
jtulach@105 | 44 |
} |
jtulach@105 | 45 |
} |
jtulach@105 | 46 |
|
jtulach@105 | 47 |
|
jtulach@105 | 48 |
|
jtulach@105 | 49 |
|
jtulach@105 | 50 |
public void testCreateLabel() throws Exception { |
jtulach@105 | 51 |
final LabelProvider instance = new StrangePanel(); |
jtulach@105 | 52 |
|
jtulach@105 | 53 |
class R implements Runnable { |
jtulach@105 | 54 |
public void run() { |
jtulach@105 | 55 |
JFrame f = new JFrame(); |
jtulach@105 | 56 |
f.add(instance); |
jtulach@105 | 57 |
f.setVisible(true); |
jtulach@105 | 58 |
f.pack(); |
jtulach@105 | 59 |
} |
jtulach@105 | 60 |
} |
jtulach@105 | 61 |
|
jtulach@105 | 62 |
R showFrame = new R(); |
jtulach@105 | 63 |
SwingUtilities.invokeLater(showFrame); |
jtulach@105 | 64 |
|
jtulach@105 | 65 |
Thread.sleep(500); |
jtulach@105 | 66 |
JLabel result = instance.createLabel(); |
jtulach@105 | 67 |
assertNotNull("Creates the result", result); |
jtulach@105 | 68 |
} |
jtulach@105 | 69 |
|
jtulach@105 | 70 |
} |
jtulach@105 | 71 |
// END: deadlock.test |
jtulach@105 | 72 |