lundi 7 décembre 2015

How to inject mock for @Lookup annotation in spring

@Component
public class SomeFactory implements ISomeFactory {

    public someWatchFactory() {};
    @Override
    public boolean startWatch(MethodToWatch methodName, UUID uniqueID, Callable toRun) {
        IPerformanceStopWatch mywatch = getStartWatch(methodName,uniqueID,toRun);
        return mywatch.startWatchDeployTaskStatus();
    }

     @Lookup
    private IPerformanceStopWatch getStartWatch(MethodToWatch methodName, String uniqueID, Callable toRun) {
        IPerformanceStopWatch mywatch = getStartWatch(methodName,uniqueID,toRun);
        return null;  //stub implementation which will be replaced by the container
    }
}

I would like to test the factory class, using something like:

@InjectMock
ISomeFactory someFactory;

@Mock
IPerformanceStopWatch performanceWatch

That whenever the lookup annotation inside the SomeFactory class will try to get the instance, it will use the mock.

How should i do it?

Aucun commentaire:

Enregistrer un commentaire