我目前正在努力解决我的任务问题。我必须为代理(MyCacheProxy)创建一个类,它将重定向请求图片。它在下面,似乎很好。
package ijp.proxy;
import ijp.Picture;
import ijp.service.Service;
import ijp.service.ServiceFromProperties;
public class MyCacheProxy {
private Service baseService = null;
public MyCacheProxy()
{
baseService = new ServiceFromProperties("MyCacheProxyTest.base_service");
}
public Picture getPicture(String subject, int index)
{
Picture picture = baseService.getPicture(subject, index);
return picture;
}
}
然后为我们提供了测试该代理的类的代码模板。但是,模板会测试库中提供的单独代理。我想要做的是测试我上面创建的代理MyCacheProxy。我假设这可以通过导入我的MyCacheProxy类来完成,但它没有用。
我真的不确定如何进步,并希望得到任何帮助或提示。
package ijp.test;
import static org.junit.Assert.*;
import java.awt.image.BufferedImage;
import org.junit.Test;
import ijp.Picture;
import ijp.proxy.CacheProxy;
import ijp.service.Service;
/**
* A template for testing a cache proxy for the PictureViewer application.
*
* @author YOUR NAME HERE
* @version YOUR VERSION HERE
*/
public class MyCacheProxyTest implements Service {
/**
* Test that requests for the same subject and index return the same image.
*/
@Test
public void equalityTest() {
Service proxy = new CacheProxy(this);
Picture firstPicture = proxy.getPicture("equalityTest",2);
Picture secondPicture = proxy.getPicture("equalityTest",2);
assertTrue(
"different picture returned for same subject (and index)",
firstPicture.equals(secondPicture));
}
/**
* Return a picture from the simulated service.
* This service simply returns an empty picture every time that it called.
* Note that a <em>different</em> object is returned each time, even if the
* subject and index are the same.
*
* @param subject the requested subject
* @param index the index of the picture within all pictures for the requested topic
*
* @return the picture
*/
@Override
public Picture getPicture(String subject, int index) {
return new Picture((BufferedImage)null, subject ,serviceName(), index);
}
/**
* Return a textual name to identify the simulated service.
*
* @return the name of the service ("cacheProxyTest")
*/
@Override
public String serviceName() {
return "MyCacheProxyTest";
}
}