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