evainga / Timeline

0 stars 1 forks source link

build failing after pull #15

Open evainga opened 7 years ago

evainga commented 7 years ago

@mle-enso, I merged your pull request after I added my showSpecificEvent changes and didn't realize thet the master was red after that... I am trying to fix it and might not be too far away from the solution but I cant totally figure it out... Maybe we can have a look at it together tomorrow...

mle-enso commented 7 years ago

Did you compile your code before committing? I would suggest the patch below.

diff --git a/src/main/java/de/timeline/TimelineController.java b/src/main/java/de/timeline/TimelineController.java
index 1b06007..75a834d 100644
--- a/src/main/java/de/timeline/TimelineController.java
+++ b/src/main/java/de/timeline/TimelineController.java
@@ -1,6 +1,7 @@
 package de.timeline;

 import java.util.List;
+import java.util.Optional;
 import java.util.UUID;

 import javax.validation.Valid;
@@ -29,8 +30,13 @@ public class TimelineController {
        }

        @GetMapping(path = "/events/{uuid}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
-       public Event showSpecificEvent(@PathVariable UUID uuid) {
-               return timelineService.getEventByUUID(uuid);
+       public ResponseEntity<Event> showSpecificEvent(@PathVariable UUID uuid) {
+               Optional<Event> event = timelineService.getEventByUUID(uuid);
+               if (event.isPresent()) {
+                       return new ResponseEntity<>(event.get(), HttpStatus.OK);
+               } else {
+                       return new ResponseEntity<>(HttpStatus.NOT_FOUND);
+               }
        }

        @PostMapping("/events")
@@ -49,5 +55,4 @@ public class TimelineController {
                        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
                }
        }
-
 }
diff --git a/src/test/java/de/timeline/TimelineControllerTest.java b/src/test/java/de/timeline/TimelineControllerTest.java
index f78eabb..ab94d86 100644
--- a/src/test/java/de/timeline/TimelineControllerTest.java
+++ b/src/test/java/de/timeline/TimelineControllerTest.java
@@ -10,6 +10,7 @@ import static org.mockito.Mockito.when;
 import java.time.ZoneId;
 import java.time.ZonedDateTime;
 import java.util.List;
+import java.util.Optional;
 import java.util.UUID;

 import org.mockito.InjectMocks;
@@ -40,18 +41,16 @@ public class TimelineControllerTest extends MockitoTest {

        @Test
        public void showSpecificEvent() {
-
                // given
                UUID uuid = UUID.fromString("00000000-0000-0000-0000-000000000002");
-               Event christmas = new Event(uuid, "Sommeranfang",
-                               ZonedDateTime.of(2016, 6, 1, 0, 0, 0, 00, ZoneId.of("Europe/Paris")));
-               when(timelineService.getEventByUUID(uuid)).thenReturn(christmas);
+               Event christmas = new Event(uuid, "Sommeranfang", ZonedDateTime.of(2016, 6, 1, 0, 0, 0, 00, ZoneId.of("Europe/Paris")));
+               when(timelineService.getEventByUUID(uuid)).thenReturn(Optional.of(christmas));
                // when
-               Event specificEvent = timelineController.showSpecificEvent(uuid);
+               ResponseEntity<Event> specificEvent = timelineController.showSpecificEvent(uuid);

                // then
-               assertThat(specificEvent, is(christmas));
+               assertThat(specificEvent.getBody(), is(christmas));
        }

        @Test