执行 JUnit 测试用例时出现 AssertionError

AssertionError while executing JUnit test case

我正在执行 JUnit 测试用例来测试服务。我正面临 java.lang.AssertionError 而 运行 测试用例。下面给出的是测试 class 和 url 构建器代码段。

@Test
    public void testSuccess() throws Exception
    {
        final String mockedResponseJson = rawJsonFromFile("com/cnanational/preferences/client/rule-sets/getRuleSetsResponse.json");

        MockRestServiceServer mockServer = mockServer();

        mockServer.expect(requestTo(dummyUri()))
                .andExpect(queryParam("ruleSetDescription", RULE_DESCRIPTION))
                .andExpect(method(HttpMethod.GET))
                .andRespond(withSuccess(
                        mockedResponseJson,
                        MediaType.APPLICATION_JSON));

        ServiceClientResponse<GetRuleSetsResponse> response = executeDummyRequest();

        mockServer.verify();

        assertThat(response.isSuccessful(), equalTo(true));

    }

实际需要测试的服务代码如下:

    URI targetUri = UriComponentsBuilder.fromUri(this.preferencesServiceUri).path(this.rulesSetsPath)
                .queryParam("ruleSetDescription", params).build()
                .toUri();

下面给出了我得到的断言错误的堆栈跟踪:

java.lang.AssertionError: Unexpected request expected:<http://localhost:8039> but was:<http://localhost:8039?ruleSetDescription=TestRuleDescription>
    at org.springframework.test.util.AssertionErrors.fail(AssertionErrors.java:54)
    at org.springframework.test.util.AssertionErrors.assertEquals(AssertionErrors.java:81)
    at org.springframework.test.web.client.match.MockRestRequestMatchers.match(MockRestRequestMatchers.java:121)

具有类似 JUnit 案例和类似 GET 端点的其他测试 classes 工作正常。我错过了什么吗?请给我一些建议。

请使用调试器,在该行设置断点

URI targetUri = ...

并找出 URL 未正确构建的原因。