Skip to content

Instantly share code, notes, and snippets.

@bcoughlan
bcoughlan / MockUtils.java
Last active May 29, 2024 23:19
Mock an interface by proxying to a a real class
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Proxy;
public class MockUtils {
/**
* Proxy an interface to a real implementation. The implementation doesn't have to implement the interface,
* which can save on a lot of boilerplate for test doubles.
*/
public static <T> T proxyToFake(Class<T> iface, Object forwardTo) {
@bcoughlan
bcoughlan / build.yml
Created April 11, 2025 22:43
Continuous versioning: headver in GitHub Actions
name: Build
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest