samples/deadlock/test/org/apidesign/deadlock/LabelProviderTest.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Jun 2008 09:56:12 +0200
changeset 132 3bc4c54f4bcc
parent 105 5c7a65ed657a
child 153 b5cbb797ec0a
permissions -rw-r--r--
Truncating all examples to 80 characters per line
jtulach@104
     1
package org.apidesign.deadlock;
jtulach@104
     2
jtulach@104
     3
import java.awt.Dimension;
jtulach@104
     4
import java.util.logging.Logger;
jtulach@104
     5
import javax.swing.JFrame;
jtulach@104
     6
import javax.swing.JLabel;
jtulach@104
     7
import javax.swing.JPanel;
jtulach@104
     8
import javax.swing.SwingUtilities;
jtulach@104
     9
import org.junit.Test;
jtulach@104
    10
import org.netbeans.junit.Log;
jtulach@104
    11
import org.netbeans.junit.NbTestCase;
jtulach@104
    12
import static org.junit.Assert.*;
jtulach@104
    13
jtulach@105
    14
// BEGIN: deadlock.test.controlflow
jtulach@104
    15
public class LabelProviderTest extends NbTestCase {
jtulach@132
    16
    static final Logger LOG = Logger.getLogger(
jtulach@132
    17
        LabelProviderTest.class.getName()
jtulach@132
    18
    );
jtulach@104
    19
    
jtulach@104
    20
    public LabelProviderTest(String n) {
jtulach@104
    21
        super(n);
jtulach@104
    22
    }
jtulach@104
    23
jtulach@104
    24
    @Override
jtulach@104
    25
    protected int timeOut() {
jtulach@104
    26
        return 10000;
jtulach@104
    27
    }
jtulach@104
    28
    
jtulach@104
    29
    
jtulach@104
    30
    public static class StrangePanel extends LabelProvider {
jtulach@104
    31
        @Override
jtulach@104
    32
        // BEGIN: deadlock.pref.size
jtulach@104
    33
        public Dimension getPreferredSize () {
jtulach@104
    34
            JLabel sampleLabel = createLabel();
jtulach@104
    35
            return sampleLabel.getPreferredSize ();
jtulach@104
    36
        }
jtulach@104
    37
        // END: deadlock.pref.size
jtulach@104
    38
    }
jtulach@104
    39
    
jtulach@104
    40
    
jtulach@104
    41
    
jtulach@104
    42
jtulach@104
    43
    public void testCreateLabel() {
jtulach@104
    44
        final LabelProvider instance = new StrangePanel();
jtulach@104
    45
        
jtulach@104
    46
        class R implements Runnable {
jtulach@104
    47
            public void run() {
jtulach@104
    48
                LOG.info("In AWT thread");
jtulach@104
    49
                JFrame f = new JFrame();
jtulach@104
    50
                f.add(instance);
jtulach@104
    51
                f.setVisible(true);
jtulach@104
    52
                f.pack();
jtulach@104
    53
            }
jtulach@104
    54
        }
jtulach@104
    55
jtulach@104
    56
        Log.controlFlow(
jtulach@104
    57
            Logger.getLogger("org.apidesign"),
jtulach@104
    58
            Logger.getLogger("global"), 
jtulach@104
    59
            "THREAD: main MSG: Begin" +
jtulach@104
    60
            "THREAD: .*AWT.* MSG: In.*thread" +
jtulach@104
    61
            "THREAD: main MSG: Will create JLabel" +
jtulach@104
    62
            "THREAD: .*AWT.* MSG: Will create JLabel", 
jtulach@104
    63
            300
jtulach@104
    64
        );
jtulach@104
    65
        
jtulach@104
    66
        R showFrame = new R();
jtulach@104
    67
        SwingUtilities.invokeLater(showFrame);
jtulach@104
    68
        
jtulach@104
    69
        LOG.info("Begin");
jtulach@104
    70
        JLabel result = instance.createLabel();
jtulach@104
    71
        assertNotNull("Creates the result", result);
jtulach@104
    72
    }
jtulach@104
    73
jtulach@105
    74
}
jtulach@105
    75
// END: deadlock.test.controlflow
jtulach@105
    76