PageRenderTime 30ms CodeModel.GetById 18ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/ant-task/src/test/java/com/google/ant/TaskModelTest.java

http://testability-explorer.googlecode.com/
Java | 171 lines | 134 code | 37 blank | 0 comment | 0 complexity | 3f3fe3de62b6e038e1139c1c6a104296 MD5 | raw file
  1package com.google.ant;
  2
  3import java.io.File;
  4import java.io.OutputStream;
  5import java.util.ArrayList;
  6import java.util.List;
  7import java.util.regex.Matcher;
  8import java.util.regex.Pattern;
  9
 10import junit.framework.TestCase;
 11
 12import org.apache.tools.ant.Project;
 13import org.apache.tools.ant.types.Path;
 14
 15public class TaskModelTest extends TestCase {
 16  private TaskModel model;
 17
 18  public TaskModelTest(String name)
 19  {
 20    super(name);
 21  }
 22
 23  @Override
 24  protected void setUp()
 25  {
 26    model = new TaskModel();
 27  }
 28
 29  @Override
 30  protected void tearDown()
 31  {
 32  }
 33
 34  public void testDefaultPrintDepth()  throws Exception {
 35    assertEquals(model.getPrintDepth(), -1);
 36    model.validate(new ArrayList<String>());
 37    assertEquals(model.getPrintDepth(), TaskModel.DEFAULT_PRINT_DEPTH);
 38  }
 39
 40  public void testDefaultMinCost()  throws Exception {
 41    assertEquals(model.getMinCost(), -1);
 42    model.validate(new ArrayList<String>());
 43    assertEquals(model.getMinCost(), TaskModel.DEFAULT_MIN_COST);
 44  }
 45
 46  public void testDefaultMaxExcellenceCost()  throws Exception {
 47    assertEquals(model.getMaxExcellentCost(), -1);
 48    model.validate(new ArrayList<String>());
 49    assertEquals(model.getMaxExcellentCost(), TaskModel.DEFAULT_MAX_EXCELLENT_COST);
 50  }
 51
 52  public void testDefaultMaxAcceptableCost()  throws Exception {
 53    assertEquals(model.getMaxAcceptableCost(), -1);
 54    model.validate(new ArrayList<String>());
 55    assertEquals(model.getMaxAcceptableCost(), TaskModel.DEFAULT_MAX_ACCEPTABLE_COST);
 56  }
 57
 58  public void testDeafaultWorstOffenderCount()  throws Exception {
 59    assertEquals(model.getWorstOffenderCount(), -1);
 60    model.validate(new ArrayList<String>());
 61    assertEquals(model.getWorstOffenderCount(), TaskModel.DEFAULT_WORST_OFFENDER_COUNT);
 62  }
 63
 64  public void testDefaultWhiteList()  throws Exception {
 65    assertEquals(model.getWhiteList(), null);
 66    model.validate(new ArrayList<String>());
 67    assertEquals(model.getWhiteList(), TaskModel.DEFAULT_WHITE_LIST);
 68  }
 69
 70  public void testDefaultPrint()  throws Exception {
 71    assertEquals(model.getPrint(), null);
 72    model.validate(new ArrayList<String>());
 73    assertEquals(model.getPrint(), TaskModel.DEFAULT_PRINT);
 74  }
 75
 76  public void testDefaultResultFile() throws Exception {
 77    assertEquals(null, model.getResultFile());
 78    model.validate(new ArrayList<String>());
 79    assertEquals(model.getResultFile(), TaskModel.DEFAULT_RESULT_FILE);
 80  }
 81
 82  public void testDefaultErrorFile() throws Exception {
 83    assertEquals(null, model.getErrorFile());
 84    model.validate(new ArrayList<String>());
 85    assertEquals(model.getErrorFile(), TaskModel.DEFAULT_RESULT_FILE); // error becomes result if not set
 86  }
 87
 88  public void testDefaultFilter() throws Exception {
 89    assertEquals(null, model.getFilter());
 90    model.validate(new ArrayList<String>());
 91    assertEquals(model.getFilter(), TaskModel.DEFAULT_FILTER);
 92  }
 93
 94  public void testSystemOutOutputStream() throws Exception {
 95    OutputStream os = model.getOutputStream("System.out");
 96
 97    assertEquals(os, System.out);
 98  }
 99
100  public void testSystemErrOutputStream() throws Exception {
101    OutputStream os = model.getOutputStream("System.err");
102
103    assertEquals(os, System.err);
104  }
105
106  public void testResultStreamError() throws Exception {
107    List<String> messages = new ArrayList<String>();
108
109    model.addClasspath(new Path(new Project()));
110    model.setResultFile("/this/result/file/does/not/exist.txt");
111    assertFalse(model.validate(messages));
112    assertTrue(messages.contains(TaskModel.ERROR_RESULT_FILE_CREATION_FAILED));
113  }
114
115  public void testErrorStreamError() throws Exception {
116    List<String> messages = new ArrayList<String>();
117
118    model.addClasspath(new Path(new Project()));
119    model.setErrorFile("/this/error/file/does/not/exist.txt");
120    assertFalse(model.validate(messages));
121    assertTrue(messages.contains(TaskModel.ERROR_ERROR_FILE_CREATION_FAILED));
122  }
123
124  public void testGetClassPath() throws Exception {
125    Project proj = new Project();
126    Path p = new Path(proj);
127
128    proj.setBasedir(".");
129    p.setLocation(new File("src-test/com/google/ant"));
130
131    model.addClasspath(p);
132    Matcher matcher = Pattern.compile("src-test.com.google.ant").matcher(model.getClassPath());
133    assertTrue(matcher.find());
134  }
135
136  public void testResultFileNotSet() throws Exception {
137    List<String> messages = new ArrayList<String>();
138
139    model.addClasspath(new Path(new Project()));
140    model.setResultFile(null);
141    assertTrue(model.validate(messages));
142    assertTrue(messages.contains(TaskModel.ERROR_RESULT_FILE_NOT_SET));
143  }
144
145  public void testFilterNotSet() throws Exception {
146    List<String> messages = new ArrayList<String>();
147
148    model.addClasspath(new Path(new Project()));
149    model.setFilter(null);
150    assertTrue(model.validate(messages));
151    assertTrue(messages.contains(TaskModel.ERROR_FILTER_NOT_SET));
152  }
153
154  public void testErrorFileSameAsResultFile() throws Exception {
155    List<String> messages = new ArrayList<String>();
156
157    model.addClasspath(new Path(new Project()));
158    model.setErrorFile(null);
159    model.setResultFile(File.createTempFile("anyfile", ".temp").toString());
160    assertTrue(model.validate(messages));
161    assertEquals(model.getResultFile(), model.getErrorFile());
162  }
163
164  public void testFileSetNotSet() throws Exception {
165    List<String> messages = new ArrayList<String>();
166
167    assertFalse(model.validate(messages));
168    assertTrue(messages.contains(TaskModel.ERROR_FILESET_NOT_SET));
169  }
170}
171