Changeset 267 in josm for test/org/openstreetmap/josm
- Timestamp:
- 2007-06-30T22:01:02+02:00 (17 years ago)
- Location:
- test/org/openstreetmap/josm
- Files:
-
- 4 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
test/org/openstreetmap/josm/data/osm/OsmPrimitiveTest.java
r146 r267 44 44 } 45 45 46 public void testHashCodeReturnsIdIfNotZeroAndNotZeroIfIdIsZero() {47 osm.id = 23;48 assertEquals(23, osm.hashCode());49 osm.id = 0;50 assertTrue(0 != osm.hashCode());51 }52 53 46 public void testVisit() { 54 47 osm.visit(new Visitor(){ -
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 } -
test/org/openstreetmap/josm/tools/XmlObjectParserTest.java
r193 r267 52 52 } 53 53 54 public void testManyTags() throws Exception {55 StringBuilder b = new StringBuilder("<all>");56 for (int i = 0; i < 50000; ++i) {57 if (Math.random() > 0.5) {58 b.append("<foo bar='blob");59 b.append(i);60 b.append("'/>");61 } else {62 b.append("<foo><bar>yuppel");63 b.append(i);64 b.append("</bar></foo>");65 }66 }67 b.append("</all>");68 69 System.gc();70 long memBefore = Runtime.getRuntime().freeMemory();71 parser = createParser(b.toString());72 Thread.sleep(300);73 System.gc();74 long memAfter = Runtime.getRuntime().freeMemory();75 assertTrue("2MB should be more than enough. "+(memAfter-memBefore), memAfter-memBefore < 2*1024*1024);76 77 for (int i = 0; i < 50000; ++i) {78 Foo f = (Foo)parser.next();79 assertTrue(f.bar.equals("blob"+i) || f.bar.equals("yuppel"+i));80 }81 assertFalse(parser.hasNext());82 }83 84 54 public void testIterable() throws Exception { 85 55 parser = createParser("<xml><foo bar='yo'/><foo bar='yo'/><foo bar='yo'/></xml>");
Note:
See TracChangeset
for help on using the changeset viewer.