我有一个像这样的对象流:
"0", "1", "2", "3", "4", "5",
Run Code Online (Sandbox Code Playgroud)
如何将其转换为对的流:
{ new Pair("0", "1"), new Pair("2", "3"), new Pair("4", "5")}.
Run Code Online (Sandbox Code Playgroud)
流大小未知.我正在从一个可能很大的文件中读取数据.我只有收集器的迭代器,我使用spliterator将此迭代器转换为流.我知道这是使用StreamEx处理相邻对的答案: 从流中收集连续对 可以在java或StreamEx中完成吗?谢谢
我正在使用Wiremock模拟github api对我的服务进行一些测试。该服务调用API GitHub的。为了测试我的端点属性设置为
github.api.endpoint=http://localhost:8087
Run Code Online (Sandbox Code Playgroud)
该主机和端口与Wiremock服务器相同,@AutoConfigureWireMock(port = 8087)因此我可以测试不同的情况,例如:格式错误的响应,超时等。
我怎样才能让这个端口动态,以避免情况下,当它已经使用的系统?有没有办法让wiremock端口测试和重新分配端点的财产?
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureWireMock(port = 8087)
@TestPropertySource(properties ={"github.api.endpoint=http://localhost:8087"})
public class GithubRepositoryServiceTestWithWireMockServer {
@Value("${github.api.client.timeout.milis}")
private int githubClientTimeout;
@Autowired
private GithubRepositoryService service;
@Test
public void getRepositoryDetails() {
GithubRepositoryDetails expected = new GithubRepositoryDetails("niemar/xf-test", null,
"https://github.com/niemar/xf-test.git", 1, "2016-06-12T18:46:24Z");
stubFor(get(urlEqualTo("/repos/niemar/xf-test"))
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("/okResponse.json")));
GithubRepositoryDetails repositoryDetails = service.getRepositoryDetails("niemar", "xf-test");
Assert.assertEquals(expected, repositoryDetails);
}
@Test
public void testTimeout() {
GithubRepositoryDetails expected = new GithubRepositoryDetails("niemar/xf-test", null,
"https://github.com/niemar/xf-test.git", 1, "2016-06-12T18:46:24Z");
stubFor(get(urlEqualTo("/repos/niemar/xf-test"))
.willReturn(aResponse()
.withHeader("Content-Type", "application/json")
.withBodyFile("/okResponse.json")
.withFixedDelay(githubClientTimeout * 3)));
boolean wasExceptionThrown …Run Code Online (Sandbox Code Playgroud)