-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ArC: fix generating Bean.create() to wrap checked exceptions in Creat…
…ionException
- Loading branch information
Showing
3 changed files
with
126 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
...projects/arc/tests/src/test/java/io/quarkus/arc/test/bean/create/BeanCreateErrorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package io.quarkus.arc.test.bean.create; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
import java.math.BigDecimal; | ||
import java.math.BigInteger; | ||
|
||
import javax.enterprise.context.Dependent; | ||
import javax.enterprise.inject.CreationException; | ||
import javax.enterprise.inject.Produces; | ||
import javax.inject.Inject; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.quarkus.arc.test.ArcTestContainer; | ||
|
||
public class BeanCreateErrorTest { | ||
@RegisterExtension | ||
ArcTestContainer container = new ArcTestContainer(CheckedExceptionBean.class, CheckedExceptionProducerBean.class, | ||
UncheckedExceptionBean.class, UncheckedExceptionProducerBean.class); | ||
|
||
@Test | ||
public void checkedExceptionWrapped() { | ||
// Test that the checked exception is wrapped | ||
|
||
CreationException exception = assertThrows(CreationException.class, () -> { | ||
Arc.container().instance(CheckedExceptionBean.class); | ||
}); | ||
assertEquals("foo", exception.getCause().getMessage()); | ||
|
||
exception = assertThrows(CreationException.class, () -> { | ||
Arc.container().instance(BigInteger.class); | ||
}); | ||
assertEquals("bar", exception.getCause().getMessage()); | ||
} | ||
|
||
@Test | ||
public void uncheckedExceptionNotWrapped() { | ||
// Test that the unchecked exception is _not_ wrapped | ||
|
||
assertThrows(IllegalArgumentException.class, () -> { | ||
Arc.container().instance(UncheckedExceptionBean.class); | ||
}); | ||
|
||
assertThrows(IllegalStateException.class, () -> { | ||
Arc.container().instance(BigDecimal.class); | ||
}); | ||
} | ||
|
||
@Dependent | ||
static class CheckedExceptionBean { | ||
@Inject | ||
public CheckedExceptionBean() throws Exception { | ||
throw new Exception("foo"); | ||
} | ||
} | ||
|
||
@Dependent | ||
static class CheckedExceptionProducerBean { | ||
@Produces | ||
@Dependent | ||
BigInteger produce() throws Exception { | ||
throw new Exception("bar"); | ||
} | ||
} | ||
|
||
@Dependent | ||
static class UncheckedExceptionBean { | ||
@Inject | ||
public UncheckedExceptionBean() { | ||
throw new IllegalArgumentException(); | ||
} | ||
} | ||
|
||
@Dependent | ||
static class UncheckedExceptionProducerBean { | ||
@Produces | ||
@Dependent | ||
BigDecimal produce() { | ||
throw new IllegalStateException(); | ||
} | ||
} | ||
} |