Search in sources :

Example 41 with Mockery

use of org.jmock.Mockery in project Internet-Software-Architectures by zivko11.

the class SeatManagerTests method ReadAllSeats_ReturnsAllSeats.

@Test
public void ReadAllSeats_ReturnsAllSeats() {
    // Arrange
    Mockery mock = new Mockery();
    seatRepository = mock.mock(SeatRepository.class);
    final ArrayList<Seat> list = new ArrayList<Seat>();
    Seat seat1 = new Seat();
    seat1.setSeatModified(new Date());
    seat1.setSeatTaken(true);
    Seat seat2 = new Seat();
    seat2.setSeatModified(new Date());
    seat2.setSeatTaken(false);
    list.add(seat1);
    list.add(seat2);
    mock.checking(new Expectations() {

        {
            oneOf(seatRepository).findAll();
            will(returnValue(list));
        }
    });
    SeatManager manager = new SeatManager(seatRepository);
    // Act
    ArrayList<SeatDTO> listDTO = manager.ReadAll();
    // Assert
    Assert.assertNotNull(listDTO);
    Assert.assertEquals(listDTO.get(0).getSeatId(), list.get(0).getSeatId());
    Assert.assertEquals(listDTO.get(0).getSeatModified(), list.get(0).getSeatModified());
    Assert.assertEquals(listDTO.get(0).isSeatTaken(), list.get(0).isSeatTaken());
    Assert.assertEquals(listDTO.get(1).getSeatId(), list.get(1).getSeatId());
    Assert.assertEquals(listDTO.get(1).getSeatModified(), list.get(1).getSeatModified());
    Assert.assertEquals(listDTO.get(1).isSeatTaken(), list.get(1).isSeatTaken());
    mock.assertIsSatisfied();
}
Also used : Expectations(org.jmock.Expectations) SeatDTO(com.management.dto.SeatDTO) Seat(com.management.entities.Seat) ArrayList(java.util.ArrayList) SeatRepository(com.management.repositories.SeatRepository) Mockery(org.jmock.Mockery) Date(java.util.Date) Test(org.junit.Test)

Example 42 with Mockery

use of org.jmock.Mockery in project Internet-Software-Architectures by zivko11.

the class UserManagerTest method DeletingUser_ReturnsBoolean.

@Test
public void DeletingUser_ReturnsBoolean() {
    // Arrange
    Mockery mock = new Mockery();
    userRepository = mock.mock(UserRepository.class);
    // expectations
    mock.checking(new Expectations() {

        {
            oneOf(userRepository).delete(1);
        }
    });
    // Act and assert
    UserManager manager = new UserManager(userRepository);
    Assert.assertNotNull(manager);
    Assert.assertTrue(manager.Delete(1));
    mock.assertIsSatisfied();
}
Also used : Expectations(org.jmock.Expectations) UserRepository(com.management.repositories.UserRepository) Mockery(org.jmock.Mockery) Test(org.junit.Test)

Example 43 with Mockery

use of org.jmock.Mockery in project Internet-Software-Architectures by zivko11.

the class UserManagerTest method ReadAllUsers_ReturnsAllUsers.

@Test
public void ReadAllUsers_ReturnsAllUsers() {
    // Arrange
    Mockery mock = new Mockery();
    userRepository = mock.mock(UserRepository.class);
    final ArrayList<User> list = new ArrayList<User>();
    User user1 = new User();
    user1.setUserId(1);
    user1.setUserActive(true);
    user1.setUserName("Pero");
    user1.setUserSurname("Peric");
    user1.setUserAdmin('O');
    user1.setUserCity("Novi Sad");
    user1.setUserCreationDate(new Date());
    user1.setUserEmail("pero@gmail.com");
    user1.setUserPassword("123");
    user1.setUserRank(0);
    user1.setUserPhone(123456);
    user1.setUserStateid("381");
    User user2 = new User();
    user2.setUserId(2);
    user2.setUserActive(false);
    user2.setUserName("Djuro");
    user2.setUserSurname("Djuric");
    user2.setUserAdmin('O');
    user2.setUserCity("Sombor");
    user2.setUserCreationDate(new Date());
    user2.setUserEmail("djuro@gmail.com");
    user2.setUserPassword("321");
    user2.setUserRank(1);
    user2.setUserPhone(654321);
    user2.setUserStateid("386");
    list.add(user1);
    list.add(user2);
    mock.checking(new Expectations() {

        {
            oneOf(userRepository).findAll();
            will(returnValue(list));
        }
    });
    UserManager manager = new UserManager(userRepository);
    // Act
    ArrayList<UserDTO> listDTO = manager.ReadAll();
    // Assert
    Assert.assertNotNull(listDTO);
    Assert.assertEquals(listDTO.get(0).getUserCity(), list.get(0).getUserCity());
    Assert.assertEquals(listDTO.get(0).getUserAdmin(), list.get(0).getUserAdmin());
    Assert.assertEquals(listDTO.get(0).getUserRank(), list.get(0).getUserRank());
    Assert.assertEquals(listDTO.get(0).getUserCity(), list.get(0).getUserCity());
    Assert.assertEquals(listDTO.get(0).getUserEmail(), list.get(0).getUserEmail());
    Assert.assertEquals(listDTO.get(0).getUserName(), list.get(0).getUserName());
    Assert.assertEquals(listDTO.get(0).getUserPassword(), list.get(0).getUserPassword());
    Assert.assertEquals(listDTO.get(0).getUserSurname(), list.get(0).getUserSurname());
    Assert.assertEquals(listDTO.get(0).getUserAdmin(), list.get(0).getUserAdmin());
    Assert.assertEquals(listDTO.get(0).getUserCreationDate(), list.get(0).getUserCreationDate());
    Assert.assertEquals(listDTO.get(0).getUserPhone(), list.get(0).getUserPhone());
    Assert.assertEquals(listDTO.get(0).getUserStateid(), list.get(0).getUserStateid());
    Assert.assertEquals(listDTO.get(1).getUserCity(), list.get(1).getUserCity());
    Assert.assertEquals(listDTO.get(1).getUserAdmin(), list.get(1).getUserAdmin());
    Assert.assertEquals(listDTO.get(1).getUserRank(), list.get(1).getUserRank());
    Assert.assertEquals(listDTO.get(1).getUserCity(), list.get(1).getUserCity());
    Assert.assertEquals(listDTO.get(1).getUserEmail(), list.get(1).getUserEmail());
    Assert.assertEquals(listDTO.get(1).getUserName(), list.get(1).getUserName());
    Assert.assertEquals(listDTO.get(1).getUserPassword(), list.get(1).getUserPassword());
    Assert.assertEquals(listDTO.get(1).getUserSurname(), list.get(1).getUserSurname());
    Assert.assertEquals(listDTO.get(1).getUserAdmin(), list.get(1).getUserAdmin());
    Assert.assertEquals(listDTO.get(1).getUserCreationDate(), list.get(1).getUserCreationDate());
    Assert.assertEquals(listDTO.get(1).getUserPhone(), list.get(1).getUserPhone());
    Assert.assertEquals(listDTO.get(1).getUserStateid(), list.get(1).getUserStateid());
    mock.assertIsSatisfied();
}
Also used : Expectations(org.jmock.Expectations) UserRepository(com.management.repositories.UserRepository) User(com.management.entities.User) UserDTO(com.management.dto.UserDTO) ArrayList(java.util.ArrayList) Mockery(org.jmock.Mockery) Date(java.util.Date) Test(org.junit.Test)

Example 44 with Mockery

use of org.jmock.Mockery in project Internet-Software-Architectures by zivko11.

the class SeatControllerTests method ReadAllSeats_ReturnsOK.

@Test
public void ReadAllSeats_ReturnsOK() {
    // Arrange
    Mockery mock = new Mockery();
    seatRepository = mock.mock(SeatRepository.class);
    final ArrayList<Seat> list = new ArrayList<Seat>();
    Seat seat1 = new Seat();
    seat1.setSeatModified(new Date());
    seat1.setSeatTaken(true);
    Seat seat2 = new Seat();
    seat2.setSeatModified(new Date());
    seat2.setSeatTaken(false);
    list.add(seat1);
    list.add(seat2);
    mock.checking(new Expectations() {

        {
            oneOf(seatRepository).findAll();
            will(returnValue(list));
        }
    });
    SeatManager manager = new SeatManager(seatRepository);
    SeatController controller = new SeatController(manager);
    // Act
    ResponseEntity<List<SeatDTO>> response = controller.getSeats();
    ArrayList<SeatDTO> listDTO = (ArrayList<SeatDTO>) response.getBody();
    // Assert
    Assert.assertNotNull(controller);
    Assert.assertEquals(response, new ResponseEntity<List<SeatDTO>>(listDTO, HttpStatus.OK));
    mock.assertIsSatisfied();
}
Also used : Expectations(org.jmock.Expectations) Seat(com.management.entities.Seat) ArrayList(java.util.ArrayList) SeatRepository(com.management.repositories.SeatRepository) Mockery(org.jmock.Mockery) Date(java.util.Date) SeatDTO(com.management.dto.SeatDTO) ArrayList(java.util.ArrayList) List(java.util.List) SeatManager(com.management.managers.SeatManager) Test(org.junit.Test)

Example 45 with Mockery

use of org.jmock.Mockery in project Internet-Software-Architectures by zivko11.

the class UserControllerTests method DeletingUser_ReturnsOK.

@Test
public void DeletingUser_ReturnsOK() {
    // Arrange
    Mockery mock = new Mockery();
    userRepository = mock.mock(UserRepository.class);
    // expectations
    mock.checking(new Expectations() {

        {
            oneOf(userRepository).delete(1);
        }
    });
    // Act and assert
    UserManager manager = new UserManager(userRepository);
    UserController controller = new UserController(manager);
    Assert.assertNotNull(controller);
    Assert.assertEquals(controller.deleteUser(1), new ResponseEntity<UserDTO>(HttpStatus.OK));
    mock.assertIsSatisfied();
}
Also used : Expectations(org.jmock.Expectations) UserRepository(com.management.repositories.UserRepository) UserManager(com.management.managers.UserManager) UserDTO(com.management.dto.UserDTO) Mockery(org.jmock.Mockery) Test(org.junit.Test)

Aggregations

Mockery (org.jmock.Mockery)148 Expectations (org.jmock.Expectations)118 Test (org.junit.Test)77 Before (org.junit.Before)28 ArrayList (java.util.ArrayList)24 Date (java.util.Date)21 JUnit4Mockery (org.jmock.integration.junit4.JUnit4Mockery)17 File (java.io.File)15 BeforeMethod (org.testng.annotations.BeforeMethod)15 Synchroniser (org.jmock.lib.concurrent.Synchroniser)14 List (java.util.List)11 ActorDTO (com.management.dto.ActorDTO)7 FanZoneDTO (com.management.dto.FanZoneDTO)6 PropsDTO (com.management.dto.PropsDTO)6 ActorPerformancesRepository (com.management.repositories.ActorPerformancesRepository)6 ActorRepository (com.management.repositories.ActorRepository)6 CinemaTheatreRepository (com.management.repositories.CinemaTheatreRepository)6 EventRepository (com.management.repositories.EventRepository)6 FriendsListRepository (com.management.repositories.FriendsListRepository)6 PerformanceRepository (com.management.repositories.PerformanceRepository)6