我这里有一个界面
interface Idemo{
public int getDemo(int i);
}
Run Code Online (Sandbox Code Playgroud)
这是一个实现
class DemoImpl implements Idemo{
@Override
public int getDemo(int i){
return i+10;
}
}
Run Code Online (Sandbox Code Playgroud)
并且有一个类依赖于Idemo
class Sample{
@Inject
Idemo demo;
public int getSample(int i){
return demo.getDemo(i);
}
}
Run Code Online (Sandbox Code Playgroud)
现在说我想测试Sample类
public class SampleTest extends JerseyTest {
@Inject
Sample s;
@Override
protected Application configure() {
AbstractBinder binder = new AbstractBinder() {
@Override
protected void configure() {
bind(Demo.class).to(Idemo.class);
bind(Sample.class).to(Sample.class); //**doesn't work**
}
};
ResourceConfig config = new ResourceConfig(Sample.class);
config.register(binder);
return config;
}
@Test
public void …Run Code Online (Sandbox Code Playgroud)