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

COVERAGE SUMMARY FOR SOURCE FILE [TestClass_info.java]

nameclass, %method, %block, %line, %
TestClass_info.java100% (2/2)100% (11/11)100% (174/174)100% (38/38)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class TestClass_info100% (1/1)100% (10/10)100% (132/132)100% (33/33)
TestClass_info (): void 100% (1/1)100% (3/3)100% (1/1)
access$000 (TestClass_info): ConstantPool 100% (1/1)100% (3/3)100% (1/1)
expectClassNameLookup (int, String): void 100% (1/1)100% (17/17)100% (3/3)
setUp (): void 100% (1/1)100% (25/25)100% (5/5)
testGetName_defaultPackage (): void 100% (1/1)100% (14/14)100% (4/4)
testGetName_withPackageName (): void 100% (1/1)100% (14/14)100% (4/4)
testGetPackageName_defaultPackage (): void 100% (1/1)100% (14/14)100% (4/4)
testGetPackageName_withPackageName (): void 100% (1/1)100% (14/14)100% (4/4)
testGetSimpleName_defaultPackage (): void 100% (1/1)100% (14/14)100% (4/4)
testGetSimpleName_withPackageName (): void 100% (1/1)100% (14/14)100% (4/4)
     
class TestClass_info$1100% (1/1)100% (1/1)100% (42/42)100% (6/6)
TestClass_info$1 (TestClass_info, int, UTF8_info, String): void 100% (1/1)100% (42/42)100% (6/6)

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.classreader.impl;
34 
35import static org.hamcrest.Matchers.*;
36import org.jmock.*;
37import org.jmock.integration.junit4.*;
38import org.jmock.lib.legacy.*;
39import static org.junit.Assert.*;
40import org.junit.*;
41import org.junit.runner.*;
42 
43@RunWith(JMock.class)
44public class TestClass_info {
45    private static final int CLASS_NAME_INDEX = 1;
46    private static final String PACKAGE_NAME = "foo";
47    private static final String SIMPLE_CLASS_NAME = "Foo";
48    private static final String ENCODED_SIMPLE_CLASS_NAME = "L" + SIMPLE_CLASS_NAME + ";";
49    private static final String ENCODED_FULL_CLASS_NAME = "L" + PACKAGE_NAME + "/" + SIMPLE_CLASS_NAME + ";";
50    private static final String FULL_CLASS_NAME = PACKAGE_NAME + "." + SIMPLE_CLASS_NAME;
51 
52    private Mockery context;
53 
54    private ConstantPool constantPool;
55 
56    private Class_info sut;
57 
58    @Before
59    public void setUp() throws Exception {
60        context = new Mockery();
61        context.setImposteriser(ClassImposteriser.INSTANCE);
62 
63        constantPool = context.mock(ConstantPool.class);
64 
65        sut = new Class_info(constantPool, CLASS_NAME_INDEX);
66    }
67 
68    @Test
69    public void testGetName_defaultPackage() {
70        expectClassNameLookup(CLASS_NAME_INDEX, ENCODED_SIMPLE_CLASS_NAME);
71 
72        String actualValue = sut.getName();
73        assertThat("full name", actualValue, is(SIMPLE_CLASS_NAME));
74    }
75 
76    @Test
77    public void testGetName_withPackageName() {
78        expectClassNameLookup(CLASS_NAME_INDEX, ENCODED_FULL_CLASS_NAME);
79 
80        String actualValue = sut.getName();
81        assertThat("full name", actualValue, is(FULL_CLASS_NAME));
82    }
83 
84    @Test
85    public void testGetPackageName_defaultPackage() {
86        expectClassNameLookup(CLASS_NAME_INDEX, ENCODED_SIMPLE_CLASS_NAME);
87 
88        String actualValue = sut.getPackageName();
89        assertThat("package", actualValue, is(""));
90    }
91 
92    @Test
93    public void testGetPackageName_withPackageName() {
94        expectClassNameLookup(CLASS_NAME_INDEX, ENCODED_FULL_CLASS_NAME);
95 
96        String actualValue = sut.getPackageName();
97        assertThat("package", actualValue, is(PACKAGE_NAME));
98    }
99 
100    @Test
101    public void testGetSimpleName_defaultPackage() {
102        expectClassNameLookup(CLASS_NAME_INDEX, ENCODED_SIMPLE_CLASS_NAME);
103 
104        String actualValue = sut.getSimpleName();
105        assertThat("simple name", actualValue, is(SIMPLE_CLASS_NAME));
106    }
107 
108    @Test
109    public void testGetSimpleName_withPackageName() {
110        expectClassNameLookup(CLASS_NAME_INDEX, ENCODED_FULL_CLASS_NAME);
111 
112        String actualValue = sut.getSimpleName();
113        assertThat("simple name", actualValue, is(SIMPLE_CLASS_NAME));
114    }
115 
116    private void expectClassNameLookup(final int index, final String value) {
117        final UTF8_info utf8_info = context.mock(UTF8_info.class);
118 
119        context.checking(new Expectations() {{
120            one (constantPool).get(index);
121                will(returnValue(utf8_info));
122            one (utf8_info).getValue();
123                will(returnValue(value));
124        }});
125    }
126}

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