Skip to content

Instantly share code, notes, and snippets.

@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 / FindFile.groovy
Created Jul 9, 2012
Use Groovy to find path of a file in a directory tree
View FindFile.groovy
import groovy.transform.TypeChecked
/**
* search file according to its name in directory and subdirectories
*/
@TypeChecked
class FileFind {
String basePath; // for unit testing
@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;
@josefbetancourt
josefbetancourt / Vsdf.groovy
Last active Dec 9, 2015
Groovy source code from blog post "A very simple data file metaformat" at http://octodecillion.com/blog/very-simple-data-file-format/
View Vsdf.groovy
package com.octodecillion.inix
import java.util.regex.Pattern
import groovy.transform.TypeChecked
import java.util.regex.Matcher
/**
*
*
* @author Josef Betancourt
@josefbetancourt
josefbetancourt / GraphSort.java
Last active Dec 10, 2015
Source code for blog post "List sorting using topological ordering of a digraph" http://octodecillion.com/blog/sort-using-digraph/
View GraphSort.java
package com.octodecillion.sort;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.Arrays;
@josefbetancourt
josefbetancourt / SvnOutputTransform.java
Last active Dec 15, 2015
Transform SVN log diff using Java XPath example for blog post http://octodecillion.com/blog/svn-report-java-xpath/
View SvnOutputTransform.java
/**
*
*/
package com.octodecillion.utils;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Reader;
@josefbetancourt
josefbetancourt / Gather.groovy
Last active Dec 23, 2015
Code to accompany "Parsing files using Groovy closures" on my blog.
View Gather.groovy
package com.octodecillion
import java.nio.file.Files;
/**
* Simple folder walker and file parser.
* <p>
* Dev with Groovy 2.1.6, Java 7, Eclipse 4.3
*
* @author jbetancourt
@josefbetancourt
josefbetancourt / GoGenerator.groovy
Created Oct 15, 2013
Code for blog post "Change dir batch generator using Groovy" on http://octodecillion.com
View GoGenerator.groovy
/**
* GoGenerator.groovy
* Copyright 2010 Josef Betancourt 20100312-17:47
*/
/*@Grapes([
@Grab(group='ch.qos.logback', module='logback-core', version='0.9.18'),
@Grab(group='ch.qos.logback', module='logback-classic', version='0.9.18'),
@Grab(group='org.slf4j', module='slf4j-api', version='1.5.10')])