Skip to content

Commit

Permalink
Testcase for WELD-1223
Browse files Browse the repository at this point in the history
  • Loading branch information
jharting committed Oct 11, 2012
1 parent 49ca8da commit fec324a
Show file tree
Hide file tree
Showing 6 changed files with 310 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2012, Red Hat, Inc., and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* 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.jboss.weld.tests.decorators.exception;

public class CheckedException extends Exception {

private static final long serialVersionUID = 2272688680157036226L;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2012, Red Hat, Inc., and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* 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.jboss.weld.tests.decorators.exception;

public class CustomRuntimeException extends RuntimeException {

private static final long serialVersionUID = 3598778994005468661L;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2012, Red Hat, Inc., and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* 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.jboss.weld.tests.decorators.exception;

import javax.inject.Inject;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.BeanArchive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(Arquillian.class)
public class ExceptionThrownByDecoratedBeanTest {

@Inject
private Foo foo;

@Deployment
public static Archive<?> getDeployment() {
return ShrinkWrap.create(BeanArchive.class).decorate(FooDecorator.class)
.addPackage(ExceptionThrownByDecoratedBeanTest.class.getPackage());
}

@Test
public void testCheckedExceptionPropagatedThroughDecoratorCall() {
try {
foo.throwCheckedException1();
Assert.fail();
} catch (CheckedException expected) {
}
}

@Test
public void testCheckedExceptionThrownByDecorator() {
try {
foo.throwCheckedException2();
Assert.fail();
} catch (CheckedException expected) {
}
}

@Test
public void testCheckedExceptionPropagated() {
try {
foo.throwCheckedException3();
Assert.fail();
} catch (CheckedException expected) {
}
}

@Test
public void testCheckedExceptionPropagatedThroughAbstractDecoratorMethod() {
try {
foo.throwCheckedException4();
Assert.fail();
} catch (CheckedException expected) {
}
}

@Test
public void testRuntimeExceptionPropagatedThroughDecoratorCall() {
try {
foo.throwRuntimeException1();
Assert.fail();
} catch (CustomRuntimeException expected) {
}
}

@Test
public void testRuntimeExceptionThrownByDecorator() {
try {
foo.throwRuntimeException2();
Assert.fail();
} catch (CustomRuntimeException expected) {
}
}

@Test
public void testRuntimeExceptionPropagated() {
try {
foo.throwRuntimeException3();
Assert.fail();
} catch (CustomRuntimeException expected) {
}
}

@Test
public void testRuntimeExceptionPropagatedThroughAbstractDecoratorMethod() {
try {
foo.throwRuntimeException4();
Assert.fail();
} catch (CustomRuntimeException expected) {
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2012, Red Hat, Inc., and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* 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.jboss.weld.tests.decorators.exception;

public interface Foo {

void throwCheckedException1() throws CheckedException;

void throwCheckedException2() throws CheckedException;

void throwCheckedException3() throws CheckedException;

void throwCheckedException4() throws CheckedException;

void throwRuntimeException1();

void throwRuntimeException2();

void throwRuntimeException3();

void throwRuntimeException4();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2012, Red Hat, Inc., and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* 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.jboss.weld.tests.decorators.exception;

import javax.decorator.Decorator;
import javax.decorator.Delegate;
import javax.inject.Inject;

@Decorator
public abstract class FooDecorator implements Foo {

@Inject
@Delegate
private Foo delegate;

@Override
public void throwCheckedException1() throws CheckedException {
delegate.throwCheckedException1();
}

@Override
public void throwCheckedException2() throws CheckedException {
throw new CheckedException();
}

@Override
public void throwRuntimeException1() {
delegate.throwRuntimeException1();
}

@Override
public void throwRuntimeException2() {
throw new CustomRuntimeException();
}

@Override
public abstract void throwCheckedException4() throws CheckedException;

@Override
public abstract void throwRuntimeException4();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2012, Red Hat, Inc., and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* 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.jboss.weld.tests.decorators.exception;

public class FooImpl implements Foo {

@Override
public void throwCheckedException1() throws CheckedException {
throw new CheckedException();
}

@Override
public void throwCheckedException2() throws CheckedException {
throw new CheckedException();
}

@Override
public void throwCheckedException3() throws CheckedException {
throw new CheckedException();
}

@Override
public void throwCheckedException4() throws CheckedException {
throw new CheckedException();
}

@Override
public void throwRuntimeException1() {
throw new CustomRuntimeException();
}

@Override
public void throwRuntimeException2() {
throw new CustomRuntimeException();
}

@Override
public void throwRuntimeException3() {
throw new CustomRuntimeException();
}

@Override
public void throwRuntimeException4() {
throw new CustomRuntimeException();
}
}

0 comments on commit fec324a

Please sign in to comment.