Remove unused type parameter declarations in MockMvc result matchers

Prior to this commit, several of the ResultMatcher methods used in
MockMvc declared unused type parameters (e.g., <T>). This was obviously
the result of copying an existing method that actually needs the type
parameter for proper casting.

For example, the following in RequestResultMatchers ...

public <T> ResultMatcher attribute(String name, Object expectedValue) {
    // ...
}

... should actually be declared without <T>, since T is not used in the
implementation or in the return type:

public ResultMatcher attribute(String name, Object expectedValue) {
    // ...
}

This commit removes all unused type parameter declarations in MockMvc
result matchers.

Side Effects:

Now that we have removed the unused type parameter declarations, users
will see the following side effects if they had previously declared a
type argument when invoking such methods.

- Java: an "Unused type arguments for the non generic method ..."
  warning will be generated by the compiler, but the code will continue
  to work unmodified.

- Kotlin: a "Type inference failed: Not enough information to infer
  parameter T in fun ..." compiler error will be raised, causing the
  code to no longer compile (see
  https://youtrack.jetbrains.com/issue/KT-5464). Removal of the type
  argument declaration will allow the code to work correctly again.

Closes gh-23858
This commit is contained in:
Sam Brannen
2019-10-23 14:10:25 +02:00
parent 5c0212e678
commit 693101ded8
5 changed files with 13 additions and 13 deletions

View File

@@ -130,7 +130,7 @@ class MockMvcExtensionsTests {
assertThatExceptionOfType(AssertionError::class.java).isThrownBy { content { json("""{"name":"wrong"}""") } }
assertThatExceptionOfType(AssertionError::class.java).isThrownBy { jsonPath("name") { value("wrong") } }
assertThatExceptionOfType(AssertionError::class.java).isThrownBy { cookie { value("name", "wrong") } }
assertThatExceptionOfType(AssertionError::class.java).isThrownBy { flash { attribute<String>("name", "wrong") } }
assertThatExceptionOfType(AssertionError::class.java).isThrownBy { flash { attribute("name", "wrong") } }
assertThatExceptionOfType(AssertionError::class.java).isThrownBy { header { stringValues("name", "wrong") } }
assertThatExceptionOfType(AssertionError::class.java).isThrownBy { model { attributeExists("name", "wrong") } }
assertThatExceptionOfType(AssertionError::class.java).isThrownBy { redirectedUrl("wrong/Url") }