Lines 45-50
Link Here
|
45 |
package org.netbeans.modules.settings.convertors; |
45 |
package org.netbeans.modules.settings.convertors; |
46 |
|
46 |
|
47 |
import java.io.*; |
47 |
import java.io.*; |
|
|
48 |
import java.lang.ref.Reference; |
49 |
import java.lang.ref.WeakReference; |
50 |
import java.util.Properties; |
51 |
import static junit.framework.Assert.assertEquals; |
52 |
import static junit.framework.Assert.assertNotNull; |
53 |
import org.netbeans.api.settings.ConvertAsProperties; |
54 |
import org.netbeans.api.settings.FactoryMethod; |
48 |
|
55 |
|
49 |
import org.netbeans.junit.NbTestCase; |
56 |
import org.netbeans.junit.NbTestCase; |
50 |
import org.netbeans.junit.RandomlyFails; |
57 |
import org.netbeans.junit.RandomlyFails; |
Lines 58-63
Link Here
|
58 |
import org.openide.filesystems.FileObject; |
65 |
import org.openide.filesystems.FileObject; |
59 |
import org.openide.filesystems.FileSystem; |
66 |
import org.openide.filesystems.FileSystem; |
60 |
import org.openide.filesystems.FileUtil; |
67 |
import org.openide.filesystems.FileUtil; |
|
|
68 |
import org.openide.filesystems.Repository; |
61 |
import org.openide.filesystems.XMLFileSystem; |
69 |
import org.openide.filesystems.XMLFileSystem; |
62 |
import org.openide.loaders.*; |
70 |
import org.openide.loaders.*; |
63 |
import org.openide.modules.ModuleInfo; |
71 |
import org.openide.modules.ModuleInfo; |
Lines 352-357
Link Here
|
352 |
assertEquals("Listener not deregistered", 0, obj.getListenerCount()); |
360 |
assertEquals("Listener not deregistered", 0, obj.getListenerCount()); |
353 |
assertNull(filename + ".settings was not deleted!", root.getFileObject(filename)); |
361 |
assertNull(filename + ".settings was not deleted!", root.getFileObject(filename)); |
354 |
} |
362 |
} |
|
|
363 |
|
364 |
public void testFactoryMethod() throws Exception { |
365 |
FileObject dtdFO = Repository.getDefault().getDefaultFileSystem(). |
366 |
findResource("/xml/lookups/abc/x.instance"); |
367 |
assertNotNull("Provider not found", dtdFO); |
368 |
Convertor c = XMLPropertiesConvertor.create(dtdFO); |
369 |
assertNotNull("Convertor created", c); |
370 |
|
371 |
DataFolder folder = DataFolder.findFolder(root); |
372 |
|
373 |
FactoryBase inst = FactoryBase.create(); |
374 |
InstanceDataObject ido = InstanceDataObject.create(folder, null, inst, null); |
375 |
|
376 |
assertSame("Instance is there", inst, ido.instanceCreate()); |
377 |
|
378 |
Reference<Object> ref = new WeakReference<Object>(inst); |
379 |
inst = null; |
380 |
|
381 |
assertGC("Instance can disappear", ref); |
382 |
|
383 |
Object obj = ido.instanceCreate(); |
384 |
assertEquals("One can re-create it without default constructor", FactoryBase.class, obj.getClass()); |
385 |
} |
386 |
|
387 |
@ConvertAsProperties(dtd = "-//abc/x") |
388 |
@FactoryMethod("create") |
389 |
public static class FactoryBase implements Serializable { |
390 |
public FactoryBase() { |
391 |
throw new IllegalStateException("Don't call my default constructor"); |
392 |
} |
393 |
|
394 |
FactoryBase(boolean ok) { |
395 |
} |
396 |
|
397 |
public static FactoryBase create() { |
398 |
return new FactoryBase(true); |
399 |
} |
400 |
|
401 |
void readProperties(Properties p) { |
402 |
} |
403 |
|
404 |
void writeProperties(Properties p) { |
405 |
} |
406 |
} |
355 |
|
407 |
|
356 |
public void testModuleDisabling() throws Exception { |
408 |
public void testModuleDisabling() throws Exception { |
357 |
FileObject dtd = FileUtil.getConfigFile("xml/lookups/NetBeans_org_netbeans_modules_settings_testModuleDisabling/DTD_XML_FooSetting_1_0.instance"); |
409 |
FileObject dtd = FileUtil.getConfigFile("xml/lookups/NetBeans_org_netbeans_modules_settings_testModuleDisabling/DTD_XML_FooSetting_1_0.instance"); |