Simplifying some tests with MockServices.
1.1 --- a/xmlnavigation/test/unit/src/org/netbeans/modules/xmlnavigation/XMLNavigatorPanelTest.java Sat Mar 25 11:12:23 2006 -0500
1.2 +++ b/xmlnavigation/test/unit/src/org/netbeans/modules/xmlnavigation/XMLNavigatorPanelTest.java Fri May 12 17:49:54 2006 -0400
1.3 @@ -7,7 +7,7 @@
1.4 * http://www.sun.com/
1.5 *
1.6 * The Original Code is NetBeans. The Initial Developer of the Original
1.7 - * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun
1.8 + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
1.9 * Microsystems, Inc. All Rights Reserved.
1.10 */
1.11
1.12 @@ -17,11 +17,8 @@
1.13 import java.io.StringReader;
1.14 import junit.framework.Assert;
1.15 import org.netbeans.api.xml.services.UserCatalog;
1.16 +import org.netbeans.junit.MockServices;
1.17 import org.netbeans.junit.NbTestCase;
1.18 -import org.netbeans.modules.xmlnavigation.XMLNavigatorPanel.Item;
1.19 -import org.openide.util.Lookup;
1.20 -import org.openide.util.lookup.Lookups;
1.21 -import org.openide.util.lookup.ProxyLookup;
1.22 import org.xml.sax.EntityResolver;
1.23 import org.xml.sax.InputSource;
1.24 import org.xml.sax.SAXException;
1.25 @@ -32,36 +29,13 @@
1.26 */
1.27 public class XMLNavigatorPanelTest extends NbTestCase {
1.28
1.29 - static {
1.30 - System.setProperty("org.openide.util.Lookup", Lkp.class.getName());
1.31 - Assert.assertEquals(Lkp.class, Lookup.getDefault().getClass());
1.32 - }
1.33 - public static final class Lkp extends ProxyLookup {
1.34 - private static Lkp DEFAULT;
1.35 - public Lkp() {
1.36 - Assert.assertNull(DEFAULT);
1.37 - DEFAULT = this;
1.38 - setLookup(new Object[0]);
1.39 - }
1.40 - public static void setLookup(Object[] instances) {
1.41 - ClassLoader l = Lkp.class.getClassLoader();
1.42 - DEFAULT.setLookups(new Lookup[] {
1.43 - Lookups.fixed(instances),
1.44 - Lookups.metaInfServices(l),
1.45 - Lookups.singleton(l),
1.46 - });
1.47 - }
1.48 - }
1.49 -
1.50 public XMLNavigatorPanelTest(String name) {
1.51 super(name);
1.52 }
1.53
1.54 protected void setUp() throws Exception {
1.55 super.setUp();
1.56 - Lkp.setLookup(new Object[] {
1.57 - new TestCatalog(),
1.58 - });
1.59 + MockServices.setServices(new Class[] {TestCatalog.class});
1.60 }
1.61
1.62 public void testParseXHTML() throws Exception {
1.63 @@ -132,11 +106,11 @@
1.64 */
1.65 }
1.66
1.67 - private static Item[] parse(String xml) throws Exception {
1.68 + private static XMLNavigatorPanel.Item[] parse(String xml) throws Exception {
1.69 return XMLNavigatorPanel.parse(new InputSource(new StringReader(xml)), null);
1.70 }
1.71
1.72 - private static String itemsSummary(Item[] items) {
1.73 + private static String itemsSummary(XMLNavigatorPanel.Item[] items) {
1.74 StringBuffer b = new StringBuffer();
1.75 for (int i = 0; i < items.length; i++) {
1.76 b.append(items[i].getLine());
1.77 @@ -151,7 +125,7 @@
1.78 return b.toString();
1.79 }
1.80
1.81 - private static final class TestCatalog extends UserCatalog implements EntityResolver {
1.82 + public static final class TestCatalog extends UserCatalog implements EntityResolver {
1.83 public TestCatalog() {}
1.84 public EntityResolver getEntityResolver() {
1.85 return this;