Skip to content

Commit

Permalink
Tests for empty observable
Browse files Browse the repository at this point in the history
  • Loading branch information
jbojar authored and jmnarloch committed Nov 28, 2016
1 parent 29a4ec7 commit d6d4db5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ public class ObservableDeferredResultTest {
@RestController
protected static class Application {

@RequestMapping(method = RequestMethod.GET, value = "/empty")
public ObservableDeferredResult<String> empty() {
return new ObservableDeferredResult<String>(Observable.<String>empty());
}

@RequestMapping(method = RequestMethod.GET, value = "/single")
public ObservableDeferredResult<String> single() {
return new ObservableDeferredResult<String>(Observable.just("single value"));
Expand Down Expand Up @@ -105,6 +110,18 @@ public String call(Long aLong) {
}
}

@Test
public void shouldRetrieveEmptyResponse() {

// when
ResponseEntity<List> response = restTemplate.getForEntity(path("/empty"), List.class);

// then
assertNotNull(response);
assertEquals(HttpStatus.OK, response.getStatusCode());
assertEquals(Collections.emptyList(), response.getBody());
}

@Test
public void shouldRetrieveSingleValue() {

Expand Down Expand Up @@ -168,4 +185,4 @@ public void shouldTimeoutOnConnection() {
private String path(String context) {
return String.format("http://localhost:%d%s", port, context);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ public class ObservableReturnValueHandlerTest {
@RestController
protected static class Application {

@RequestMapping(method = RequestMethod.GET, value = "/empty")
public Observable<Void> empty() {
return Observable.empty();
}

@RequestMapping(method = RequestMethod.GET, value = "/single")
public Observable<String> single() {
return Observable.just("single value");
Expand All @@ -90,6 +95,18 @@ public String call(Long aLong) {
}
}

@Test
public void shouldRetrieveEmptyResponse() {

// when
ResponseEntity<List> response = restTemplate.getForEntity(path("/empty"), List.class);

// then
assertNotNull(response);
assertEquals(HttpStatus.OK, response.getStatusCode());
assertEquals(Collections.emptyList(), response.getBody());
}

@Test
public void shouldRetrieveSingleValue() {

Expand Down Expand Up @@ -139,4 +156,4 @@ public void shouldTimeoutOnConnection() {
private String path(String context) {
return String.format("http://localhost:%d%s", port, context);
}
}
}

0 comments on commit d6d4db5

Please sign in to comment.