49122

Type interference issue with the WebFlux WebTestClient and Kotlin

<h3>Question</h3>

I'm building a prototype for a new application using Spring Webflux and Kotlin. Spring Webflux contains a WebTestClient for unit tests. According to the documentation I should be able to test the results of a REST call like this:

@Test fun getVersion_SingleResult_ContentTypeJson_StatusCodeOk_ContentEqualsVersion() { //given var version = Version("Test", "1.0") val handler = ApiHandler(version!!) val client = WebTestClient.bindToRouterFunction(ApiRoutes(handler).apiRouter()).build() //expect val response = client.get().uri("/api/version/").exchange() response.expectStatus().isOk response.expectHeader().contentType(MediaType.APPLICATION_JSON_UTF8) response.expectBody(Version::class.java).isEqualTo(version) }

However, I'm running into some type interference issues. The problem is in the combination of 'expectBody' and 'isEqualTo'.

The error I get is:

<blockquote>

Kotlin: Type inference failed: Not enough information to infer parameter T in fun isEqualTo(p0: Version!): T! Please specify it explicitly.

</blockquote>

The used methods have the following signatures:

<B> WebTestClient.BodySpec<B, ?> expectBody(Class<B> var1); public interface BodySpec<B, S extends WebTestClient.BodySpec<B, S>> { <T extends S> T isEqualTo(B var1); }

Sadly I'm running into the limits of my knowledge of generics and the differences between Kotlin and Java which means that I'm not sure how I should specify this.

Edit:

Recommend

  • Type interference issue with the WebFlux WebTestClient and Kotlin
  • Pass multiple values using ajax and echo in another page
  • Does python garbage-collect at the end of an iteration in a loop?
  • Fetch data from nested nodes in Firebase
  • Limit # of records returned based on a form control
  • Adding custom message on Thank You page by shipping method
  • Spongycastle is missing many algorithms when loaded on android
  • Jekyll - How do I create pages in the root directory?
  • Expression.Call GroupBy then Select and Count()?
  • Use PHP to Replace HTML with HTML
  • Loading hyperspectral images in Octave
  • Defer unused CSS
  • Unity Resources.load() won't work with external dll
  • Shiny - change the size (padding?) of dropdown menu (select tags) smaller
  • Why do you need 2 Javascript files for cross-platform Cordova plugin?
  • Request Access Token in Postman for Azure Function App protected by Azure AD B2C
  • 'Edit' function for forum posts and such
  • time column in sqlite using gorm
  • trigger ontouch event programmatically
  • When to use the tag in the head and body section of a html page? [duplicate]
  • Annotate objects in a queryset with next and previous object ids
  • Typeahead.js does give me suggestions but doesn't select them
  • PHPMailer return to AJAX
  • How convert html to BBcode in C#
  • How to use Streams api peek() function and make it work?
  • `$http:badreq Bad Request Configuration` - from angular post method, what is wrong here?
  • How to decleare char *const argv[] in swift [duplicate]
  • Send array to next viewcontroller iOs xcode [duplicate]
  • How to get rgb from transparent pixel in js
  • Codeigniniter insert data through models and controller
  • Call Microservice from another Microservice within Docker
  • WPF custom control and direct content support
  • PHP Permalinks.. how to change?
  • What does the “id” field in an Android “Google Play Music” broadcast intent correspond to?