PageRenderTime 24ms CodeModel.GetById 14ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/eclipse-plugin/com.google.test.metric.eclipse.test/src/main/java/com/google/test/metric/eclipse/internal/core/TestabilityLauncherTest.java

http://testability-explorer.googlecode.com/
Java | 88 lines | 57 code | 12 blank | 19 comment | 0 complexity | bcb84449fef980e51758c55fdd7d9bfa MD5 | raw file
 1/*
 2 * Copyright 2009 Google Inc.
 3 * 
 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 5 * use this file except in compliance with the License. You may obtain a copy of
 6 * the License at
 7 * 
 8 * http://www.apache.org/licenses/LICENSE-2.0
 9 * 
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
14 * the License.
15 */
16package com.google.test.metric.eclipse.internal.core;
17
18import static org.easymock.EasyMock.expect;
19
20import junit.framework.TestCase;
21
22import org.easymock.EasyMock;
23import org.easymock.IMocksControl;
24import org.eclipse.core.runtime.Path;
25import org.eclipse.jdt.core.IClasspathEntry;
26import org.eclipse.jdt.core.IJavaProject;
27
28/**
29 * @author klundberg@google.com (Karin Lundberg)
30 * 
31 */
32public class TestabilityLauncherTest extends TestCase {
33  private TestabilityLauncher launcher;
34  private IJavaProject javaProject;
35  private IMocksControl control;
36
37  @Override
38  protected void setUp() throws Exception {
39    launcher = new TestabilityLauncher();
40    control = EasyMock.createControl();
41    javaProject = control.createMock(IJavaProject.class);
42  }
43
44  public void testGetClassPathsReturnsDefaultOutputPath() throws Exception {
45    expect(javaProject.getRawClasspath()).andReturn(new IClasspathEntry[0]);
46    expect(javaProject.getOutputLocation()).andReturn(new Path("/expected"));
47    control.replay();
48    String[] results = launcher.getClassPaths(javaProject, "whatever");
49    assertEquals(1, results.length);
50    assertEquals("whatever/expected", results[0]);
51    control.verify();
52  }
53  
54  public void testGetClassPathsReturnsAbsoluePathWhenOutputPathNull() throws Exception {
55    IClasspathEntry[] entries = new IClasspathEntry[1];
56    entries[0] = control.createMock(IClasspathEntry.class);
57    expect(entries[0].getOutputLocation()).andReturn(null);
58    expect(entries[0].getPath()).andReturn(new Path("/expectedpath"));
59    expect(javaProject.getRawClasspath()).andReturn(entries);
60    expect(javaProject.getOutputLocation()).andReturn(new Path("/expected2"));
61    control.replay();
62    String projectLocation = "location";
63    
64    String[] results = launcher.getClassPaths(javaProject, projectLocation);
65    
66    assertEquals(2, results.length);
67    assertEquals(projectLocation + "/expectedpath", results[0]);
68    assertEquals(projectLocation + "/expected2", results[1]);
69    control.verify();
70  }
71
72  public void testGetClassPathsReturnsAbsoluePathWhenOutputPathNotNull() throws Exception {
73    IClasspathEntry[] entries = new IClasspathEntry[1];
74    entries[0] = control.createMock(IClasspathEntry.class);
75    expect(entries[0].getOutputLocation()).andReturn(new Path("/expected"));
76    expect(javaProject.getRawClasspath()).andReturn(entries);
77    expect(javaProject.getOutputLocation()).andReturn(new Path("/expected2"));
78    control.replay();
79    String projectLocation = "location";
80    
81    String[] results = launcher.getClassPaths(javaProject, projectLocation);
82    
83    assertEquals(2, results.length);
84    assertEquals(projectLocation + "/expected", results[0]);
85    assertEquals(projectLocation + "/expected2", results[1]);
86    control.verify();
87  }
88}