1 19 20 package org.netbeans.api.project.libraries; 21 22 import java.net.URL ; 23 import java.util.ArrayList ; 24 import java.util.List ; 25 import org.netbeans.api.project.TestUtil; 26 import org.netbeans.junit.NbTestCase; 27 import org.netbeans.spi.project.libraries.LibraryImplementation; 28 import org.netbeans.spi.project.libraries.LibraryProvider; 29 import org.openide.util.lookup.Lookups; 30 34 public class LibraryTest extends NbTestCase { 35 36 private LibraryManagerTest.TestLibraryProvider lp; 37 38 39 public LibraryTest (String testName) { 40 super (testName); 41 } 42 43 protected void setUp() throws Exception { 44 super.setUp(); 45 lp = new LibraryManagerTest.TestLibraryProvider (); 46 TestUtil.setLookup (Lookups.fixed(new Object [] {lp})); 47 } 48 49 public void testGetLibraries () throws Exception { 50 LibraryManager lm = LibraryManager.getDefault(); 51 Library[] libs = lm.getLibraries(); 52 LibraryImplementation[] impls = LibraryManagerTest.createTestLibs (); 53 lp.setLibraries(impls); 54 libs = lm.getLibraries(); 55 assertEquals ("Libraries count", 2, libs.length); 56 LibraryManagerTest.assertLibsEquals (libs, impls); 57 LibraryManagerTest.TestListener tl = new LibraryManagerTest.TestListener (); 58 libs[0].addPropertyChangeListener(tl); 59 impls[0].setName("NewLibrary1"); 60 LibraryManagerTest.assertEventsEquals(tl.getEventNames(), new String [] {Library.PROP_NAME}); 61 tl.reset(); 62 LibraryManagerTest.assertLibsEquals (new Library[] {libs[0]}, new LibraryImplementation[] {impls[0]}); 63 64 impls[0].setDescription("NewLibrary1Description"); 65 LibraryManagerTest.assertEventsEquals(tl.getEventNames(), new String [] {Library.PROP_DESCRIPTION}); 66 tl.reset(); 67 LibraryManagerTest.assertLibsEquals (new Library[] {libs[0]}, new LibraryImplementation[] {impls[0]}); 68 List <URL > urls = new ArrayList <URL >(); 69 urls.add (new URL ("file:/lib/libnew1.so")); 70 urls.add (new URL ("file:/lib/libnew2.so")); 71 impls[0].setContent ("bin",urls); 72 LibraryManagerTest.assertEventsEquals(tl.getEventNames(), new String [] {Library.PROP_CONTENT}); 73 tl.reset(); 74 LibraryManagerTest.assertLibsEquals (new Library[] {libs[0]}, new LibraryImplementation[] {impls[0]}); 75 urls = new ArrayList <URL >(); 76 urls.add (new URL ("file:/src/new/src/")); 77 impls[0].setContent ("src",urls); 78 LibraryManagerTest.assertEventsEquals(tl.getEventNames(), new String [] {Library.PROP_CONTENT}); 79 tl.reset(); 80 LibraryManagerTest.assertLibsEquals (new Library[] {libs[0]}, new LibraryImplementation[] {impls[0]}); 81 } 82 83 } 84 | Popular Tags |