/* * Copyright (c) 2010, Stanislav Muhametsin. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ package org.qi4j.runtime.composite; import org.junit.Test; import org.qi4j.api.composite.TransientComposite; import org.qi4j.api.mixin.Mixins; import org.qi4j.bootstrap.AssemblyException; import org.qi4j.bootstrap.ModuleAssembly; import org.qi4j.test.AbstractQi4jTest; /** * * @author Stanislav Muhametsin */ public class UndeclaredThrowableTest extends AbstractQi4jTest { public static class TestException extends RuntimeException { public TestException() { super("Test"); } } @Mixins({ TestTransient.TestTransientMixin.class }) public static interface TestTransient extends TransientComposite { public void declaredMethodThatThrowsException(); public void invokeDeclaredPublicMethodThatThrowsException(); public void invokePrivateMethodThatThrowsException(); public void invokeProtectedMethodThatThrowsException(); public void invokeUndeclaredPublicMethodThatThrowsException(); public abstract class TestTransientMixin implements TestTransient { @Override public void declaredMethodThatThrowsException() { throw new TestException(); } @Override public void invokeDeclaredPublicMethodThatThrowsException() { this.declaredMethodThatThrowsException(); } @Override public void invokePrivateMethodThatThrowsException() { this.privateThrowException(); } @Override public void invokeProtectedMethodThatThrowsException() { this.protectedThrowException(); } @Override public void invokeUndeclaredPublicMethodThatThrowsException() { this.publicThrowException(); } private void privateThrowException() { throw new TestException(); } protected void protectedThrowException() { throw new TestException(); } public void publicThrowException() { throw new TestException(); } } } @Override public void assemble( ModuleAssembly module ) throws AssemblyException { module.addTransients( TestTransient.class ); } @Test(expected = TestException.class) public void invokeExceptionThrowingMethod() { this.transientBuilderFactory.newTransient( TestTransient.class ).declaredMethodThatThrowsException(); } @Test(expected = TestException.class) public void invokeDeclaredPublicMethodWhichInvokesExceptionThrowingMethod() { this.transientBuilderFactory.newTransient( TestTransient.class ).invokeDeclaredPublicMethodThatThrowsException(); } @Test(expected = TestException.class) public void invokeUndeclaredPublicMethodWhichInvokesExceptionThrowingMethod() { this.transientBuilderFactory.newTransient( TestTransient.class ).invokeUndeclaredPublicMethodThatThrowsException(); } @Test(expected = TestException.class) public void invokePrivateMethodWhichInvokesExceptionThrowingMethod() { this.transientBuilderFactory.newTransient( TestTransient.class ).invokePrivateMethodThatThrowsException(); } @Test(expected = TestException.class) public void invokeProtectedMethodWhichInvokesExceptionThrowingMethod() { this.transientBuilderFactory.newTransient( TestTransient.class ).invokeProtectedMethodThatThrowsException(); } }