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();
}
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();
}
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();
}
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();
}
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();
}
Aggregations