1/**
2 * Copyright (c) 2008, http://www.snakeyaml.org
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.yaml.snakeyaml.extensions.compactnotation;
17
18import junit.framework.TestCase;
19
20public class PackageCompactConstructorTest extends TestCase {
21
22    public void testGetClassForName() throws ClassNotFoundException {
23        assertEquals(Table.class, check("Table"));
24        assertEquals(Table.class, check("org.yaml.snakeyaml.extensions.compactnotation.Table"));
25        assertEquals(String.class, check("java.lang.String"));
26    }
27
28    public void testException1() throws ClassNotFoundException {
29        try {
30            check("foo.Bar");
31            fail();
32        } catch (ClassNotFoundException e) {
33            assertEquals("foo.Bar", e.getMessage());
34        }
35    }
36
37    public void testException2() throws ClassNotFoundException {
38        try {
39            check("FooBar");
40            fail();
41        } catch (ClassNotFoundException e) {
42            assertEquals("FooBar", e.getMessage());
43        }
44    }
45
46    private Class<?> check(String name) throws ClassNotFoundException {
47        return new PackageCompactConstructor("org.yaml.snakeyaml.extensions.compactnotation")
48                .getClassForName(name);
49    }
50}
51