Skip to content

Instantly share code, notes, and snippets.

View jangalinski's full-sized avatar

Jan Galinski jangalinski

View GitHub Profile
import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.util.Set;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.inject.Any;
import javax.enterprise.inject.Default;
import javax.enterprise.inject.spi.Bean;
@jangalinski
jangalinski / BeanValidationRule.java
Created April 11, 2013 09:14
Useful little junit-4.11 classrule that allows to assertValid() directly without looking into the validation result set every time, but still can be used as a full blown JSR303 validator if needed.
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.collection.IsEmptyCollection.empty;
import static org.junit.Assert.assertThat;
import java.util.Set;
import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
@jangalinski
jangalinski / ActivitiTestWatchman.java
Created April 10, 2013 21:05
suggestion on how to extend/fix the current ProcessEngineRule
/**
* Rewrite of the ActivitiRule since TestWatchman is deprecated for junit>4.9.
*
* @author Jan Galinski, Holisticon AG (jan.galinski@holisticon.de)
*/
public class ActivitiTestWatcher extends TestWatcher implements ProcessEngineRule {
/**
* Default configuration file name when not used with needle.
*/
public class FactoryThatThrowsException {
// a String creation Factory/Builder ...
public static String getString() throws Exception {
throw new Exception();
}
// normally would not compile
private final String aString = getString();
@jangalinski
jangalinski / Coin.java
Created March 21, 2013 12:50
cannot decide what to do? Just Coin.flip() to get random 50/50 decisions.
import java.util.Random;
public class Coin {
private static final Random random = new Random();
@Deprecated
private Coin() {
// never instantiate
}
package sof14839561;
import static com.google.inject.Guice.createInjector;
import static com.google.inject.name.Names.named;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import javax.inject.Inject;
import javax.inject.Named;
public MyBean {
@Inject
@Named("myValue")
private String value;
@Produces
@Named("myValue")
private static String initValue() {
return new PropertyReader("file").getValue("parameter");
public MyBean {
private String value;
@PostConstruct
public void initValue() {
value = new PropertyReader("file").getValue("parameter");
}
}
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ear-subdeployments-isolated>false</ear-subdeployments-isolated>
<!--
I have a ear deployment, I'm specifying only the module which is client of the EJB Remote module running in AS5.
My client class is itself an EJB 3.1 running in JBoss AS7. It is client of an EJB 2.0 running in JBoss AS5.
-->
<sub-deployment name="my-ejb-module-on-as7-${project.version}.jar">
<dependencies>