samples/friendpackage/test/implpkg/AccessorTest.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Jun 2008 09:50:50 +0200
changeset 6 b577ee7fcf67
parent 3 b44baa125b38
child 35 ecab95a52f10
permissions -rw-r--r--
example with conditional usage of an API
     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     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 }