/*
 * Copyright (C) by Courtanet, All Rights Reserved.
 */
package org.modelmap.example;

import org.junit.Test;
import org.mockito.Mockito;
import org.modelmap.core.FieldModel;
import org.modelmap.sample.field.SampleFieldId;
import org.modelmap.sample.model.*;

public class MockDomainModelTest {

    @Test
    public void mockJavaBean() {
        SampleModel model = new SampleModel();

        Account account = new Account();
        account.setEmail("foo@bar.com");
        model.setAccount(account);

        User user = new User();
        user.setLastName("foo");
        user.setFirstName("bar");
        model.setUser(user);

        // ... do some testing
    }

    @Test
    public void mockWithMockito() {
        /*
         * This feature will not work when any return type of methods included in the chain cannot be mocked
         * (for example: is a primitive or a final class). This is because of java type system.
         */
        final SampleModel model = Mockito.mock(SampleModel.class, Mockito.RETURNS_DEEP_STUBS);

        Mockito.when(model.getAccount().getEmail()).thenReturn("foo@bar.com");
        Mockito.when(model.getUser().getFirstName()).thenReturn("foo");
        Mockito.when(model.getUser().getLastName()).thenReturn("bar");

        // ... do some testing
    }

    @Test
    public void mockWithModelMap() {
        FieldModel model = new SampleModelWrapper(new SampleModel());

        model.set(SampleFieldId.EMAIL, "foo@bar.com");
        model.set(SampleFieldId.LAST_NAME, "foo");
        model.set(SampleFieldId.FIRST_NAME, "bar");

        // ... do some testing
    }
}



@@ -83,16 +83,56 @@
 ample;%0A%0A
+import org.assertj.core.api.Assertions;%0A
 import o
@@ -696,32 +696,148 @@
 some testing
+%0A%0A        FieldModel fieldModel = new SampleModelWrapper(model);%0A        should_contains_name_and_email(fieldModel);
 %0A    %7D%0A%0A
     @Test%0A  
@@ -816,32 +816,33 @@
 dModel);%0A    %7D%0A%0A
+%0A
     @Test%0A    pu
@@ -1314,19 +1314,18 @@
 er().get
-Fir
+La
 stName()
@@ -1377,34 +1377,35 @@
 el.getUser().get
-La
+Fir
 stName()).thenRe
@@ -1444,24 +1444,140 @@
 some testing
+%0A%0A        FieldModel fieldModel = new SampleModelWrapper(model);%0A        should_contains_name_and_email(fieldModel);
 %0A    %7D%0A%0A    
@@ -1634,25 +1634,30 @@
  FieldModel 
-m
+fieldM
 odel = new S
@@ -1695,33 +1695,38 @@
 el());%0A%0A        
-m
+fieldM
 odel.set(SampleF
@@ -1755,33 +1755,38 @@
 .com%22);%0A        
-m
+fieldM
 odel.set(SampleF
@@ -1811,33 +1811,38 @@
 %22foo%22);%0A        
-m
+fieldM
 odel.set(SampleF
@@ -1899,16 +1899,448 @@
  testing
+%0A%0A        should_contains_name_and_email(fieldModel);%0A    %7D%0A%0A    private void should_contains_name_and_email(FieldModel fieldModel) %7B%0A        Assertions.assertThat(fieldModel.%3CString%3E get(SampleFieldId.EMAIL)).isEqualTo(%22foo@bar.com%22);%0A        Assertions.assertThat(fieldModel.%3CString%3E get(SampleFieldId.LAST_NAME)).isEqualTo(%22foo%22);%0A        Assertions.assertThat(fieldModel.%3CString%3E get(SampleFieldId.FIRST_NAME)).isEqualTo(%22bar%22);
 %0A    %7D%0A%7D

complete test