Skip to content

Instantly share code, notes, and snippets.

Frank Appel fappel

View GitHub Profile
@fappel
fappel / RunInThread
Last active Dec 3, 2019
JUnit 4 TestRule to run a test in its own thread
View RunInThread
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
public @interface RunInThread {
}
@fappel
fappel / Repeat.java
Last active Dec 3, 2019
JUnit 4 TestRule to run a test repeatedly for a specified amount of repititions
View Repeat.java
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention( RetentionPolicy.RUNTIME )
@Target( {
java.lang.annotation.ElementType.METHOD
} )
public @interface Repeat {
public abstract int times();
@fappel
fappel / FormDatas.java
Created Mar 30, 2014
A utility class and to ease SWT FormData handling (Dependencies: SWT & JUnit + DisplayHelper gist for test).
View FormDatas.java
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.widgets.Control;
public class FormDatas {
static final int DENOMINATOR = 100;
private final FormData formData;
@fappel
fappel / SWTEventHelper.java
Created Mar 8, 2014
Utility to simplify event listener notifcation of SWT widgets. Basically created for JUnit testing.
View SWTEventHelper.java
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Touch;
import org.eclipse.swt.widgets.Widget;
public class SWTEventHelper {
private final Event event;
private SWTEventHelper( int eventType ) {
@fappel
fappel / DisplayHelper.java
Last active Jan 4, 2017
JUnit 4 TestRule to ease SWT Display Tests (Dependencies: JUnit, SWT, Guava)
View DisplayHelper.java
import static com.google.common.collect.Iterables.toArray;
import static com.google.common.collect.Lists.newLinkedList;
import static java.util.Arrays.asList;
import java.util.Collection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.junit.rules.TestRule;
@fappel
fappel / Demo ScaleLayout
Last active Dec 18, 2015
Draft of an Custom SWT Layout for Responsive SWT UI Development (depends on SWT and Google Guava)
View Demo ScaleLayout
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
public class Demo {
@fappel
fappel / junit-4-templates.xml
Last active Aug 29, 2015
JUnit 4 Templates for Eclipse
View junit-4-templates.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?><templates><template autoinsert="false" context="java-members" deleted="false" description="JUnit 4 test case set up method" enabled="true" name="setUp">@${testType:newType(org.junit.Before)}
public void setUp() {
${cursor}
}</template><template autoinsert="false" context="java-members" deleted="false" description="JUnit 4 test case clean up method" enabled="true" name="tearDown">@${testType:newType(org.junit.After)}
public void tearDown() {
${cursor}
}</template><template autoinsert="false" context="java-members" deleted="false" description="JUnit 4 test method" enabled="true" id="org.eclipse.jdt.ui.templates.test_junit4" name="test">@${testType:newType(org.junit.Test)}
public void test${Name}() {
${cursor}
}</template><template autoinsert="false" context="java-members" deleted="false" description="Data collection method for parameterized JUnit test cases based on an enum type" enabled="true" name="parametersOverEnum">${a:importStatic(com.google.com
@fappel
fappel / mockito-templates.xml
Created Feb 7, 2014
Mockito Templates for Eclipse
View mockito-templates.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?><templates><template autoinsert="false" context="java-statements" deleted="false" description="Mockito doAnswer(answer).when(mock).call() construct" enabled="true" name="doAnswer">${a:importStatic(org.mockito.Mockito.doAnswer)}${b:import(org.mockito.stubbing.Answer, org.mockito.invocation.InvocationOnMock, java.lang.Throwable)}doAnswer( new Answer&lt;${T}&gt;() {&#13;
public ${T} answer( InvocationOnMock invocation ) throws Throwable {&#13;
${cursor}&#13;
return null;&#13;
}&#13;
} ).when( ${mock} ).${call};</template><template autoinsert="false" context="java-statements" deleted="false" description="Mockito doAnswer(answer).when(mock).call() construct that manipulates invocation argument" enabled="true" name="doAnswerOnArgument">${a:importStatic(org.mockito.Mockito.doAnswer)}${b:import(org.mockito.stubbing.Answer, org.mockito.invocation.InvocationOnMock, java.lang.Throwable)}doAnswer( new Answer&lt;${T}&gt;() {&#13;
public ${T} answer( InvocationOn
You can’t perform that action at this time.