Skip to content

Commit

Permalink
DATACMNS-203 - Re-enabled accidentally disabled unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
odrotbohm committed Jul 23, 2012
1 parent c64f014 commit f476100
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
import static org.mockito.Mockito.*;
import static org.springframework.data.convert.ReflectionEntityInstantiator.*;

import java.lang.reflect.Field;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.data.convert.ReflectionEntityInstantiatorUnitTest.Outer.Inner;
import org.springframework.data.convert.ReflectionEntityInstantiatorUnitTests.Outer.Inner;
import org.springframework.data.mapping.PersistentEntity;
import org.springframework.data.mapping.PersistentProperty;
import org.springframework.data.mapping.PreferredConstructor;
Expand All @@ -33,15 +35,16 @@
import org.springframework.data.mapping.model.ParameterValueProvider;
import org.springframework.data.mapping.model.PreferredConstructorDiscoverer;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.util.ReflectionUtils;
import org.springframework.util.ReflectionUtils.FieldCallback;

/**
* Unit tests for {@link ReflectionEntityInstantiator}.
*
* @author Oliver Gierke
*/
@RunWith(MockitoJUnitRunner.class)
public class ReflectionEntityInstantiatorUnitTest<P extends PersistentProperty<P>> {
public class ReflectionEntityInstantiatorUnitTests<P extends PersistentProperty<P>> {

@Mock
PersistentEntity<?, P> entity;
Expand Down Expand Up @@ -93,13 +96,22 @@ public void createsInnerClassInstanceCorrectly() {
PreferredConstructor<Inner, P> constructor = entity.getPersistenceConstructor();
Parameter<Object, P> parameter = constructor.getParameters().iterator().next();

Object outer = new Outer();
final Object outer = new Outer();

when(provider.getParameterValue(parameter)).thenReturn(outer);
Inner instance = INSTANCE.createInstance(entity, provider);
final Inner instance = INSTANCE.createInstance(entity, provider);

assertThat(instance, is(notNullValue()));
assertThat(ReflectionTestUtils.getField(instance, "this$1"), is(outer));

// Hack to check syntheic field as compiles create different field names (e.g. this$0, this$1)
ReflectionUtils.doWithFields(Inner.class, new FieldCallback() {
public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException {
if (field.isSynthetic() && field.getName().startsWith("this$")) {
ReflectionUtils.makeAccessible(field);
assertThat(ReflectionUtils.getField(field, instance), is(outer));
}
}
});
}

static class Foo {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* @author Oliver Gierke
*/
@RunWith(MockitoJUnitRunner.class)
public class RevisionsUnitTest {
public class RevisionsUnitTests {

@Mock
RevisionMetadata<Integer> first, second;
Expand Down

0 comments on commit f476100

Please sign in to comment.