Skip to content

Commit

Permalink
#80
Browse files Browse the repository at this point in the history
  • Loading branch information
justinhrobbins committed Jan 11, 2014
1 parent 4489bfd commit 1efe552
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

public class HibernateFieldMapper implements CustomFieldMapper {

/**
* If false is returned from the call to mapField(), then the field will be subsequently mapped by Dozer as normal.
*/
public boolean mapField(Object source, Object destination, Object sourceFieldValue, ClassMap classMap, FieldMap fieldMapping)
{
// Check if field is a Hibernate PersistentSet
Expand All @@ -21,8 +24,7 @@ public boolean mapField(Object source, Object destination, Object sourceFieldVal
return false;
}

// Set destination to null, and tell dozer that the field is mapped
destination = null;
// tell dozer that the field is mapped
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.springframework.test.util.ReflectionTestUtils;

@Category(UnitTest.class)
public class HibernateFieldMapperUT extends BaseMockingTest {
public class FieldInitializerUtilUT extends BaseMockingTest {

@Mock
private EntityManagerFactory mockEntityManagerFactory;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.robbins.flashcards.service.util.dozer;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

import org.hibernate.collection.internal.PersistentSet;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.robbins.flashcards.dto.TagDto;
import org.robbins.tests.BaseMockingTest;

public class HibernateFieldMapperUT extends BaseMockingTest {
private HibernateFieldMapper hibernateFieldMapper;

@Mock
private TagDto mockTagDto;

@Mock
private PersistentSet mockPersistentSet;

@Before
public void before() {
hibernateFieldMapper = new HibernateFieldMapper();
}

@Test
public void mapField_NotPersistentSet() {

boolean result = hibernateFieldMapper.mapField(null, null, new String("test"), null, null);

assertThat(result, is(false));
}

@Test
public void mapField_PersistentSetNotInitialized() {
Set<TagDto> mockTagDtos = new HashSet<TagDto>(Arrays.asList(mockTagDto));
PersistentSet persistentSet = new PersistentSet(null, mockTagDtos);

boolean result = hibernateFieldMapper.mapField(null, null, persistentSet, null, null);

assertThat(result, is(false));
}
}

0 comments on commit 1efe552

Please sign in to comment.