EMMA Coverage Report (generated Mon Nov 29 14:43:38 PST 2010)
[all classes][com.jeantessier.commandline]

COVERAGE SUMMARY FOR SOURCE FILE [TestOptionalValueSwitch.java]

nameclass, %method, %block, %line, %
TestOptionalValueSwitch.java100% (1/1)100% (9/9)92%  (153/167)91%  (42/46)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class TestOptionalValueSwitch100% (1/1)100% (9/9)92%  (153/167)91%  (42/46)
testValidateWhenMandatory (): void 100% (1/1)42%  (10/24)50%  (4/8)
TestOptionalValueSwitch (): void 100% (1/1)100% (3/3)100% (1/1)
setUp (): void 100% (1/1)100% (10/10)100% (3/3)
testParseEmptyString (): void 100% (1/1)100% (24/24)100% (6/6)
testParseNull (): void 100% (1/1)100% (24/24)100% (6/6)
testParseString (): void 100% (1/1)100% (24/24)100% (6/6)
testSetToNull (): void 100% (1/1)100% (23/23)100% (6/6)
testSetToObject (): void 100% (1/1)100% (23/23)100% (6/6)
testValidateWhenNotMandatory (): void 100% (1/1)100% (12/12)100% (4/4)

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 
33package com.jeantessier.commandline;
34 
35import junit.framework.*;
36 
37public class TestOptionalValueSwitch extends TestCase {
38    private static final String DEFAULT_VALUE = "default value";
39 
40    private OptionalValueSwitch commandLineSwitch;
41    private static final String EXPECTED_VALUE = "expected value";
42 
43    protected void setUp() throws Exception {
44        super.setUp();
45 
46        commandLineSwitch = new OptionalValueSwitch("switch", DEFAULT_VALUE);
47    }
48 
49    public void testSetToNull() {
50        assertFalse(commandLineSwitch.isPresent());
51        assertEquals(DEFAULT_VALUE, commandLineSwitch.getValue());
52        commandLineSwitch.setValue(null);
53        assertTrue(commandLineSwitch.isPresent());
54        assertEquals(DEFAULT_VALUE, commandLineSwitch.getValue());
55    }
56 
57    public void testSetToObject() {
58        assertFalse(commandLineSwitch.isPresent());
59        assertEquals(DEFAULT_VALUE, commandLineSwitch.getValue());
60        commandLineSwitch.setValue(EXPECTED_VALUE);
61        assertTrue(commandLineSwitch.isPresent());
62        assertEquals(EXPECTED_VALUE, commandLineSwitch.getValue());
63    }
64 
65    public void testParseNull() throws CommandLineException {
66        assertFalse(commandLineSwitch.isPresent());
67        assertEquals(DEFAULT_VALUE, commandLineSwitch.getValue());
68        commandLineSwitch.parse(null);
69        assertTrue(commandLineSwitch.isPresent());
70        assertEquals(DEFAULT_VALUE, commandLineSwitch.getValue());
71    }
72 
73    public void testParseEmptyString() throws CommandLineException {
74        assertFalse(commandLineSwitch.isPresent());
75        assertEquals(DEFAULT_VALUE, commandLineSwitch.getValue());
76        commandLineSwitch.parse("");
77        assertTrue(commandLineSwitch.isPresent());
78        assertEquals("", commandLineSwitch.getValue());
79    }
80 
81    public void testParseString() throws CommandLineException {
82        assertFalse(commandLineSwitch.isPresent());
83        assertEquals(DEFAULT_VALUE, commandLineSwitch.getValue());
84        commandLineSwitch.parse(EXPECTED_VALUE);
85        assertTrue(commandLineSwitch.isPresent());
86        assertEquals(EXPECTED_VALUE, commandLineSwitch.getValue());
87    }
88 
89    public void testValidateWhenNotMandatory() throws CommandLineException {
90        commandLineSwitch.validate();
91        commandLineSwitch.parse(EXPECTED_VALUE);
92        commandLineSwitch.validate();
93    }
94 
95    public void testValidateWhenMandatory() throws CommandLineException {
96        commandLineSwitch = new OptionalValueSwitch("switch", "default", true);
97        try {
98            commandLineSwitch.validate();
99            fail("Missing mandatory switch should not validate.");
100        } catch (CommandLineException e) {
101            // Expected
102        }
103        commandLineSwitch.parse(EXPECTED_VALUE);
104        commandLineSwitch.validate();
105    }
106}

[all classes][com.jeantessier.commandline]
EMMA 2.0.5312 (C) Vladimir Roubtsov