Coverage Report - com.jeantessier.dependencyfinder.ant.TestListDiff
 
Classes in this File Line Coverage Branch Coverage Complexity
TestListDiff
85%
80/94
N/A
1.538
 
 1  
 /*
 2  
  *  Copyright (c) 2001-2009, Jean Tessier
 3  
  *  All rights reserved.
 4  
  *
 5  
  *  Redistribution and use in source and binary forms, with or without
 6  
  *  modification, are permitted provided that the following conditions
 7  
  *  are met:
 8  
  *
 9  
  *      * Redistributions of source code must retain the above copyright
 10  
  *        notice, this list of conditions and the following disclaimer.
 11  
  *
 12  
  *      * Redistributions in binary form must reproduce the above copyright
 13  
  *        notice, this list of conditions and the following disclaimer in the
 14  
  *        documentation and/or other materials provided with the distribution.
 15  
  *
 16  
  *      * Neither the name of Jean Tessier nor the names of his contributors
 17  
  *        may be used to endorse or promote products derived from this software
 18  
  *        without specific prior written permission.
 19  
  *
 20  
  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 21  
  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 22  
  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 23  
  *  A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR
 24  
  *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 25  
  *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 26  
  *  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 27  
  *  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 28  
  *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 29  
  *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 30  
  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 31  
  */
 32  
 
 33  
 package com.jeantessier.dependencyfinder.ant;
 34  
 
 35  
 import java.io.*;
 36  
 
 37  
 import junit.framework.*;
 38  
 
 39  
 import org.apache.tools.ant.*;
 40  
 
 41  12
 public class TestListDiff extends TestCase {
 42  
     private File existingOldFile;
 43  
     private File existingNewFile;
 44  
     private File existingDir;
 45  
     private File nonExistingFile;
 46  
 
 47  
     private ListDiff sut;
 48  
 
 49  
     protected void setUp() throws Exception {
 50  12
         super.setUp();
 51  
 
 52  12
         existingOldFile = File.createTempFile(getName(), "old");
 53  12
         existingOldFile.deleteOnExit();
 54  12
         existingNewFile = File.createTempFile(getName(), "new");
 55  12
         existingNewFile.deleteOnExit();
 56  12
         existingDir = existingOldFile.getParentFile();
 57  12
         nonExistingFile = new File("DoesNotExist");
 58  
 
 59  12
         sut = new ListDiff();
 60  12
     }
 61  
 
 62  
     public void testAllMandatoryParameters() throws Exception {
 63  1
         sut.setOld(existingOldFile);
 64  1
         sut.setNew(existingNewFile);
 65  1
         sut.setDestfile(nonExistingFile);
 66  
 
 67  1
         sut.validateParameters();
 68  1
     }
 69  
 
 70  
     public void testOldNotSet() {
 71  
         try {
 72  1
             sut.validateParameters();
 73  0
             fail("executed without old being set");
 74  1
         } catch (BuildException ex) {
 75  1
             assertEquals("Wrong message", "old must be set!", ex.getMessage());
 76  0
         }
 77  1
     }
 78  
 
 79  
     public void testOldDoesNotExist() {
 80  1
         sut.setOld(nonExistingFile);
 81  
 
 82  
         try {
 83  1
             sut.validateParameters();
 84  0
             fail("executed without old being set");
 85  1
         } catch (BuildException ex) {
 86  1
             assertEquals("Wrong message", "old does not exist!", ex.getMessage());
 87  0
         }
 88  1
     }
 89  
 
 90  
     public void testOldNotAFile() {
 91  1
         sut.setOld(existingDir);
 92  
 
 93  
         try {
 94  1
             sut.validateParameters();
 95  0
             fail("executed without old being set");
 96  1
         } catch (BuildException ex) {
 97  1
             assertEquals("Wrong message", "old is not a file!", ex.getMessage());
 98  0
         }
 99  1
     }
 100  
 
 101  
     public void testOldLabel() {
 102  1
         sut.setOld(existingOldFile);
 103  1
         sut.setNew(existingNewFile);
 104  1
         sut.setDestfile(nonExistingFile);
 105  
 
 106  1
         String expectedOldLabel = "old label";
 107  1
         sut.setOldlabel(expectedOldLabel);
 108  
 
 109  1
         sut.validateParameters();
 110  1
         assertEquals(expectedOldLabel, sut.getOldlabel());
 111  1
     }
 112  
 
 113  
     public void testOldLabelNotSet() {
 114  1
         sut.setOld(existingOldFile);
 115  1
         sut.setNew(existingNewFile);
 116  1
         sut.setDestfile(nonExistingFile);
 117  
 
 118  1
         sut.validateParameters();
 119  1
         assertEquals("default old label", sut.getOld().getPath(), sut.getOldlabel());
 120  1
     }
 121  
 
 122  
     public void testNewNotSet() {
 123  1
         sut.setOld(existingOldFile);
 124  
 
 125  
         try {
 126  1
             sut.validateParameters();
 127  0
             fail("executed without old being set");
 128  1
         } catch (BuildException ex) {
 129  1
             assertEquals("Wrong message", "new must be set!", ex.getMessage());
 130  0
         }
 131  1
     }
 132  
 
 133  
     public void testNewDoesNotExist() {
 134  1
         sut.setOld(existingOldFile);
 135  1
         sut.setNew(nonExistingFile);
 136  
 
 137  
         try {
 138  1
             sut.validateParameters();
 139  0
             fail("executed without old being set");
 140  1
         } catch (BuildException ex) {
 141  1
             assertEquals("Wrong message", "new does not exist!", ex.getMessage());
 142  0
         }
 143  1
     }
 144  
 
 145  
     public void testNewNotAFile() {
 146  1
         sut.setOld(existingOldFile);
 147  1
         sut.setNew(existingDir);
 148  
 
 149  
         try {
 150  1
             sut.validateParameters();
 151  0
             fail("executed without old being set");
 152  1
         } catch (BuildException ex) {
 153  1
             assertEquals("Wrong message", "new is not a file!", ex.getMessage());
 154  0
         }
 155  1
     }
 156  
 
 157  
     public void testNewLabel() {
 158  1
         sut.setOld(existingOldFile);
 159  1
         sut.setNew(existingNewFile);
 160  1
         sut.setDestfile(nonExistingFile);
 161  
 
 162  1
         String expectedNewLabel = "new label";
 163  1
         sut.setNewlabel(expectedNewLabel);
 164  
 
 165  1
         sut.validateParameters();
 166  1
         assertEquals(expectedNewLabel, sut.getNewlabel());
 167  1
     }
 168  
 
 169  
     public void testNewLabelNotSet() {
 170  1
         sut.setOld(existingOldFile);
 171  1
         sut.setNew(existingNewFile);
 172  1
         sut.setDestfile(nonExistingFile);
 173  
 
 174  1
         sut.validateParameters();
 175  1
         assertEquals("default new label", sut.getNew().getPath(), sut.getNewlabel());
 176  1
     }
 177  
 
 178  
     public void testMissingDestfile() {
 179  1
         sut.setOld(existingOldFile);
 180  1
         sut.setNew(existingNewFile);
 181  
 
 182  
         try {
 183  1
             sut.validateParameters();
 184  0
             fail("executed without destfile being set");
 185  1
         } catch (BuildException ex) {
 186  1
             assertEquals("Wrong message", "destfile must be set!", ex.getMessage());
 187  0
         }
 188  1
     }
 189  
 }