001package io.avaje.inject.spi; 002 003import org.mockito.Mockito; 004 005import java.util.function.Consumer; 006 007/** 008 * Holds Spy setup consumers for dependency injection using Mockito Spy. 009 */ 010public class EnrichBean<B> { 011 012 private final Class<B> type; 013 014 private final Consumer<B> consumer; 015 016 public EnrichBean(Class<B> type, Consumer<B> consumer) { 017 this.type = type; 018 this.consumer = consumer; 019 } 020 021 /** 022 * Return the dependency injection target type. 023 */ 024 public Class<B> getType() { 025 return type; 026 } 027 028 /** 029 * Return the spy enhanced bean instance to use. 030 */ 031 public B enrich(B bean) { 032 // should extract a SPI for this. Only enrichment is Mockito spy at this point. 033 B spy = Mockito.spy(bean); 034 if (consumer != null) { 035 consumer.accept(spy); 036 } 037 return spy; 038 } 039}