Search in sources :

Example 6 with PropsRepository

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

the class PropsManagerTests method ReadProps_ReturnsProps.

@Test
public void ReadProps_ReturnsProps() throws IOException {
    // Arrange
    Mockery mock = new Mockery();
    propsRepository = mock.mock(PropsRepository.class);
    final Props props = new Props();
    props.setPropsDeadline(new Date());
    props.setPropsDesc("Spoderman props description");
    props.setPropsName("Spoderman props");
    props.setPropsPrice(300);
    props.setPropsModified(new Date());
    props.setPropsUsed(true);
    String filePath = "C:\\Users\\Nikola\\Desktop\\test.png";
    byte[] byteArray;
    byteArray = ((DataBufferByte) ImageIO.read(new File(filePath)).getData().getDataBuffer()).getData();
    props.setPropsImage(byteArray);
    mock.checking(new Expectations() {

        {
            oneOf(propsRepository).findOne(1);
            will(returnValue(props));
        }
    });
    PropsManager manager = new PropsManager(propsRepository);
    // Act
    PropsDTO dto = manager.Read(1);
    // Assert
    Assert.assertNotNull(dto);
    Assert.assertEquals(dto.getPropsId(), props.getPropsId());
    Assert.assertEquals(dto.getPropsName(), props.getPropsName());
    Assert.assertEquals(dto.getPropsPrice(), props.getPropsPrice(), 0.1);
    Assert.assertEquals(dto.getPropsDeadline(), props.getPropsDeadline());
    Assert.assertEquals(dto.getPropsModified(), props.getPropsModified());
    Assert.assertEquals(dto.getPropsDesc(), props.getPropsDesc());
    Assert.assertArrayEquals(dto.getPropsImage(), props.getPropsImage());
    Assert.assertEquals(dto.isPropsUsed(), props.isPropsUsed());
    mock.assertIsSatisfied();
}
Also used : Expectations(org.jmock.Expectations) PropsDTO(com.management.dto.PropsDTO) PropsRepository(com.management.repositories.PropsRepository) Props(com.management.entities.Props) Mockery(org.jmock.Mockery) File(java.io.File) Date(java.util.Date) Test(org.junit.Test)

Aggregations

PropsRepository (com.management.repositories.PropsRepository)6 Expectations (org.jmock.Expectations)6 Mockery (org.jmock.Mockery)6 Test (org.junit.Test)6 PropsDTO (com.management.dto.PropsDTO)5 Props (com.management.entities.Props)4 File (java.io.File)4 Date (java.util.Date)4 PropsManager (com.management.managers.PropsManager)3 DataBufferByte (java.awt.image.DataBufferByte)3 ArrayList (java.util.ArrayList)2 List (java.util.List)1