Clover coverage report - Dependency Finder
Coverage timestamp: Mon Nov 29 2010 15:00:50 PST
file stats: LOC: 187   Methods: 23
NCLOC: 123   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
TestHex.java - 95% 100% 96.4%
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.text;
 34   
 35    import java.io.*;
 36   
 37    import junit.framework.*;
 38   
 39    public class TestHex extends TestCase {
 40    private StringWriter sw;
 41    private PrintWriter pw;
 42   
 43    private ByteArrayOutputStream baos;
 44    private PrintStream ps;
 45   
 46  21 protected void setUp() throws Exception {
 47  21 super.setUp();
 48   
 49  21 sw = new StringWriter();
 50  21 pw = new PrintWriter(sw);
 51   
 52  21 baos = new ByteArrayOutputStream();
 53  21 ps = new PrintStream(baos);
 54    }
 55   
 56  21 protected void tearDown() throws Exception {
 57  21 try {
 58  21 pw.close();
 59  21 ps.close();
 60    } finally {
 61  21 super.tearDown();
 62    }
 63    }
 64   
 65  1 public void testPrintNullToWriter() {
 66  1 try {
 67  1 Hex.print(pw, null);
 68  0 fail("Printed null byte array");
 69    } catch (NullPointerException ex) {
 70    // Expected
 71    }
 72    }
 73   
 74  1 public void testPrintNullToStream() {
 75  1 try {
 76  1 Hex.print(ps, null);
 77  0 fail("Printed null byte array");
 78    } catch (NullPointerException ex) {
 79    // Expected
 80    }
 81    }
 82   
 83  1 public void testPrintEmptyToWriter() {
 84  1 Hex.print(pw, new byte[0]);
 85  1 pw.close();
 86  1 assertEquals("", sw.toString());
 87    }
 88   
 89  1 public void testPrintEmptyToStream() {
 90  1 Hex.print(ps, new byte[0]);
 91  1 pw.close();
 92  1 assertEquals("", baos.toString());
 93    }
 94   
 95  1 public void testPrintOneByteToWriter() {
 96  1 Hex.print(pw, new byte[] {0});
 97  1 pw.close();
 98  1 assertEquals("00", sw.toString());
 99    }
 100   
 101  1 public void testPrintOneByteToStream() {
 102  1 Hex.print(ps, new byte[] {0});
 103  1 pw.close();
 104  1 assertEquals("00", baos.toString());
 105    }
 106   
 107  1 public void testPrintFourBitsToWriter() {
 108  1 Hex.print(pw, new byte[] {7});
 109  1 pw.close();
 110  1 assertEquals("07", sw.toString());
 111    }
 112   
 113  1 public void testPrintFourBitsToStream() {
 114  1 Hex.print(ps, new byte[] {7});
 115  1 pw.close();
 116  1 assertEquals("07", baos.toString());
 117    }
 118   
 119  1 public void testPrintGeneratesCapitalsToWriter() {
 120  1 Hex.print(pw, new byte[] {10});
 121  1 pw.close();
 122  1 assertEquals("0A", sw.toString());
 123    }
 124   
 125  1 public void testPrintGeneratesCapitalsToStream() {
 126  1 Hex.print(ps, new byte[] {10});
 127  1 pw.close();
 128  1 assertEquals("0A", baos.toString());
 129    }
 130   
 131  1 public void testPrintEightBitsToWriter() {
 132  1 Hex.print(pw, new byte[] {(byte) 255});
 133  1 pw.close();
 134  1 assertEquals("FF", sw.toString());
 135    }
 136   
 137  1 public void testPrintEightBitsToStream() {
 138  1 Hex.print(ps, new byte[] {(byte) 255});
 139  1 pw.close();
 140  1 assertEquals("FF", baos.toString());
 141    }
 142   
 143  1 public void testPrintTwoBytesToWriter() {
 144  1 Hex.print(pw, new byte[] {0, 1});
 145  1 pw.close();
 146  1 assertEquals("0001", sw.toString());
 147    }
 148   
 149  1 public void testPrintTwoBytesToStream() {
 150  1 Hex.print(ps, new byte[] {0, 1});
 151  1 pw.close();
 152  1 assertEquals("0001", baos.toString());
 153    }
 154   
 155  1 public void testNullToString() {
 156  1 try {
 157  1 Hex.toString(null);
 158  0 fail("Printed null byte array");
 159    } catch (NullPointerException ex) {
 160    // Expected
 161    }
 162    }
 163   
 164  1 public void testEmptyToString() {
 165  1 assertEquals("", Hex.toString(new byte[0]));
 166    }
 167   
 168  1 public void testOneByteToString() {
 169  1 assertEquals("00", Hex.toString(new byte[] {0}));
 170    }
 171   
 172  1 public void testFourBitsToString() {
 173  1 assertEquals("07", Hex.toString(new byte[] {7}));
 174    }
 175   
 176  1 public void testToStringGeneratesCapitals() {
 177  1 assertEquals("0A", Hex.toString(new byte[] {10}));
 178    }
 179   
 180  1 public void testEightBitsToString() {
 181  1 assertEquals("FF", Hex.toString(new byte[] {(byte) 255}));
 182    }
 183   
 184  1 public void testTwoBytesToString() {
 185  1 assertEquals("0001", Hex.toString(new byte[] {0, 1}));
 186    }
 187    }