Skip to content

Instantly share code, notes, and snippets.

@josefbetancourt
josefbetancourt / ClasspathTestScanner
Last active Aug 29, 2015
Simple method to search Java classpath to find @test annotated JUnit tests
View ClasspathTestScanner
/**
* Get all test classes starting from a base package path.
* <p>
* Example use:
* <pre>
* UnitTestScanner scanner = new UnitTestScanner();
* List<Class<?>> list = scanner.getTestClasses("com.octodecillion.test");
* </pre>
* @param basePackage package where search will start
* @param debug if true output more info
@josefbetancourt
josefbetancourt / RequiresTestAnnotationScanner.java
Last active Aug 29, 2015
Scan classpath for classes with @RequiresTest annotated methods
View RequiresTestAnnotationScanner.java
package com.octodecillion.test;
import java.lang.reflect.Method;
import java.util.List;
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
import org.springframework.core.type.ClassMetadata;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.filter.TypeFilter;
@josefbetancourt
josefbetancourt / FubarClassExample.java
Created Nov 30, 2011
Sample class for illustrating unit testing
View FubarClassExample.java
public class Fubar {
private boolean launch = true;
public void getLaunch(){
return this.launch;
}
public void setLaunch(boolean launch){
/* this.launch = launch; */ // broken!
}
@josefbetancourt
josefbetancourt / Vsdf.java
Last active Oct 13, 2015
Very simple data file in Java source with embedded JUnit test. Presented in "Simple Java Data File" blog post.
View Vsdf.java
/** Vsdf.java */
package com.octodecillion.vsdf;
import static com.octodecillion.vsdf.Vsdf.EventType.END;
import static org.hamcrest.core.DescribedAs.describedAs;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
@josefbetancourt
josefbetancourt / InvokeCounter.java
Last active Oct 13, 2015
Behavior counters for improved JUnit tests
View InvokeCounter.java
package com.octodecillion.junit;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import java.util.HashMap;
import java.util.Map;
/**
@josefbetancourt
josefbetancourt / JarInfo.java
Created Dec 15, 2012
Source code from blog post "Java Generics Example: Jar Manifest" at [http://octodecillion.com/blog/java-generics-manifest/]
View JarInfo.java
/**
*
*/
package com.octodecillion.utils;
import java.io.IOException;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.jar.Attributes;
import java.util.jar.JarFile;
View InitMap.java
package com.octodecillion.util;
import java.util.Map;
import java.util.Map.Entry;
/**
* A {@link Map} decorator that allows
* <a href="https://en.wikipedia.org/wiki/Fluent_interface#Java">Fluent</a>
* add of entries.<p>
*
View DuplicatePropertyDetectorWithCGLIB.java
package com.octodecillion.util;
import java.io.IOException;
import java.io.Reader;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
View DuplicatePropertyDetectorWithJavassist.java
package com.octodecillion.util;
import java.io.IOException;
import java.io.Reader;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
View DuplicatePropertyDetectorWithSubClass.java
package com.octodecillion.util;
import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;