Skip to content

Instantly share code, notes, and snippets.

View richashworth's full-sized avatar

Richard Ashworth richashworth

View GitHub Profile
@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;
@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();
@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 / 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 / ResultsWriter.java
Last active June 28, 2020 15:07
Used as Class Under Test in PowerMock Example
package com.richashworth.powermockexample;
import java.util.List;
public class ResultsWriter {
public String getDataAsString(){
StringBuilder builder = new StringBuilder();
List<String> dataList = DataProvider.getData();
for(String str: dataList){
@richashworth
richashworth / ResultsWriterTest.java
Last active March 1, 2019 18:54
Unit Test used in PowerMock Example
package com.richashworth.powermockexample;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
package com.richashworth.testingutils.mocking;
import org.junit.Test;
import static junit.framework.Assert.assertEquals;
public class FootballerTest {
@Test
public void testGetGameGoalsRatio() {
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 {
@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>';
$ tmux new -s dev