This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package no.gorman.stop.it; | |
import java.lang.reflect.InvocationTargetException; | |
import java.lang.reflect.Method; | |
import javassist.util.proxy.MethodHandler; | |
import javassist.util.proxy.ProxyFactory; | |
/** | |
* I like using Mockito in tests and wondered if I could create |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.lang.ref.WeakReference; | |
import java.util.WeakHashMap; | |
public class Test { | |
/** | |
* Still don't know why the first two lambdas don't get cleared by the GC :( | |
*/ | |
public static void main(String[] args) throws Exception { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.WeakHashMap; | |
public class PubSub { | |
static @FunctionalInterface interface Subscriber<T> { | |
public void hereYouGo(T message); | |
} | |
static class Publisher<T> { | |
WeakHashMap<Subscriber<T>, Boolean> subscribers = new WeakHashMap<>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Example of how you can rewrite your code to avoid the need for mocks in your tests */ | |
/*----------------------------------------------- | |
Implementation where you need mocks for testing | |
-------------------------------------------------*/ | |
public class MyClassThatNeedsTesting { | |
private BusinessLogicClass blc; | |
public int estimatedTotalCost(SomeDataStructure input) { |