1/* 2 * Copyright (c) 2016 Mockito contributors 3 * This program is made available under the terms of the MIT License. 4 */ 5package org.mockito.internal.creation.bytebuddy; 6 7import java.lang.reflect.Method; 8import java.util.concurrent.Callable; 9import java.util.concurrent.ConcurrentHashMap; 10import java.util.concurrent.ConcurrentMap; 11 12public abstract class MockMethodDispatcher { 13 14 private static final ConcurrentMap<String, MockMethodDispatcher> INSTANCE = new ConcurrentHashMap<String, MockMethodDispatcher>(); 15 16 public static MockMethodDispatcher get(String identifier, Object mock) { 17 if (mock == INSTANCE) { // Avoid endless loop if ConcurrentHashMap was redefined to check for being a mock. 18 return null; 19 } else { 20 return INSTANCE.get(identifier); 21 } 22 } 23 24 public static void set(String identifier, MockMethodDispatcher dispatcher) { 25 INSTANCE.putIfAbsent(identifier, dispatcher); 26 } 27 28 public abstract Callable<?> handle(Object instance, Method origin, Object[] arguments) throws Throwable; 29 30 public abstract boolean isMock(Object instance); 31 32 public abstract boolean isMocked(Object instance); 33 34 public abstract boolean isOverridden(Object instance, Method origin); 35} 36