SET @row := NULL;
SELECT
SomeColumn,
AnotherColumn
FROM (
SELECT
CASE @id <=> SomeColumn AND @row IS NOT NULL
WHEN TRUE THEN @row := @row+1
ELSE @row := 0
END AS rownum,
@id := SomeColumn AS SomeColumn,
AnotherColumn
FROM
SomeTable
ORDER BY
SomeColumn, -AnotherColumn DESC
) _values
WHERE rownum = 0
ORDER BY SomeColumn;
在运行测试用例时,@RunWith(PowerMockRunner.class)
@PrepareForTest({ConnectionFactory.class, Proxy.class})
public class ConnectionFactoryTest {
@InjectMocks
private ConnectionFactory connectionFactory;
@Mock
private Proxy proxy;
@Mock
private InetSocketAddress inetSocketAddress;
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
PowerMockito.mockStatic(Proxy.class);
PowerMockito.whenNew(InetSocketAddress.class).withArguments(Mockito.anyString(), Mockito.anyInt()).thenReturn(inetSocketAddress);
PowerMockito.whenNew(Proxy.class).withArguments(Proxy.Type.SOCKS, Mockito.any(InetSocketAddress.class)).thenReturn(proxy);
}
@Test
public void testInitializeProxy() throws Exception {
connectionFactory.getHttpURLConnection(Mockito.any(URL.class));
}
}
public class ConnectionFactory implements HttpURLConnectionFactory {
private String proxyHost;
private Integer proxyPort;
Proxy proxy;
public HttpURLConnection getHttpURLConnection(URL url) throws IOException {
InetSocketAddress inetSocketAddress = new InetSocketAddress(proxyHost, proxyPort); // error occurs here
proxy = new Proxy(Proxy.Type.SOCKS, inetSocketAddress);
return (HttpURLConnection) url.openConnection(proxy);
}
}
和new InetSocketAddress
会调用anyString()
,但仍然会引发anyInt()
。在这方面,欢迎任何建议。
NullPointerException
上面添加了错误跟踪。在ConnectionFactoryTest类中执行测试方法testInitializeProxy()时发生此错误
答案 0 :(得分:0)
您尚未初始化error: pattern cannot match values of type 'State'
case (.scan, .stopScanning): State.idle
~^~~~
。
因此,在您实际初始化成员变量之前,该成员变量为proxyHost
。