Changeset 267 in josm for test/org/openstreetmap/josm/plugins
- Timestamp:
- 2007-06-30T22:01:02+02:00 (18 years ago)
- Location:
- test/org/openstreetmap/josm/plugins
- Files:
-
- 4 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
test/org/openstreetmap/josm/plugins/PluginExceptionTest.java
r153 r267 9 9 PluginException e = new PluginException(new PluginProxy(new String(), null), "42", barEx); 10 10 assertEquals(barEx, e.getCause()); 11 assertEquals("42", e. getName());11 assertEquals("42", e.name); 12 12 } 13 13 -
test/org/openstreetmap/josm/plugins/PluginInformationTest.java
r169 r267 1 1 package org.openstreetmap.josm.plugins; 2 2 3 import java.io.ByteArrayInputStream; 4 import java.io.ByteArrayOutputStream; 3 5 import java.io.File; 6 import java.net.URL; 7 import java.net.URLClassLoader; 8 import java.util.Arrays; 9 import java.util.Collection; 10 import java.util.jar.JarInputStream; 4 11 5 12 import junit.framework.TestCase; 6 13 14 import org.openstreetmap.josm.Main; 15 import org.openstreetmap.josm.data.Preferences; 16 7 17 public class PluginInformationTest extends TestCase { 18 19 @Override protected void setUp() throws Exception { 20 super.setUp(); 21 Main.pref = new Preferences(){ 22 @Override public Collection<String> getAllPossiblePreferenceDirs() { 23 return Arrays.asList(new String[]{getClass().getResource("..").getFile()}); 24 } 25 }; 26 } 8 27 9 28 public void testConstructorExtractsAttributesFromManifest() throws Exception { 10 29 PluginInformation info = new PluginInformation(new File(getClass().getResource("simple.jar").getFile())); 11 30 String s = getClass().getResource(".").getFile(); 12 13 assertEquals(4, info.libraries.size()); 14 assertEquals(s+"foo", info.libraries.get(1).getFile()); 15 assertEquals(s+"bar", info.libraries.get(2).getFile()); 16 assertEquals(s+"C:/Foo%20and%20Bar", info.libraries.get(3).getFile()); 17 18 assertEquals("imi", info.author); 19 assertEquals("Simple", info.className); 20 assertEquals("Simpler", info.description); 21 assertEquals(true, info.early); 31 assertEquals(4, info.libraries.size()); 32 assertEquals(s+"foo", info.libraries.get(1).getFile()); 33 assertEquals(s+"bar", info.libraries.get(2).getFile()); 34 assertEquals(s+"C:/Foo%20and%20Bar", info.libraries.get(3).getFile()); 35 36 assertEquals("imi", info.author); 37 assertEquals("Simple", info.className); 38 assertEquals("Simpler", info.description); 39 assertEquals(true, info.early); 40 } 41 42 public void testConstructorRequiresJarWithManifest() throws Exception { 43 try { 44 new PluginInformation(new File(getClass().getResource("no_manifest.jar").getFile())); 45 fail("Exception because missing manifest excpected"); 46 } catch (PluginException e) { 47 } 48 } 49 50 public void testConstructorWithInputStream() throws Exception { 51 JarInputStream f = new JarInputStream(getClass().getResourceAsStream("simple.jar")); 52 ByteArrayOutputStream out = new ByteArrayOutputStream(); 53 f.getManifest().write(out); 54 55 PluginInformation info = new PluginInformation(null, "simple", new ByteArrayInputStream(out.toByteArray())); 56 assertEquals("Only the 3 external classpaths are added (as we are using bootstrap classpath for plugin", 57 3, info.libraries.size()); 58 } 59 60 public void testLoadClassInstantiatePlugin() throws Exception { 61 PluginInformation info = new PluginInformation(new File(getClass().getResource("working.jar").getFile())); 62 ClassLoader cl = new URLClassLoader(new URL[]{getClass().getResource("working.jar")}); 63 assertNotNull(info.load(info.loadClass(cl))); 64 } 65 66 // This is so the bugtracker always detect coding problems as "plugin problems" 67 public void testLoadThrowsPluginExceptionOnRuntimeException() throws Exception { 68 PluginInformation info = new PluginInformation(new File(getClass().getResource("working.jar").getFile())); 69 try { 70 info.load(null); 71 fail("Exception excpected because null-Class"); 72 } catch (PluginException e) { 73 } 74 try { 75 info.loadClass(null); 76 fail("Exception excpected because null-ClassLoader"); 77 } catch (PluginException e) { 78 } 79 } 80 81 public void testFindPluginReturnsInformationFromBootstrapClasspath() throws Exception { 82 PluginInformation info = PluginInformation.findPlugin("test_simple"); 83 assertEquals("Simpler", info.description); 84 } 85 86 public void testFindPluginReturnsFromPreferencesDirs() throws Exception { 87 PluginInformation info = PluginInformation.findPlugin("simple"); 88 assertEquals("Simpler", info.description); 89 } 90 91 public void testFindPluginForUnknownReturnsNull() throws Exception { 92 assertNull(PluginInformation.findPlugin("asdf")); 93 } 94 95 public void testPluginLocationsReturnModifiedPreferenceLocations() throws Exception { 96 setUp(); 97 Collection<String> locations = PluginInformation.getPluginLocations(); 98 assertEquals(1, locations.size()); 99 assertTrue(locations.iterator().next().endsWith("/plugins")); 22 100 } 23 101 }
Note:
See TracChangeset
for help on using the changeset viewer.