View Javadoc

1   /*
2    * Copyright 2002,2004 The Apache Software Foundation.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of 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,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.apache.commons.jelly.tags.junit;
17  
18  import java.io.File;
19  
20  import org.apache.commons.jelly.JellyTagException;
21  import org.apache.commons.jelly.MissingAttributeException;
22  import org.apache.commons.jelly.XMLOutput;
23  import org.apache.commons.jelly.expression.Expression;
24  
25  /***
26   * Checks that a file cant be found.
27   *
28   * @author <a href="mailto:dion@apache.org">Dion Gillard</a>
29   * @version $Revision: 345902 $
30   */
31  public class AssertFileNotFoundTag extends AssertTagSupport
32  {
33      /*** the file to check */
34      private File file;
35  
36      /***
37       * Do the tag functionality: check the file can't be found.
38       * @param output a place to write text output
39       * @throws JellyTagException if the file exists.
40       */
41      public void doTag(XMLOutput output) throws JellyTagException
42      {
43          String message = getBodyText();
44          if (message == null || message.length() == 0)
45          {
46              message = "File exists.";
47          }
48  
49          
50          if (file == null)
51          {
52              throw new MissingAttributeException("file");
53          }
54          else
55          {
56              assertFalse(message, file.exists());
57          }
58      }
59      
60      /***
61       * The file to be tested. If this file exists, the test will pass.
62       * @param aFile the file to test.
63       */
64      public void setFile(File aFile)
65      {
66          file = aFile;
67      }
68  }