alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 * 
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 * 
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package org.netbeans.spi.looks;

import org.netbeans.junit.*;

import java.io.IOException;
import javax.swing.Action;

import org.openide.util.Lookup;

import org.netbeans.spi.looks.*;
import org.openide.filesystems.FileUtil;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.Repository;


/** Tests whether the DefaultLook returns proper values 
 */
public class DefaultLookValuesTest extends TestBaseValues {
    
    // Methods of testCase -----------------------------------------------------
    
    public DefaultLookValuesTest(java.lang.String testName) {
        super(testName);
    }
    
    public static void main(java.lang.String[] args) {
        junit.textui.TestRunner.run(suite());
    }
    
    public static NbTest suite() {
        NbTestSuite suite = new NbTestSuite(DefaultLookValuesTest.class);
        return suite;
    }    
    
    protected void setUp() throws Exception {       
        
        Look look = createLook();
        setTarget( look, new SampleRepObject(), 1 );
        setGoldenValues( createGoldenValues() );

        super.setUp();    
    }
    
    protected void tearDown() throws Exception {
        super.tearDown();
    }
    
    
    // Test methods ------------------------------------------------------------
    
    /////////////////////////////////////////////////////////////////
    //                                                             //
    //  All methods except one are inherited from: TestBaseValues  //
    //                                                             //
    /////////////////////////////////////////////////////////////////
      
    public void testGetActions() throws Exception {

        Action[] actions = look.getActions( representedObject, NO_LOOKUP );
        
        if ( actions != null ) {
            fail( MSSG_UNEXPECTED_VALUE_RETURNED + actions );
        }
        
        String folderName = "Looks/Actions/" + look.getClass().getName().replace( '.', '/' ) + 
            "/org-openide-actions-NewAction.instance";
        
        FileObject fo = FileUtil.createData (
            Repository.getDefault ().getDefaultFileSystem().getRoot(),
            folderName
        );
        
        actions = look.getActions ( representedObject, NO_LOOKUP );
        
        assertNotNull ("Not null", actions);
        assertEquals ("One action", actions.length, 1);
        assertTrue ("NewAction", actions[0] instanceof org.openide.actions.NewAction);
        
        fo.delete ();
    }
    
    public void testIconBase() throws Exception {
        fail( "The test case empty" );
    }
    
    public void testActionBase() throws Exception {
        fail( "The test case empty" );
    }
    
    // Private helper methods --------------------------------------------------
    
    private static GoldenValue[] createGoldenValues() {
        return new GoldenValue[] {
            new GoldenValue( ProxyLook.GET_DISPLAY_NAME, null ),
            new GoldenValue( ProxyLook.GET_NAME, null ),
            // new GoldenValue( ProxyLook.RENAME )
            new GoldenValue( ProxyLook.GET_SHORT_DESCRIPTION, null ),
            new GoldenValue( ProxyLook.GET_ICON, null ),
            new GoldenValue( ProxyLook.GET_OPENED_ICON, null ),
            new GoldenValue( ProxyLook.GET_HELP_CTX, null ),
            new GoldenValue( ProxyLook.GET_CHILD_OBJECTS, null ),
            new GoldenValue( ProxyLook.GET_NEW_TYPES, null ),
            new GoldenValue( ProxyLook.GET_ACTIONS, null ),
            new GoldenValue( ProxyLook.GET_CONTEXT_ACTIONS, null ),
            new GoldenValue( ProxyLook.GET_DEFAULT_ACTION, null ),
            new GoldenValue( ProxyLook.GET_PROPERTY_SETS, null ),
            new GoldenValue( ProxyLook.GET_CUSTOMIZER, null ),
            new GoldenValue( ProxyLook.HAS_CUSTOMIZER, Boolean.FALSE ),
            new GoldenValue( ProxyLook.CAN_RENAME, Boolean.FALSE ),
            new GoldenValue( ProxyLook.CAN_DESTROY, Boolean.FALSE ),
            new GoldenValue( ProxyLook.CAN_COPY, Boolean.FALSE ),
            new GoldenValue( ProxyLook.CAN_CUT, Boolean.FALSE ),
            new GoldenValue( ProxyLook.GET_PASTE_TYPES, null ),
            new GoldenValue( ProxyLook.GET_DROP_TYPE, null ),
            new GoldenValue( ProxyLook.CLIPBOARD_COPY, null ),
            new GoldenValue( ProxyLook.CLIPBOARD_CUT, null ),
            new GoldenValue( ProxyLook.DRAG, null ),
            new GoldenValue( ProxyLook.GET_LOOKUP_ITEMS, null )
            // new GoldenValue( ProxyLook.DESTROY )    
        };
    }
    
    private static Look createLook() {
        return new DefaultLook( "DefaultLookTest" ) {
                        
            public void attachTo( Object representedObject ) {
                super.attachTo( representedObject );                
                
                if ( representedObject instanceof SampleRepObject ) {
                    ((SampleRepObject)representedObject).attach();
                }
                // return new Look.NodeSubstitute( representedObject, this, null / PENDING / );        

            }
            
            public void rename(Object representedObject, String newName, Lookup env ) {
                if ( representedObject instanceof SampleRepObject ) {
                    ((SampleRepObject)representedObject).setName();
                }
            }
                        
            public void destroy(Object representedObject, Lookup env ) throws IOException {
               if ( representedObject instanceof SampleRepObject ) {
                    ((SampleRepObject)representedObject).destroy();
                }
            }            
        };
    }
}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.