Java 测试在另一个类中定义的代理

Java 测试在另一个类中定义的代理,java,proxy,Java,Proxy,我目前正在努力完成任务的一个方面。我必须为代理(MyCacheProxy)创建一个类,该类将重新定向图片请求。它在下面,看起来很好 package ijp.proxy; import ijp.Picture; import ijp.service.Service; import ijp.service.ServiceFromProperties; public class MyCacheProxy { private Service baseService = null; public

我目前正在努力完成任务的一个方面。我必须为代理(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";
}
}
包ijp.test;
导入静态org.junit.Assert.*;
导入java.awt.image.buffereImage;
导入org.junit.Test;
进口ijp.图片;
导入ijp.proxy.CacheProxy;
导入ijp.service.service;
/**
*用于测试PictureViewer应用程序的缓存代理的模板。
* 
*@author你的名字在这里
*@version此处显示您的版本
*/
公共类MyCacheProxyTest实现服务{
/**
*测试相同主题和索引的请求是否返回相同的图像。
*/
@试验
公共无效均衡测试(){
服务代理=新缓存代理(此);
Picture firstPicture=proxy.getPicture(“equalityTest”,2);
Picture secondPicture=proxy.getPicture(“equalityTest”,2);
资产真实(
“为同一主题(和索引)返回的不同图片”,
第一张图片。等于(第二张图片));
}
/**
*从模拟服务返回图片。
*该服务每次调用时只返回一张空图片。
*请注意,每次都返回不同的对象,即使
*主题和索引是相同的。
*
*@param subject请求的主题
*@param index请求主题的所有图片中的图片索引
*
*@归还照片
*/
@凌驾
公共图片getPicture(字符串主题,整数索引){
返回新图片((BuffereImage)null,主题,serviceName(),索引);
}
/**
*返回文本名称以标识模拟服务。
*
*@返回服务的名称(“cacheProxyTest”)
*/
@凌驾
公共字符串serviceName(){
返回“MyCacheProxyTest”;
}
}