samples/friendpackage/test/implpkg/AccessorTest.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Jun 2008 09:50:27 +0200
changeset 3 b44baa125b38
parent 0 32b39aaa68f0
child 6 b577ee7fcf67
permissions -rw-r--r--
Accessor example is taken from real source code
jtulach@0
     1
/*
jtulach@0
     2
 *                 Sun Public License Notice
jtulach@0
     3
 * 
jtulach@0
     4
 * The contents of this file are subject to the Sun Public License
jtulach@0
     5
 * Version 1.0 (the "License"). You may not use this file except in
jtulach@0
     6
 * compliance with the License. A copy of the License is available at
jtulach@0
     7
 * http://www.sun.com/
jtulach@0
     8
 * 
jtulach@0
     9
 * The Original Code is NetBeans. The Initial Developer of the Original
jtulach@0
    10
 * Code is Sun Microsystems, Inc. Portions Copyright 1999-2006 Sun
jtulach@0
    11
 * Microsystems, Inc. All Rights Reserved.
jtulach@0
    12
 */
jtulach@0
    13
jtulach@0
    14
package implpkg;
jtulach@0
    15
jtulach@0
    16
import javax.swing.event.ChangeEvent;
jtulach@0
    17
import junit.framework.TestCase;
jtulach@0
    18
import junit.framework.*;
jtulach@0
    19
import apipkg.Item;
jtulach@0
    20
import javax.swing.event.ChangeListener;
jtulach@0
    21
jtulach@0
    22
/**
jtulach@0
    23
 *
jtulach@0
    24
 * @author Jaroslav Tulach
jtulach@0
    25
 */
jtulach@0
    26
public class AccessorTest extends TestCase 
jtulach@0
    27
implements ChangeListener {
jtulach@0
    28
jtulach@0
    29
    private int cnt;
jtulach@0
    30
    
jtulach@0
    31
    public AccessorTest(String testName) {
jtulach@0
    32
        super(testName);
jtulach@0
    33
    }
jtulach@0
    34
jtulach@0
    35
    protected void setUp() throws Exception {
jtulach@0
    36
    }
jtulach@0
    37
jtulach@0
    38
    protected void tearDown() throws Exception {
jtulach@0
    39
    }
jtulach@0
    40
    
jtulach@0
    41
    public void testGetTheItemAttachListenerChangeValue() {
jtulach@3
    42
        // BEGIN: design.less.friend.use
jtulach@0
    43
        Item item = Accessor.DEFAULT.newItem();
jtulach@0
    44
        assertNotNull("Some item is really created", item);
jtulach@0
    45
        
jtulach@0
    46
        Accessor.DEFAULT.addChangeListener(item, this);
jtulach@3
    47
        // END: design.less.friend.use
jtulach@0
    48
        
jtulach@0
    49
        item.setValue(10);
jtulach@0
    50
        assertEquals("Value is 10", 10, item.getValue());
jtulach@0
    51
        cnt = 0;
jtulach@0
    52
        item.setValue(7);
jtulach@0
    53
        assertEquals("Now it is 7", 7, item.getValue());
jtulach@0
    54
        
jtulach@0
    55
        assertEquals("There was one change", 1, cnt);
jtulach@0
    56
    }
jtulach@0
    57
jtulach@0
    58
    public void stateChanged(ChangeEvent e) {
jtulach@0
    59
        cnt++;
jtulach@0
    60
    }
jtulach@0
    61
}