Skip to content

Commit 729c899

Browse files
authored
Merge pull request eugenp#977 from vicmosin/master
BAEL-529 - Applied latest changes
2 parents 55113dd + 0282609 commit 729c899

4 files changed

Lines changed: 8 additions & 11 deletions

File tree

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.baeldung.web.resolver.Version;
66
import org.springframework.http.HttpStatus;
77
import org.springframework.http.ResponseEntity;
8+
import org.springframework.web.bind.annotation.GetMapping;
89
import org.springframework.web.bind.annotation.PathVariable;
910
import org.springframework.web.bind.annotation.RequestMapping;
1011
import org.springframework.web.bind.annotation.RequestMethod;
@@ -41,17 +42,17 @@ public GenericEntity findById(@PathVariable Long id) {
4142
return entityList.stream().filter(entity -> entity.getId().equals(id)).findFirst().get();
4243
}
4344

44-
@RequestMapping("/entity/findbydate/{date}")
45+
@GetMapping("/entity/findbydate/{date}")
4546
public GenericEntity findByDate(@PathVariable("date") LocalDateTime date) {
4647
return entityList.stream().findFirst().get();
4748
}
4849

49-
@RequestMapping("/entity/findbymode/{mode}")
50+
@GetMapping("/entity/findbymode/{mode}")
5051
public GenericEntity findByEnum(@PathVariable("mode") Modes mode) {
5152
return entityList.stream().findFirst().get();
5253
}
5354

54-
@RequestMapping("/entity/findbyversion")
55+
@GetMapping("/entity/findbyversion")
5556
public ResponseEntity findByVersion(@Version String version) {
5657
return version != null
5758
? new ResponseEntity(entityList.stream().findFirst().get(), HttpStatus.OK)

‎spring-boot/src/main/java/org/baeldung/converter/StringToLocalDateTimeConverter.java‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,12 @@
55

66
import java.time.LocalDateTime;
77
import java.time.format.DateTimeFormatter;
8-
import java.time.format.DateTimeParseException;
98

109
@Component
1110
public class StringToLocalDateTimeConverter implements Converter<String, LocalDateTime> {
1211

1312
@Override
1413
public LocalDateTime convert(final String source) {
15-
try {
16-
return LocalDateTime.parse(source, DateTimeFormatter.ISO_LOCAL_DATE_TIME);
17-
} catch (DateTimeParseException e) {
18-
throw new IllegalArgumentException("Couldn't parse value");
19-
}
14+
return LocalDateTime.parse(source, DateTimeFormatter.ISO_LOCAL_DATE_TIME);
2015
}
2116
}

‎spring-boot/src/main/java/org/baeldung/domain/Modes.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
public enum Modes {
44

5-
Alpha, Beta;
5+
ALPHA, BETA;
66
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import static org.hamcrest.Matchers.hasSize;
55
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
66

7+
import org.baeldung.domain.Modes;
78
import org.junit.Before;
89
import org.junit.Test;
910
import org.junit.runner.RunWith;
@@ -54,7 +55,7 @@ public void givenRequestHasBeenMade_whenMeetsFindByDateOfGivenConditions_thenCor
5455
public void givenRequestHasBeenMade_whenMeetsFindByModeOfGivenConditions_thenCorrect() throws Exception {
5556
MediaType contentType = new MediaType(MediaType.APPLICATION_JSON.getType(), MediaType.APPLICATION_JSON.getSubtype(), Charset.forName("utf8"));
5657

57-
mockMvc.perform(MockMvcRequestBuilders.get("/entity/findbymode/{mode}", "Alpha"))
58+
mockMvc.perform(MockMvcRequestBuilders.get("/entity/findbymode/{mode}", Modes.ALPHA.name()))
5859
.andExpect(MockMvcResultMatchers.status().isOk())
5960
.andExpect(MockMvcResultMatchers.content().contentType(contentType))
6061
.andExpect(jsonPath("$.id", equalTo(1)));

0 commit comments

Comments
 (0)