Search in sources :

Example 36 with Mockery

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

the class PerformanceManagerTests method DeletingPerformance_ReturnsBoolean.

@Test
public void DeletingPerformance_ReturnsBoolean() {
    // Arrange
    Mockery mock = new Mockery();
    performanceRepository = mock.mock(PerformanceRepository.class);
    // expectations
    mock.checking(new Expectations() {

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

Example 37 with Mockery

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

the class PerformanceManagerTests method ReadPerformance_ReturnsPerformance.

@Test
public void ReadPerformance_ReturnsPerformance() {
    // Arrange
    Mockery mock = new Mockery();
    performanceRepository = mock.mock(PerformanceRepository.class);
    final Performance per = new Performance();
    per.setPerCreationDate(new Date());
    per.setPerDescription("Neki opis.");
    per.setPerDirector("Nikola Stojanovic");
    per.setPerDuration(11);
    per.setPerGenre("Komedija");
    per.setPerPoster(new byte[] { 121 });
    per.setPerPrice(100);
    per.setPerRank(0);
    per.setPerType('M');
    mock.checking(new Expectations() {

        {
            oneOf(performanceRepository).findOne(1);
            will(returnValue(per));
        }
    });
    PerformanceManager manager = new PerformanceManager(performanceRepository);
    // Act
    PerformanceDTO dto = manager.Read(1);
    // Assert
    Assert.assertNotNull(dto);
    Assert.assertEquals(dto.getPerId(), per.getPerId());
    Assert.assertEquals(per.getPerDescription(), dto.getPerDescription());
    Assert.assertEquals(per.getPerDirector(), dto.getPerDirector());
    Assert.assertEquals(per.getPerDuration(), dto.getPerDuration());
    Assert.assertEquals(per.getPerGenre(), dto.getPerGenre());
    Assert.assertEquals((int) per.getPerPrice(), (int) dto.getPerPrice());
    Assert.assertEquals(per.getPerRank(), dto.getPerRank());
    Assert.assertEquals(per.getPerType(), dto.getPerType());
    mock.assertIsSatisfied();
}
Also used : PerformanceRepository(com.management.repositories.PerformanceRepository) Expectations(org.jmock.Expectations) Performance(com.management.entities.Performance) Mockery(org.jmock.Mockery) Date(java.util.Date) PerformanceDTO(com.management.dto.PerformanceDTO) Test(org.junit.Test)

Example 38 with Mockery

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

the class PropsManagerTests method DeletingProps_ReturnsBoolean.

@Test
public void DeletingProps_ReturnsBoolean() {
    // Arrange
    Mockery mock = new Mockery();
    propsRepository = mock.mock(PropsRepository.class);
    // Expectations
    mock.checking(new Expectations() {

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

Example 39 with Mockery

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

the class PropsManagerTests method ReadAllProps_ReturnsAllProps.

@Test
public void ReadAllProps_ReturnsAllProps() throws IOException {
    // Arrange
    Mockery mock = new Mockery();
    propsRepository = mock.mock(PropsRepository.class);
    final ArrayList<Props> list = new ArrayList<Props>();
    Props p1 = new Props();
    p1.setPropsDeadline(new Date());
    p1.setPropsDesc("Spoderman props");
    p1.setPropsName("Spoderman suit");
    p1.setPropsPrice(300);
    p1.setPropsModified(new Date());
    p1.setPropsUsed(true);
    byte[] propsImage = ((DataBufferByte) ImageIO.read(new File("C:\\Users\\Nikola\\Desktop\\test.png")).getData().getDataBuffer()).getData();
    p1.setPropsImage(propsImage);
    Props p2 = new Props();
    p2.setPropsDeadline(new Date());
    p2.setPropsDesc("Captain Murica props");
    p2.setPropsName("Captain Murica suit");
    p2.setPropsPrice(500);
    p2.setPropsModified(new Date());
    p2.setPropsUsed(false);
    byte[] propsImage2 = ((DataBufferByte) ImageIO.read(new File("C:\\Users\\Nikola\\Desktop\\9cd.jpg")).getData().getDataBuffer()).getData();
    p2.setPropsImage(propsImage2);
    list.add(p1);
    list.add(p2);
    mock.checking(new Expectations() {

        {
            oneOf(propsRepository).findAll();
            will(returnValue(list));
        }
    });
    PropsManager manager = new PropsManager(propsRepository);
    // Act
    ArrayList<PropsDTO> dtoList = manager.ReadAll();
    // Assert
    Assert.assertNotNull(dtoList);
    Assert.assertEquals(dtoList.get(0).getPropsId(), list.get(0).getPropsId());
    Assert.assertEquals(dtoList.get(0).getPropsDesc(), list.get(0).getPropsDesc());
    Assert.assertEquals(dtoList.get(0).getPropsName(), list.get(0).getPropsName());
    Assert.assertEquals(dtoList.get(0).getPropsPrice(), list.get(0).getPropsPrice(), 0.1);
    Assert.assertEquals(dtoList.get(0).getPropsDeadline(), list.get(0).getPropsDeadline());
    Assert.assertEquals(dtoList.get(0).getPropsModified(), list.get(0).getPropsModified());
    Assert.assertArrayEquals(dtoList.get(0).getPropsImage(), list.get(0).getPropsImage());
    Assert.assertEquals(dtoList.get(0).isPropsUsed(), list.get(0).isPropsUsed());
    Assert.assertEquals(dtoList.get(1).getPropsId(), list.get(1).getPropsId());
    Assert.assertEquals(dtoList.get(1).getPropsDesc(), list.get(1).getPropsDesc());
    Assert.assertEquals(dtoList.get(1).getPropsName(), list.get(1).getPropsName());
    Assert.assertEquals(dtoList.get(1).getPropsPrice(), list.get(1).getPropsPrice(), 0.1);
    Assert.assertEquals(dtoList.get(1).getPropsDeadline(), list.get(1).getPropsDeadline());
    Assert.assertEquals(dtoList.get(1).getPropsModified(), list.get(1).getPropsModified());
    Assert.assertArrayEquals(dtoList.get(1).getPropsImage(), list.get(1).getPropsImage());
    Assert.assertEquals(dtoList.get(1).isPropsUsed(), list.get(1).isPropsUsed());
    mock.assertIsSatisfied();
}
Also used : Expectations(org.jmock.Expectations) PropsDTO(com.management.dto.PropsDTO) PropsRepository(com.management.repositories.PropsRepository) ArrayList(java.util.ArrayList) Props(com.management.entities.Props) DataBufferByte(java.awt.image.DataBufferByte) Mockery(org.jmock.Mockery) Date(java.util.Date) File(java.io.File) Test(org.junit.Test)

Example 40 with Mockery

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

the class SeatManagerTests method ReadSeat_ReturnsSeat.

@Test
public void ReadSeat_ReturnsSeat() {
    // Arrange
    Mockery mock = new Mockery();
    seatRepository = mock.mock(SeatRepository.class);
    final Seat seat = new Seat();
    seat.setSeatModified(new Date());
    seat.setSeatTaken(true);
    mock.checking(new Expectations() {

        {
            oneOf(seatRepository).findOne(1);
            will(returnValue(seat));
        }
    });
    SeatManager manager = new SeatManager(seatRepository);
    // Act
    SeatDTO dto = manager.Read(1);
    // Assert
    Assert.assertNotNull(dto);
    Assert.assertEquals(dto.getSeatId(), seat.getSeatId());
    Assert.assertEquals(dto.getSeatModified(), seat.getSeatModified());
    Assert.assertEquals(dto.isSeatTaken(), seat.isSeatTaken());
    mock.assertIsSatisfied();
}
Also used : Expectations(org.jmock.Expectations) SeatDTO(com.management.dto.SeatDTO) Seat(com.management.entities.Seat) SeatRepository(com.management.repositories.SeatRepository) Mockery(org.jmock.Mockery) Date(java.util.Date) 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