PageRenderTime 30ms CodeModel.GetById 24ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/eclipse-plugin/com.google.test.metric.eclipse.test/src/main/java/com/google/test/metric/eclipse/internal/util/JavaProjectHelperTest.java

http://testability-explorer.googlecode.com/
Java | 59 lines | 50 code | 9 blank | 0 comment | 0 complexity | 58964b526cd26418a46c1607fac9dc4f MD5 | raw file
 1package com.google.test.metric.eclipse.internal.util;
 2
 3import static org.easymock.EasyMock.expect;
 4
 5import junit.framework.TestCase;
 6
 7import org.easymock.EasyMock;
 8import org.easymock.IMocksControl;
 9import org.eclipse.core.resources.IResource;
10import org.eclipse.core.runtime.Path;
11import org.eclipse.jdt.core.IJavaProject;
12import org.eclipse.jdt.core.IPackageFragmentRoot;
13
14public class JavaProjectHelperTest extends TestCase {
15  private IJavaProject javaProject;
16  private JavaProjectHelper javaProjectHelper;
17  private IMocksControl control;
18
19  @Override
20  protected void setUp() throws Exception {
21    control = EasyMock.createControl();
22    javaProject = control.createMock(IJavaProject.class);
23    javaProjectHelper = new JavaProjectHelper();
24  }
25
26  public void testGetAllJavaPackagesReturnsEmptyListWhenAllFragmentsAreArchives() throws Exception {
27    IPackageFragmentRoot[] roots = new IPackageFragmentRoot[1];
28    IPackageFragmentRoot root = control.createMock(IPackageFragmentRoot.class);
29    expect(root.isArchive()).andReturn(true);
30    roots[0] = root;
31    expect(javaProject.getPackageFragmentRoots()).andReturn(roots);
32    control.replay();
33    assertEquals(0, javaProjectHelper.getAllJavaPackages(javaProject).size());
34    control.verify();
35  }
36
37  public void testGetAllJavaPackagesReturnsEmptyListWhenNoFragments() throws Exception {
38    expect(javaProject.getPackageFragmentRoots()).andReturn(new IPackageFragmentRoot[0]);
39    control.replay();
40    assertEquals(0, javaProjectHelper.getAllJavaPackages(javaProject).size());
41    control.verify();
42  }
43
44  public void testGetAllJavaPackagesReturnsPackageWhenItsThere() throws Exception {
45    IPackageFragmentRoot[] roots = new IPackageFragmentRoot[1];
46    IPackageFragmentRoot root = control.createMock(IPackageFragmentRoot.class);
47    IResource resource = control.createMock(IResource.class);
48    expect(resource.getFullPath()).andReturn(new Path("SomePath"));
49    resource.accept(EasyMock.isA(JavaPackageVisitor.class), EasyMock.anyInt());
50    
51    expect(root.isArchive()).andReturn(false);
52    expect(root.getCorrespondingResource()).andReturn(resource);
53    roots[0] = root;
54    expect(javaProject.getPackageFragmentRoots()).andReturn(roots);
55    control.replay();
56    javaProjectHelper.getAllJavaPackages(javaProject);
57    control.verify();
58  }
59}