Debian Codegraph @

src/test/java/org/jboss/modules/ErrorHandlingTest.java

raw
1 /*
2 * JBoss, Home of Professional Open Source.
3 * Copyright 2014 Red Hat, Inc., and individual contributors
4 * as indicated by the @author tags.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19 package org.jboss.modules;
20
21 import org.jboss.modules.test.ClassA;
22 import org.jboss.modules.util.TestModuleLoader;
23 import org.jboss.modules.util.TestResourceLoader;
24 import org.junit.Before;
25 import org.junit.Test;
26
27 import static org.junit.Assert.fail;
28
29 /**
30 * @author <a href="mailto:[email protected]">Carlo de Wolf</a>
31 */
32 public class ErrorHandlingTest extends AbstractModuleTestCase {
33 private static final String MODULE_A = "test-module-a";
34
35 private TestModuleLoader moduleLoader;
36
37 @Before
38 public void before() throws Exception {
39 moduleLoader = new TestModuleLoader();
40
41 final ModuleSpec.Builder moduleABuilder = ModuleSpec.build(MODULE_A);
42 moduleABuilder.addResourceRoot(ResourceLoaderSpec.createResourceLoaderSpec(
43 TestResourceLoader.build()
44 .addClass(ClassA.class)
45 .create())
46 );
47 moduleABuilder.addDependency(DependencySpec.OWN_DEPENDENCY);
48 moduleLoader.addModuleSpec(moduleABuilder.create());
49 }
50
51 @Test
52 public void testNonLinkingClass() throws ModuleLoadException, ClassNotFoundException {
53 final Module module = moduleLoader.loadModule(MODULE_A);
54 final ClassLoader classLoader = module.getClassLoader();
55 try {
56 classLoader.loadClass(ClassA.class.getName());
57 fail("Should have thrown a LinkageError");
58 } catch(LinkageError e) {
59 // good
60 }
61 }
62 }