@@ -0,0 +1,3160 @@
+package se.kits.gakusei.controller;%0A%0Aimport static org.junit.Assert.*;%0Aimport static org.mockito.Matchers.any;%0A%0Aimport static org.mockito.Mockito.*;%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0Aimport org.junit.runner.RunWith;%0Aimport org.mockito.InjectMocks;%0Aimport org.mockito.Mock;%0Aimport org.mockito.MockitoAnnotations;%0Aimport org.mockito.runners.MockitoJUnitRunner;%0Aimport org.springframework.http.ResponseEntity;%0Aimport se.kits.gakusei.dto.EventDTO;%0Aimport se.kits.gakusei.user.model.Event;%0Aimport se.kits.gakusei.user.model.User;%0Aimport se.kits.gakusei.user.repository.EventRepository;%0Aimport se.kits.gakusei.user.repository.UserRepository;%0A%0Aimport java.sql.Timestamp;%0A%0A@RunWith(MockitoJUnitRunner.class)%0Apublic class EventControllerTest %7B%0A%0A    @InjectMocks%0A    private EventController eventController;%0A%0A    @Mock%0A    private EventRepository eventRepository;%0A%0A    @Mock%0A    private UserRepository userRepository;%0A%0A    private EventDTO eventDTO;%0A    private Event event;%0A    private String username;%0A    private String password;%0A    private String role;%0A    private String gamemode;%0A    private String type;%0A    private String data;%0A    private long timestamp;%0A    private User user;%0A%0A    @Before%0A    public void setUp() throws Exception%7B%0A        eventController = new EventController();%0A        MockitoAnnotations.initMocks(this);%0A%0A        username = %22testname%22;%0A        password = %22testpassword%22;%0A        role = %22testrole%22;%0A%0A        gamemode = %22testmode%22;%0A        type = %22testtype%22;%0A        data = %22testdata%22;%0A        timestamp = 1485267234671L;%0A        user = new User(username, password, role);%0A%0A        eventDTO = new EventDTO();%0A        eventDTO.setUsername(username);%0A        eventDTO.setGamemode(gamemode);%0A        eventDTO.setType(type);%0A        eventDTO.setData(data);%0A        eventDTO.setTimestamp(timestamp);%0A    %7D%0A%0A    public Event createEvent(long timestamp, User user, String gamemode, String type, String data)%7B%0A        Event event = new Event();%0A        event.setTimestamp(new Timestamp(timestamp));%0A        event.setUser(user);%0A        event.setGamemode(gamemode);%0A        event.setType(type);%0A        event.setData(data);%0A        return event;%0A    %7D%0A%0A    @Test%0A    public void testAddEventOK() throws Exception%7B%0A%0A        Event event = createEvent(timestamp, user, gamemode, type, data);%0A        when(userRepository.findByUsername(eventDTO.getUsername())).thenReturn(user);%0A        when(eventRepository.save(any(Event.class))).thenReturn(event);%0A%0A        ResponseEntity%3CEvent%3E re = eventController.addEvent(eventDTO);%0A%0A        assertEquals(timestamp, re.getBody().getTimestamp().getTime());%0A        assertEquals(user, re.getBody().getUser());%0A        assertEquals(gamemode, re.getBody().getGamemode());%0A        assertEquals(type, re.getBody().getType());%0A        assertEquals(data, re.getBody().getData());%0A        assertEquals(200, re.getStatusCodeValue());%0A    %7D%0A%0A    @Test%0A    public void testAddEventNoUser() throws Exception%7B%0A        when(userRepository.findByUsername(username)).thenReturn(null);%0A        ResponseEntity%3CEvent%3E re = eventController.addEvent(eventDTO);%0A        assertEquals(204, re.getStatusCodeValue());%0A    %7D%0A%7D%0A

add addEvent test