View Javadoc

1   package com.atlassian.plugin.factories;
2   
3   import com.atlassian.plugin.ModuleDescriptorFactory;
4   import com.atlassian.plugin.PluginAccessor;
5   import com.atlassian.plugin.PluginParseException;
6   import com.atlassian.plugin.PluginArtifact;
7   import com.atlassian.plugin.loaders.classloading.DeploymentUnit;
8   
9   import com.mockobjects.dynamic.Mock;
10  import com.mockobjects.dynamic.C;
11  
12  import java.io.File;
13  
14  import junit.framework.TestCase;
15  
16  public class TestLegacyDynamicPluginFactory extends TestCase
17  {
18      public void testCreateCorruptJar()
19      {
20          final LegacyDynamicPluginFactory factory = new LegacyDynamicPluginFactory(PluginAccessor.Descriptor.FILENAME);
21          final Mock mockModuleDescriptorFactory = new Mock(ModuleDescriptorFactory.class);
22          try
23          {
24              Mock mockArtifact = new Mock(PluginArtifact.class);
25              mockArtifact.expectAndReturn("getResourceAsStream", C.ANY_ARGS, null);
26              mockArtifact.expectAndReturn("toFile", new File("sadfasdf"));
27              factory.create((PluginArtifact) mockArtifact.proxy(), (ModuleDescriptorFactory) mockModuleDescriptorFactory.proxy());
28              fail("Should have thrown an exception");
29          }
30          catch (final PluginParseException ex)
31          {
32              // horray!
33          }
34          catch (final Exception ex)
35          {
36              ex.printStackTrace();
37              fail("No exceptions allowed");
38          }
39      }
40  }