Skip to content

Instantly share code, notes, and snippets.

View richashworth's full-sized avatar

Richard Ashworth richashworth

View GitHub Profile
import $ivy.`com.github.julien-truffaut::monocle-core:1.4.0`, monocle.Lens
import $ivy.`com.github.julien-truffaut::monocle-macro:1.4.0`, monocle.macros.GenLens
// _.copy fine for simple cases
case class Address(line1: String, line2: String, postcode: String)
val a = Address("221B", "Baker St", "NW1 6XE")
println(a)
println(a.copy(line1 = "221A"))
@richashworth
richashworth / MockObjectPopulator.java
Last active September 16, 2016 13:25
Mock Object Populator
package com.richashworth.testingutils.mocking;
import java.lang.reflect.Method;
import java.util.Map;
import static org.junit.Assert.fail;
public class MockObjectPopulator {
private DefaultValues defaultValues = new DefaultValues();
$ tmux new -s dev
@richashworth
richashworth / gist:8138799
Created December 26, 2013 21:17
Fix for Jetpack RSS Widget
if ( 'text-image' == $format )
$link_item .= '<p>&nbsp;<a href="' . get_bloginfo($rss_type) . '" title="' . esc_attr( $subscribe_to ) . '"><br/>' . esc_html__('RSS - ' . $type_text, 'jetpack'). '</a></p>';
abstract sealed class Beat
case object Rest extends Beat
case object Note extends Beat
case class Note(pitch: Int, duration: Int) extends Beat
case class Pattern(beats: Seq[Beat])
def formatBeat(b: Beat): String = b match {
case Rest => " _ "
case Note => " X "
package com.richashworth.testingutils.mocking;
import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
import static junit.framework.Assert.assertEquals;
public class FootballerTest2 {
package com.richashworth.testingutils.mocking;
import org.junit.Test;
import static junit.framework.Assert.assertEquals;
public class FootballerTest {
@Test
public void testGetGameGoalsRatio() {
@richashworth
richashworth / DataProvider.java
Last active October 1, 2015 19:18
Used as dependency in PowerMock Example
package com.richashworth.powermockexample;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.List;
import static com.google.common.io.Files.readLines;
public final class DataProvider {
@richashworth
richashworth / DefaultValues.java
Last active September 29, 2015 02:58
Default Values Class
package com.richashworth.testingutils.mocking;
import java.util.HashMap;
import java.util.Map;
public class DefaultValues {
private Map<String, Object> defaultValuesMap;
public DefaultValues() {
@richashworth
richashworth / Footballer.java
Last active September 29, 2015 01:07
Used in Example to Demonstrate Naive Initialisation of Mock Object
package com.richashworth.testingutils.mocking;
public class Footballer {
private String name;
private int age;
private Double salary;
private Integer gamesPlayed;
private Integer goalsScored;
private Boolean isCaptain;