Clover coverage report - Dependency Finder
Coverage timestamp: Mon Nov 29 2010 15:00:50 PST
file stats: LOC: 130   Methods: 8
NCLOC: 78   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
TestMultipleValuesSwitch.java - 95.3% 100% 96.1%
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.commandline;
 34   
 35    import java.util.*;
 36   
 37    import junit.framework.*;
 38   
 39    public class TestMultipleValuesSwitch extends TestCase {
 40    private static final String DEFAULT_VALUE1 = "default value 1";
 41    private static final String DEFAULT_VALUE2 = "default value 2";
 42    private static final List<String> DEFAULT_VALUE = new ArrayList<String>();
 43   
 44    private static final String EXPECTED_VALUE1 = "expected value 1";
 45    private static final String EXPECTED_VALUE2 = "expected value 2";
 46    private static final List<String> EXPECTED_VALUE = new ArrayList<String>();
 47   
 48    private static final List<String> NULL_VALUE = new ArrayList<String>();
 49   
 50    static {
 51  1 DEFAULT_VALUE.add(DEFAULT_VALUE1);
 52  1 DEFAULT_VALUE.add(DEFAULT_VALUE2);
 53   
 54  1 EXPECTED_VALUE.add(EXPECTED_VALUE1);
 55  1 EXPECTED_VALUE.add(EXPECTED_VALUE2);
 56   
 57  1 NULL_VALUE.add(null);
 58    }
 59   
 60    private MultipleValuesSwitch commandLineSwitch;
 61   
 62  7 protected void setUp() throws Exception {
 63  7 super.setUp();
 64   
 65  7 commandLineSwitch = new MultipleValuesSwitch("switch", DEFAULT_VALUE);
 66    }
 67   
 68  1 public void testSetToNull() {
 69  1 assertFalse(commandLineSwitch.isPresent());
 70  1 assertEquals(DEFAULT_VALUE, commandLineSwitch.getValue());
 71  1 commandLineSwitch.setValue(null);
 72  1 assertTrue(commandLineSwitch.isPresent());
 73  1 assertEquals(NULL_VALUE, commandLineSwitch.getValue());
 74    }
 75   
 76  1 public void testSetToObject() {
 77  1 assertFalse(commandLineSwitch.isPresent());
 78  1 assertEquals(DEFAULT_VALUE, commandLineSwitch.getValue());
 79  1 commandLineSwitch.setValue(EXPECTED_VALUE1);
 80  1 commandLineSwitch.setValue(EXPECTED_VALUE2);
 81  1 assertTrue(commandLineSwitch.isPresent());
 82  1 assertEquals(EXPECTED_VALUE, commandLineSwitch.getValue());
 83    }
 84   
 85  1 public void testParseNull() throws CommandLineException {
 86  1 try {
 87  1 commandLineSwitch.parse(null);
 88  0 fail("Parsed without a value");
 89    } catch (CommandLineException e) {
 90    // Expected
 91    }
 92    }
 93   
 94  1 public void testParseEmptyString() throws CommandLineException {
 95  1 assertFalse(commandLineSwitch.isPresent());
 96  1 assertEquals(DEFAULT_VALUE, commandLineSwitch.getValue());
 97  1 commandLineSwitch.parse("");
 98  1 assertTrue(commandLineSwitch.isPresent());
 99  1 assertEquals(Collections.singletonList(""), commandLineSwitch.getValue());
 100    }
 101   
 102  1 public void testParseString() throws CommandLineException {
 103  1 assertFalse(commandLineSwitch.isPresent());
 104  1 assertEquals(DEFAULT_VALUE, commandLineSwitch.getValue());
 105  1 commandLineSwitch.parse(EXPECTED_VALUE1);
 106  1 commandLineSwitch.parse(EXPECTED_VALUE2);
 107  1 assertTrue(commandLineSwitch.isPresent());
 108  1 assertEquals(EXPECTED_VALUE, commandLineSwitch.getValue());
 109    }
 110   
 111  1 public void testValidateWhenNotMandatory() throws CommandLineException {
 112  1 commandLineSwitch.validate();
 113  1 commandLineSwitch.parse(EXPECTED_VALUE1);
 114  1 commandLineSwitch.parse(EXPECTED_VALUE2);
 115  1 commandLineSwitch.validate();
 116    }
 117   
 118  1 public void testValidateWhenMandatory() throws CommandLineException {
 119  1 commandLineSwitch = new MultipleValuesSwitch("switch", "default", true);
 120  1 try {
 121  1 commandLineSwitch.validate();
 122  0 fail("Missing mandatory switch should not validate.");
 123    } catch (CommandLineException e) {
 124    // Expected
 125    }
 126  1 commandLineSwitch.parse(EXPECTED_VALUE1);
 127  1 commandLineSwitch.parse(EXPECTED_VALUE2);
 128  1 commandLineSwitch.validate();
 129    }
 130    }