我在其中有以下类和方法
public class A extends B implements C{
public void validateTicketGrantingTicket(final TicketGrantingTicket ticketGrantingTicket) throws InvalidTicketException {
if (ticketGrantingTicket != null)
{
if (!ticketGrantingTicket.getHostDomain().equalsIgnoreCase(getServerName()))
{
throw new InvalidTicketException();
}
}
}
public String getServerName()
{
String serverName = "";
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
if (request != null)
{
serverName = request.getServerName().toLowerCase();
}
return serverName;
}
}
Run Code Online (Sandbox Code Playgroud)
现在我正在写ATest课并嘲笑A班.
public class ATest {
private A a;
@Before
public void init(){
A = mock(A.class);
when(A.getServerName()).thenReturn("phoenix.edu.abc");
}
@Test
public void validateTicketGrantingTicketTest() throws InvalidTicketException{
a …Run Code Online (Sandbox Code Playgroud) mockito ×1