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 / persistence.xml
Last active July 21, 2016 15:33
persistence.xml with ExampleDS
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence">
<persistence-unit name="default" transaction-type="JTA">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
@stephan-mueller
stephan-mueller / JUnitAssertionTest.java
Last active October 26, 2015 15:04
JUnit test to demonstrate AssertJ assertions.
@Test
public void assertjAssertion() throws Exception {
String openKnowledge = "offen, kundig, gut!";
Assertions.assertThat(openKnowledge).startsWith("offen").contains("kundig").endsWith("gut!");
}
@stephan-mueller
stephan-mueller / JUnitAssertionTest.java
Last active October 26, 2015 16:14
JUnit test to demonstrate hamcrest assertions.
@Test
public void hamcrestAssertion() throws Exception {
String openKnowledge = "offen, kundig, gut!";
MatcherAssert.assertThat(openKnowledge, CoreMatchers.allOf(CoreMatchers.startsWith("offen"),
CoreMatchers.containsString("kundig"),
CoreMatchers.endsWith("gut!")));
}
@stephan-mueller
stephan-mueller / JUnitAssertionTest.java
Last active October 26, 2015 15:05
JUnit test to demonstrate junit assertions.
@Test
public void junitAssertion() throws Exception {
String openKnowledge = "offen, kundig, gut!";
Assert.assertTrue(openKnowledge.startsWith("offen"));
Assert.assertTrue(openKnowledge.contains("kundig"));
Assert.assertTrue(openKnowledge.endsWith("gut!"));
}
@stephan-mueller
stephan-mueller / TimeoutTest.java
Created September 29, 2015 14:56
JUnit test to demonstrate the usage of the timeout parameter and the timeout rule
public class TimeoutTest {
@Rule
public Timeout rule = new Timeout(7, TimeUnit.MILLISECONDS);
@Test(timeout = 5)
public void shouldFailWithTimeout() throws Exception {
CountDownLatch latch = new CountDownLatch(1);
assertThat(latch.await(10, TimeUnit.MILLISECONDS)).isTrue();
}
@stephan-mueller
stephan-mueller / CustomerBuilderAssertjTest.java
Created September 29, 2015 12:57
Test class for the builder {@link CustomerBuilder} with AssertJ assertions
public class CustomerBuilderAssertjTest {
private Customer customer;
@Before
public void setUp() throws Exception {
customer = Customer.newBuilder()
.setFirstName("Max")
.setLastName("Mustermann")
.setEmail("max.mustermann@openknowledge.de")
@stephan-mueller
stephan-mueller / CustomerBuilderHamcrestTest.java
Created September 29, 2015 12:55
Test class for the builder {@link CustomerBuilder} with Hamcrest assertions
public class CustomerBuilderHamcrestTest {
private Customer customer;
@Before
public void setUp() throws Exception {
customer = Customer.newBuilder()
.setFirstName("Max")
.setLastName("Mustermann")
.setEmail("max.mustermann@openknowledge.de")
@stephan-mueller
stephan-mueller / Customer.java
Created September 29, 2015 12:54
An entity that represents a customer
public class Customer implements Serializable {
private Long id;
private String firstName;
private String lastName;
private String email;
@stephan-mueller
stephan-mueller / SpecializedMailServiceIT.java
Created September 28, 2015 16:49
Arquillian test for the cdi service specializes {@link SpecializedMailService}.
@RunWith(Arquillian.class)
public class SpecializedMailServiceIT {
private static final Logger LOG = LoggerFactory.getLogger(SpecializedMailServiceIT.class);
@Deployment
public static Archive createDeployment() {
PomEquippedResolveStage pomFile = Maven.resolver().loadPomFromFile("pom.xml");
WebArchive archive = ShrinkWrap.create(WebArchive.class)
@stephan-mueller
stephan-mueller / SpecializedMailService.java
Created September 28, 2015 16:48
Specialized implementation for the service {@link MailService}.
@Specializes
public class SpecializedMailService extends MailService {
public static CountDownLatch latch;
@Override
public void sendMail(final String subject, final String body, final String... recipients) {
latch.countDown();
}
}