JUnit 测试 POST 到参数化 API

JUnit Testing POST to a parameterized API

如何将 {service} 传递给此 JUnit 测试?

@Test
public void test4() throws Exception {
    List<ProofOfDeliveryUndeliveredResult> returnList = new ArrayList<ProofOfDeliveryUndeliveredResult>();
    given(undeliveredQueryManager.prepareUndeliverServiceRecords(isA(UndeliveredRetrieveFilters.class),isA(String.class))).willReturn(ResponseEntity.ok().body(returnList));
    String response = server.perform(MockMvcRequestBuilders.post("/api/{service}/retrieve").contentType(MediaType.APPLICATION_JSON).content("{\"startRetrieveTime\":\"\",\"endRetrieveTime\":\"\",\"timeStampFormat\":\"\"}"))
        .andExpect(status().isOk())
        .andReturn()
        .getResponse()
        .getContentAsString();
    assertEquals(response,"[]"); 
}

MockMvcRequestBuilderspost() 方法允许您传递可变参数列表,请参阅 javadoc。提供的参数按顺序替换成URL。

server.perform(
  MockMvcRequestBuilders
    .post("/api/{service}/retrieve", "someservice")
    .contentType(MediaTy...