Clover coverage report - Dependency Finder
Coverage timestamp: Mon Nov 29 2010 15:00:50 PST
file stats: LOC: 111   Methods: 6
NCLOC: 59   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
TestDeprecationPrinter.java 0% 100% 100% 95.5%
coverage coverage
 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.classreader;
 34   
 35    import java.io.*;
 36   
 37    import junit.framework.*;
 38    import java.util.*;
 39   
 40    public class TestDeprecationPrinter extends TestCase {
 41    private static final String NEW_CLASSPATH = "tests" + File.separator + "JarJarDiff" + File.separator + "new";
 42   
 43    private ClassfileLoader loader;
 44    private StringWriter writer;
 45    private DeprecationPrinter printer;
 46   
 47  4 protected void setUp() throws Exception {
 48  4 loader = new AggregatingClassfileLoader();
 49  4 loader.load(NEW_CLASSPATH);
 50   
 51  4 writer = new StringWriter();
 52  4 printer = new DeprecationPrinter(new PrintWriter(writer));
 53    }
 54   
 55  1 public void testOneNonDeprecatedClass() {
 56  1 loader.getClassfile("NewPackage.NewClass").accept(printer);
 57   
 58  1 assertEquals("No deprecation", "", writer.toString());
 59    }
 60   
 61  1 public void testOneDeprecatedClass() throws IOException {
 62  1 loader.getClassfile("ModifiedPackage.DeprecatedInterface").accept(printer);
 63   
 64  1 Collection entries = parse(writer.toString());
 65   
 66  1 assertTrue("Deprecated class", entries.contains("ModifiedPackage.DeprecatedInterface"));
 67  1 assertEquals("Deprecated class", 1, entries.size());
 68    }
 69   
 70  1 public void testDeprecatedMethods() throws IOException {
 71  1 loader.getClassfile("ModifiedPackage.ModifiedClass").accept(printer);
 72   
 73  1 Collection entries = parse(writer.toString());
 74   
 75  1 assertTrue("Deprecated field", entries.contains("ModifiedPackage.ModifiedClass.deprecatedField"));
 76  1 assertTrue("Deprecated constructor", entries.contains("ModifiedPackage.ModifiedClass.ModifiedClass(int)"));
 77  1 assertTrue("Deprecated method", entries.contains("ModifiedPackage.ModifiedClass.deprecatedMethod()"));
 78  1 assertEquals("Modified class", 3, entries.size());
 79    }
 80   
 81  1 public void testListenerBehavior() throws IOException {
 82  1 loader = new TransientClassfileLoader();
 83  1 loader.addLoadListener(new LoadListenerVisitorAdapter(printer));
 84  1 loader.load(NEW_CLASSPATH);
 85   
 86  1 Collection entries = parse(writer.toString());
 87   
 88  1 assertTrue("Deprecated class", entries.contains("ModifiedPackage.DeprecatedClass"));
 89  1 assertTrue("Deprecated interface", entries.contains("ModifiedPackage.DeprecatedInterface"));
 90  1 assertTrue("Deprecated field", entries.contains("ModifiedPackage.ModifiedClass.deprecatedField"));
 91  1 assertTrue("Deprecated field", entries.contains("ModifiedPackage.ModifiedInterface.deprecatedField"));
 92  1 assertTrue("Deprecated constructor", entries.contains("ModifiedPackage.DeprecatedClass.DeprecatedClass()"));
 93  1 assertTrue("Deprecated constructor", entries.contains("ModifiedPackage.ModifiedClass.ModifiedClass(int)"));
 94  1 assertTrue("Deprecated method", entries.contains("ModifiedPackage.ModifiedClass.deprecatedMethod()"));
 95  1 assertTrue("Deprecated method", entries.contains("ModifiedPackage.ModifiedInterface.deprecatedMethod()"));
 96  1 assertEquals("Classpath " + entries, 8, entries.size());
 97    }
 98   
 99  3 private Collection parse(String text) throws IOException {
 100  3 Collection result = new HashSet();
 101   
 102  3 BufferedReader in = new BufferedReader(new StringReader(text));
 103  3 String line;
 104  ? while ((line = in.readLine()) != null) {
 105  12 result.add(line);
 106    }
 107  3 in.close();
 108   
 109  3 return result;
 110    }
 111    }