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
     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         // BEGIN: design.less.friend.use
    43         Item item = Accessor.DEFAULT.newItem();
    44         assertNotNull("Some item is really created", item);
    45         
    46         Accessor.DEFAULT.addChangeListener(item, this);
    47         // END: design.less.friend.use
    48         
    49         item.setValue(10);
    50         assertEquals("Value is 10", 10, item.getValue());
    51         cnt = 0;
    52         item.setValue(7);
    53         assertEquals("Now it is 7", 7, item.getValue());
    54         
    55         assertEquals("There was one change", 1, cnt);
    56     }
    57 
    58     public void stateChanged(ChangeEvent e) {
    59         cnt++;
    60     }
    61 }