samples/friendpackage/test/implpkg/AccessorTest.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Jun 2008 09:55:09 +0200
changeset 128 8ef997796d0a
parent 127 07696c62f340
permissions -rw-r--r--
Merge: Patrick's fixes
     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 Jaroslav Tulach. Portions Copyright 2007 Jaroslav Tulach. 
    11  * 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     public void testGetTheItemAttachListenerChangeValue() {
    36         // BEGIN: design.less.friend.use
    37         Item item = Accessor.getDefault().newItem();
    38         assertNotNull("Some item is really created", item);
    39         
    40         Accessor.getDefault().addChangeListener(item, this);
    41         // END: design.less.friend.use
    42         
    43         item.setValue(10);
    44         assertEquals("Value is 10", 10, item.getValue());
    45         cnt = 0;
    46         item.setValue(7);
    47         assertEquals("Now it is 7", 7, item.getValue());
    48         
    49         assertEquals("There was one change", 1, cnt);
    50     }
    51 
    52     public void stateChanged(ChangeEvent e) {
    53         cnt++;
    54     }
    55 }