Skip to content

Instantly share code, notes, and snippets.

View fappel's full-sized avatar

Frank Appel fappel

View GitHub Profile
@fappel
fappel / RunInThread
Last active August 8, 2023 10:17
JUnit 4 TestRule to run a test in its own thread
/**
* RunInThread an other accompanying files are licensed under the MIT
* license. Copyright (C) Frank Appel 2016-2021. All rights reserved
*/
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@fappel
fappel / Repeat.java
Last active June 5, 2023 16:58
JUnit 4 TestRule to run a test repeatedly for a specified amount of repititions
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 March 30, 2014 05:15
A utility class and to ease SWT FormData handling (Dependencies: SWT & JUnit + DisplayHelper gist for test).
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 March 8, 2014 06:59
Utility to simplify event listener notifcation of SWT widgets. Basically created for JUnit testing.
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 January 4, 2017 05:32
JUnit 4 TestRule to ease SWT Display Tests (Dependencies: JUnit, SWT, Guava)
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 May 7, 2021 07:58
Draft of an Custom SWT Layout for Responsive SWT UI Development (depends on SWT and Google Guava)
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 August 29, 2015 13:56
JUnit 4 Templates for Eclipse
<?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 February 7, 2014 14:30
Mockito Templates for Eclipse
<?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