考虑以下 servlet 代码:
public class AddDevice extends JsonServlet {
private static final long serialVersionUID = 1L;
@Override
protected void doGet(final JsonServletRequest request,
final JsonServletResponse response) throws ServletException,
IOException {
try {
final DeviceEntity device = new DeviceEntity();
device.type =
FleetManagerDatabaseHelper
.deviceTypesAccessor()
.queryForId(Integer.valueOf(
request.getParameter(DeviceTypeEntity._ID)));
device.sn = request.getParameter(DeviceEntity._SN);
device.status = Long.valueOf(0);
FleetManagerDatabaseHelper.devicesAccessor().create(device);
}
catch (final SQLException e) {
throw new ServletException("device already exists");
}
}
}
此代码取决于 DeviceEntity 和 FleetManagerDatabaseHelper 类。现在,我想为它编写一个测试,检查创建的实体是否填充了正确的类型、sn 和状态值。为此,我可以创建一个 FleetManagerDatabaseHelperMockup 类。
您将如何在此处应用 Google Guice(或其他东西)并进行最少的更改?