Skip to content

Commit 753b309

Browse files
vicmosinVictor Mosin
authored andcommitted
Added ConverterFactory test
1 parent 89f9f8c commit 753b309

3 files changed

Lines changed: 22 additions & 0 deletions

File tree

‎spring-boot/src/main/java/org/baeldung/controller/GenericEntityController.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.baeldung.controller;
22

33
import org.baeldung.domain.GenericEntity;
4+
import org.baeldung.domain.Modes;
45
import org.baeldung.web.resolver.Version;
56
import org.springframework.http.HttpStatus;
67
import org.springframework.http.ResponseEntity;
@@ -45,6 +46,11 @@ public GenericEntity findByDate(@PathVariable("date") LocalDateTime date) {
4546
return entityList.stream().findFirst().get();
4647
}
4748

49+
@RequestMapping("/entity/findbymode/{mode}")
50+
public GenericEntity findByEnum(@PathVariable("mode") Modes mode) {
51+
return entityList.stream().findFirst().get();
52+
}
53+
4854
@RequestMapping("/entity/findbyversion")
4955
public ResponseEntity findByVersion(@Version String version) {
5056
return version != null
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package org.baeldung.domain;
2+
3+
public enum Modes {
4+
5+
Alpha, Beta;
6+
}

‎spring-boot/src/test/java/org/baeldung/SpringBootApplicationIntegrationTest.java‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ public void givenRequestHasBeenMade_whenMeetsFindByDateOfGivenConditions_thenCor
5050
.andExpect(jsonPath("$.id", equalTo(1)));
5151
}
5252

53+
@Test
54+
public void givenRequestHasBeenMade_whenMeetsFindByModeOfGivenConditions_thenCorrect() throws Exception {
55+
MediaType contentType = new MediaType(MediaType.APPLICATION_JSON.getType(), MediaType.APPLICATION_JSON.getSubtype(), Charset.forName("utf8"));
56+
57+
mockMvc.perform(MockMvcRequestBuilders.get("/entity/findbymode/{mode}", "Alpha"))
58+
.andExpect(MockMvcResultMatchers.status().isOk())
59+
.andExpect(MockMvcResultMatchers.content().contentType(contentType))
60+
.andExpect(jsonPath("$.id", equalTo(1)));
61+
}
62+
5363
@Test
5464
public void givenRequestHasBeenMade_whenMeetsFindByVersionOfGivenConditions_thenCorrect() throws Exception {
5565
MediaType contentType = new MediaType(MediaType.APPLICATION_JSON.getType(), MediaType.APPLICATION_JSON.getSubtype(), Charset.forName("utf8"));

0 commit comments

Comments
 (0)