Search in sources :

Example 6 with EventRepository

use of com.management.repositories.EventRepository in project Internet-Software-Architectures by zivko11.

the class EventControllerTests method ReadAllEvents_ReturnsOK.

@Test
public void ReadAllEvents_ReturnsOK() {
    // Arrange
    Mockery mock = new Mockery();
    eventRepository = mock.mock(EventRepository.class);
    final ArrayList<Event> list = new ArrayList<Event>();
    Event event1 = new Event();
    event1.setEventDate(new Date());
    Event event2 = new Event();
    event2.setEventDate(new Date());
    list.add(event1);
    list.add(event2);
    mock.checking(new Expectations() {

        {
            oneOf(eventRepository).findAll();
            will(returnValue(list));
        }
    });
    EventManager manager = new EventManager(eventRepository);
    EventController controller = new EventController(manager);
    // Act
    ResponseEntity<List<EventDTO>> response = controller.getEvents();
    ArrayList<EventDTO> listDTO = (ArrayList<EventDTO>) response.getBody();
    // Assert
    Assert.assertNotNull(controller);
    Assert.assertEquals(response, new ResponseEntity<List<EventDTO>>(listDTO, HttpStatus.OK));
    mock.assertIsSatisfied();
}
Also used : Expectations(org.jmock.Expectations) EventManager(com.management.managers.EventManager) ArrayList(java.util.ArrayList) EventDTO(com.management.dto.EventDTO) Mockery(org.jmock.Mockery) Date(java.util.Date) Event(com.management.entities.Event) EventRepository(com.management.repositories.EventRepository) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Aggregations

EventRepository (com.management.repositories.EventRepository)6 Expectations (org.jmock.Expectations)6 Mockery (org.jmock.Mockery)6 Test (org.junit.Test)6 EventDTO (com.management.dto.EventDTO)5 Event (com.management.entities.Event)4 Date (java.util.Date)4 EventManager (com.management.managers.EventManager)3 ArrayList (java.util.ArrayList)2 List (java.util.List)1