package pl.openrest.dto.mappers.generator;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;

@RunWith(MockitoJUnitRunner.class)
public class MappedFieldPairTest {

    @Mock
    private MappedFieldInformation dtoFieldInfo;
    @Mock
    private MappedFieldInformation entityFieldInfo;

    @Test(expected = IllegalArgumentException.class)
    public void shouldConstructorThrowExceptionOnNonMatchingDtoAndEntityFieldTypesIfNonNestedDto() throws Exception {
        // given
        Mockito.doReturn(Object.class).when(dtoFieldInfo).getType();
        Mockito.doReturn(Long.class).when(entityFieldInfo).getType();
        Mockito.when(dtoFieldInfo.isDto()).thenReturn(false);
        // when
        new MappedFieldPair(dtoFieldInfo, entityFieldInfo);
        // then
    }

    @Test(expected = IllegalArgumentException.class)
    public void shouldConstructorThrowExceptionOnNonMatchingDtoAndEntityFieldTypesIfNestedDtoHasEntityTypeDifferentThanEntityFieldType()
            throws Exception {
        // given
        Mockito.doReturn(Object.class).when(dtoFieldInfo).getType();
        Mockito.doReturn(Long.class).when(entityFieldInfo).getType();
        Mockito.when(dtoFieldInfo.isDto()).thenReturn(true);
        Mockito.doReturn(Long.class).when(dtoFieldInfo).getEntityType();
        // when
        new MappedFieldPair(dtoFieldInfo, entityFieldInfo);
        // then
    }

}

@@ -52,18 +52,138 @@
 org.
-junit.Test
+hamcrest.Matchers;%0Aimport org.junit.Before;%0Aimport org.junit.Rule;%0Aimport org.junit.Test;%0Aimport org.junit.rules.ExpectedException
 ;%0Aim
@@ -516,55 +516,867 @@
    @
-Test(expected = IllegalArgumentException.class)
+Rule%0A    public ExpectedException thrown = ExpectedException.none();%0A%0A    @Before%0A    public void setUp() %7B%0A        Mockito.doReturn(Object.class).when(dtoFieldInfo).getType();%0A        Mockito.doReturn(Object.class).when(entityFieldInfo).getType();%0A%0A        Mockito.doReturn(Long.class).when(dtoFieldInfo).getDeclaringClass();%0A        Mockito.doReturn(Integer.class).when(entityFieldInfo).getDeclaringClass();%0A%0A        Mockito.when(dtoFieldInfo.getGetterName()).thenReturn(%22getName%22);%0A        Mockito.when(entityFieldInfo.getSetterName()).thenReturn(%22setName%22);%0A%0A        Mockito.when(dtoFieldInfo.getName()).thenReturn(%22name%22);%0A        Mockito.when(entityFieldInfo.getName()).thenReturn(%22name%22);%0A%0A        Mockito.when(dtoFieldInfo.toString()).thenReturn(%22dtoField%22);%0A        Mockito.when(entityFieldInfo.toString()).thenReturn(%22entityField%22);%0A    %7D%0A%0A    @Test
 %0A   
@@ -1707,16 +1707,202 @@
 (false);
+%0A%0A        thrown.expect(IllegalArgumentException.class);%0A        thrown.expectMessage(Matchers.equalTo(%22Type of dto field dtoField does not match the type of entity field entityField%22));
 %0A       
@@ -2006,51 +2006,8 @@
 Test
-(expected = IllegalArgumentException.class)
 %0A   
@@ -2388,16 +2388,16 @@
 (true);%0A
-
         
@@ -2456,24 +2456,210 @@
 ntityType();
+%0A%0A        thrown.expect(IllegalArgumentException.class);%0A        thrown.expectMessage(Matchers.equalTo(%22Type of dto field dtoField does not match the type of entity field entityField%22));
 %0A        // 

Add setUp method and change way of verifing exceptions in MappedFieldPairTest