samples/friendpackage/test/org/apidesign/friendpackage/impl/AccessorTest.java
changeset 407 e1439046d96e
parent 128 8ef997796d0a
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/samples/friendpackage/test/org/apidesign/friendpackage/impl/AccessorTest.java	Sun Oct 06 22:05:14 2013 +0200
     1.3 @@ -0,0 +1,54 @@
     1.4 +/*
     1.5 + *                 Sun Public License Notice
     1.6 + * 
     1.7 + * The contents of this file are subject to the Sun Public License
     1.8 + * Version 1.0 (the "License"). You may not use this file except in
     1.9 + * compliance with the License. A copy of the License is available at
    1.10 + * http://www.sun.com/
    1.11 + * 
    1.12 + * The Original Code is NetBeans. The Initial Developer of the Original
    1.13 + * Code is Jaroslav Tulach. Portions Copyright 2007 Jaroslav Tulach. 
    1.14 + * All Rights Reserved.
    1.15 + */
    1.16 +
    1.17 +package org.apidesign.friendpackage.impl;
    1.18 +
    1.19 +import javax.swing.event.ChangeEvent;
    1.20 +import javax.swing.event.ChangeListener;
    1.21 +import junit.framework.TestCase;
    1.22 +import org.apidesign.friendpackage.api.Item;
    1.23 +
    1.24 +/**
    1.25 + *
    1.26 + * @author Jaroslav Tulach
    1.27 + */
    1.28 +public class AccessorTest extends TestCase 
    1.29 +implements ChangeListener {
    1.30 +
    1.31 +    private int cnt;
    1.32 +    
    1.33 +    public AccessorTest(String testName) {
    1.34 +        super(testName);
    1.35 +    }
    1.36 +
    1.37 +    public void testGetTheItemAttachListenerChangeValue() {
    1.38 +        // BEGIN: design.less.friend.use
    1.39 +        Item item = Accessor.getDefault().newItem();
    1.40 +        assertNotNull("Some item is really created", item);
    1.41 +        
    1.42 +        Accessor.getDefault().addChangeListener(item, this);
    1.43 +        // END: design.less.friend.use
    1.44 +        
    1.45 +        item.setValue(10);
    1.46 +        assertEquals("Value is 10", 10, item.getValue());
    1.47 +        cnt = 0;
    1.48 +        item.setValue(7);
    1.49 +        assertEquals("Now it is 7", 7, item.getValue());
    1.50 +        
    1.51 +        assertEquals("There was one change", 1, cnt);
    1.52 +    }
    1.53 +
    1.54 +    public void stateChanged(ChangeEvent e) {
    1.55 +        cnt++;
    1.56 +    }
    1.57 +}