Skip to content

Instantly share code, notes, and snippets.

View stephan-mueller's full-sized avatar

stephan-mueller

  • adesso SE
  • Paderborn / Metropole Ruhr, Germany
View GitHub Profile
@stephan-mueller
stephan-mueller / AlternativeMailServiceIT.java
Created September 28, 2015 16:48
Arquillian test for the cdi service alternative {@link AlternativeMailService}.
@RunWith(Arquillian.class)
public class AlternativeMailServiceIT {
private static final Logger LOG = LoggerFactory.getLogger(AlternativeMailServiceIT.class);
@Deployment
public static Archive createDeployment() {
PomEquippedResolveStage pomFile = Maven.resolver().loadPomFromFile("pom.xml");
WebArchive archive = ShrinkWrap.create(WebArchive.class)
@stephan-mueller
stephan-mueller / AlternativeMailService.java
Created September 28, 2015 16:47
Alternative implementation for the service {@link MailService}
@Alternative
public class AlternativeMailService extends MailService {
public static CountDownLatch latch;
@Override
public void sendMail(final String subject, final String body, final String... recipients) {
latch.countDown();
}
}
@stephan-mueller
stephan-mueller / MailServiceIT.java
Created September 28, 2015 16:45
Arquillian test for the cdi service {@link MailService}.
@RunWith(Arquillian.class)
public class MailServiceIT {
private static final Logger LOG = LoggerFactory.getLogger(MailServiceIT.class);
@Deployment
public static Archive createDeployment() {
WebArchive archive = ShrinkWrap.create(WebArchive.class)
.addClass(MailService.class);
@stephan-mueller
stephan-mueller / MailService.java
Created September 28, 2015 16:44
Cdi managed service
@ApplicationScoped
public class MailService {
private static final Logger LOG = LoggerFactory.getLogger(MailService.class);
public void sendMail(String subject, String body, String... recipients) {
LOG.info("sendMail: \n" + "subject: \n" + subject + "body: \n" + body);
}
}
@stephan-mueller
stephan-mueller / arquillian.xml
Created September 28, 2015 16:40
arquillian configuration file
<?xml version="1.0" encoding="UTF-8"?>
<arquillian xmlns="http://jboss.org/schema/arquillian"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
<container qualifier="chameleon" default="true">
<configuration>
<property name="chameleonTarget">wildfly:9.0.0.Final:managed</property>
<property name="serverConfig">standalone-full.xml</property>
<property name="javaVmArguments">-Xmx512m -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n</property>
@stephan-mueller
stephan-mueller / pom.xml
Last active September 28, 2015 16:50
arquillian-showcase maven pom
<?xml version="1.0" encoding="UTF-8"?>
<project ...>
<properties>
...
<version.junit>4.12</version.junit>
<version.assertj>3.1.0</version.assertj>
<version.arquillian>1.1.8.Final</version.arquillian>
@stephan-mueller
stephan-mueller / ExceptionHandlingTest.java
Created September 28, 2015 16:24
JUnit test to demonstrate the handling of exceptions.
public class ExceptionHandlingTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test(expected = IndexOutOfBoundsException.class)
public void shouldFailForInvalidIndex() throws Exception {
new ArrayList<>().get(0);
}
@stephan-mueller
stephan-mueller / FixMethodOrderJVMTest.java
Created September 28, 2015 16:23
JUnit test to demonstrate the method execution order defined by the JVM.
@FixMethodOrder(JVM)
public class FixMethodOrderJVMTest {
private static final Logger LOG = LoggerFactory.getLogger(FixMethodOrderJVMTest.class);
@Rule
public TestName name = new TestName();
@Test
public void methodB() throws Exception {
@stephan-mueller
stephan-mueller / FixMethodOrderNameAscendingTest.java
Created September 28, 2015 16:23
JUnit test to demonstrate the method execution order defined by the name.
@FixMethodOrder(NAME_ASCENDING)
public class FixMethodOrderNameAscendingTest {
private static final Logger LOG = LoggerFactory.getLogger(FixMethodOrderNameAscendingTest.class);
@Rule
public TestName name = new TestName();
@Test
public void methodB() throws Exception {
@stephan-mueller
stephan-mueller / MethodOrderInheritanceTest.java
Created September 28, 2015 16:22
JUnit test to demonstrate the method execution order with inheritance.
public class MethodOrderInheritanceTest extends MethodOrderTest {
private static final Logger LOG = LoggerFactory.getLogger(MethodOrderInheritanceTest.class);
@Test
public void methodAChild() throws Exception {
LOG.info("@Test methodAChild()");
}
@Test