| | |
| | | } |
| | | |
| | | private static <T> T stub(Class<T> type, InvocationHandler handler) { |
| | | return type.cast(Proxy.newProxyInstance(type.getClassLoader(), new Class<?>[]{type}, handler)); |
| | | return type.cast(Proxy.newProxyInstance(type.getClassLoader(), new Class<?>[]{type}, (proxy, method, args) -> { |
| | | if (method.getDeclaringClass() == Object.class) { |
| | | return switch (method.getName()) { |
| | | case "toString" -> type.getSimpleName() + "Stub"; |
| | | case "hashCode" -> System.identityHashCode(proxy); |
| | | case "equals" -> proxy == args[0]; |
| | | default -> throw new AssertionError(method.getName()); |
| | | }; |
| | | } |
| | | return handler.invoke(proxy, method, args); |
| | | })); |
| | | } |
| | | |
| | | static class Fixture { |