Skip to content

Commit 4089c9b

Browse files
committed
Spockified some tests and improved coverage report
1 parent 43194d4 commit 4089c9b

15 files changed

+438
-494
lines changed

pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,16 @@
427427
<groupId>org.codehaus.mojo</groupId>
428428
<artifactId>cobertura-maven-plugin</artifactId>
429429
<version>2.6</version>
430+
<configuration>
431+
<instrumentation>
432+
<excludes>
433+
<exclude>**/*IT.class</exclude>
434+
<exclude>**/*AT.class</exclude>
435+
<exclude>**/*Example.class</exclude>
436+
</excludes>
437+
</instrumentation>
438+
<check/>
439+
</configuration>
430440
</plugin>
431441
<plugin>
432442
<groupId>org.apache.maven.plugins</groupId>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
/**
3030
* @author Daniel Bechler
3131
*/
32-
public class CircularReferenceDetectionBasedOnEqualsTest
32+
public class CircularReferenceDetectionBasedOnEqualsIT
3333
{
3434
private ObjectDiffer objectDiffer;
3535

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
/**
3030
* @author Daniel Bechler
3131
*/
32-
public class CircularReferenceDetectionBasedOnIdentityTest
32+
public class CircularReferenceDetectionBasedOnIdentityIT
3333
{
3434
private ObjectDiffer objectDiffer;
3535

src/integration-test/java/de/danielbechler/diff/issues/issue3/IgnoreTest.groovy renamed to src/integration-test/java/de/danielbechler/diff/issues/issue3/IgnoreByPropertyNameIT.groovy

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,13 @@
1717
package de.danielbechler.diff.issues.issue3
1818

1919
import de.danielbechler.diff.ObjectDifferBuilder
20-
import spock.lang.Ignore
2120
import spock.lang.Specification
2221

2322
/**
2423
* Created by dbechler.
2524
*/
26-
class IgnoreTest extends Specification {
25+
class IgnoreByPropertyNameIT extends Specification {
2726

28-
@Ignore
2927
def "ignoring by property name"() {
3028
given:
3129
def base = new FooContainer("foo-base", "bar-base", "test-base")

src/main/java/de/danielbechler/diff/introspection/BeanPropertyAccessor.java

Lines changed: 96 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -64,46 +64,6 @@ private static Method makeAccessible(final Method method)
6464
return method;
6565
}
6666

67-
private static boolean tryToReplaceCollectionContent(final Collection<Object> target,
68-
final Collection<Object> value)
69-
{
70-
if (target == null)
71-
{
72-
return false;
73-
}
74-
try
75-
{
76-
target.clear();
77-
target.addAll(value);
78-
return true;
79-
}
80-
catch (final Exception unmodifiable)
81-
{
82-
logger.debug("Failed to replace content of existing Collection", unmodifiable);
83-
return false;
84-
}
85-
}
86-
87-
private static boolean tryToReplaceMapContent(final Map<Object, Object> target,
88-
final Map<Object, Object> value)
89-
{
90-
if (target == null)
91-
{
92-
return false;
93-
}
94-
try
95-
{
96-
target.clear();
97-
target.putAll(value);
98-
return true;
99-
}
100-
catch (final Exception unmodifiable)
101-
{
102-
logger.debug("Failed to replace content of existing Map", unmodifiable);
103-
return false;
104-
}
105-
}
106-
10767
public final Set<String> getCategories()
10868
{
10969
return categories;
@@ -124,6 +84,58 @@ public void setExcluded(final boolean excluded)
12484
this.excluded = excluded;
12585
}
12686

87+
public String getPropertyName()
88+
{
89+
return this.propertyName;
90+
}
91+
92+
/**
93+
* @return The annotations of the getter used to access this property.
94+
*/
95+
public Set<Annotation> getReadMethodAnnotations()
96+
{
97+
return new LinkedHashSet<Annotation>(Arrays.asList(readMethod.getAnnotations()));
98+
}
99+
100+
public <T extends Annotation> T getReadMethodAnnotation(final Class<T> annotationClass)
101+
{
102+
final Set<? extends Annotation> annotations = getReadMethodAnnotations();
103+
assert (annotations != null) : "Something is wrong here. " +
104+
"The contract of getReadAnnotations() guarantees a non-null return value.";
105+
for (final Annotation annotation : annotations)
106+
{
107+
if (annotationClass.isAssignableFrom(annotation.annotationType()))
108+
{
109+
return annotationClass.cast(annotation);
110+
}
111+
}
112+
return null;
113+
}
114+
115+
public BeanPropertyElementSelector getElementSelector()
116+
{
117+
return new BeanPropertyElementSelector(this.propertyName);
118+
}
119+
120+
public Object get(final Object target)
121+
{
122+
if (target == null)
123+
{
124+
return null;
125+
}
126+
try
127+
{
128+
return readMethod.invoke(target);
129+
}
130+
catch (final Exception e)
131+
{
132+
final BeanPropertyReadException ex = new BeanPropertyReadException(e);
133+
ex.setPropertyName(propertyName);
134+
ex.setTargetType(target.getClass());
135+
throw ex;
136+
}
137+
}
138+
127139
public void set(final Object target, final Object value)
128140
{
129141
if (target == null)
@@ -142,24 +154,14 @@ else if (writeMethod == null)
142154
}
143155
}
144156

145-
private void logFailedSet(final Object value)
157+
public void unset(final Object target)
146158
{
147-
logger.info("Couldn't set new value '{}' for property '{}'", value, propertyName);
159+
set(target, null);
148160
}
149161

150-
private void invokeWriteMethod(final Object target, final Object value)
162+
private void logFailedSet(final Object value)
151163
{
152-
try
153-
{
154-
writeMethod.invoke(target, value);
155-
}
156-
catch (final Exception e)
157-
{
158-
final BeanPropertyWriteException ex = new BeanPropertyWriteException(e, value);
159-
ex.setPropertyName(propertyName);
160-
ex.setTargetType(getType());
161-
throw ex;
162-
}
164+
logger.info("Couldn't set new value '{}' for property '{}'", value, propertyName);
163165
}
164166

165167
private void tryToReplaceContentOfCollectionTypes(final Object target, final Object value)
@@ -181,66 +183,64 @@ private void tryToReplaceContentOfCollectionTypes(final Object target, final Obj
181183
logFailedSet(value);
182184
}
183185

184-
public Object get(final Object target)
186+
private void invokeWriteMethod(final Object target, final Object value)
185187
{
186-
if (target == null)
187-
{
188-
return null;
189-
}
190188
try
191189
{
192-
return readMethod.invoke(target);
190+
writeMethod.invoke(target, value);
193191
}
194192
catch (final Exception e)
195193
{
196-
final BeanPropertyReadException ex = new BeanPropertyReadException(e);
194+
final BeanPropertyWriteException ex = new BeanPropertyWriteException(e, value);
197195
ex.setPropertyName(propertyName);
198-
ex.setTargetType(target.getClass());
196+
ex.setTargetType(getType());
199197
throw ex;
200198
}
201199
}
202200

203-
public void unset(final Object target)
204-
{
205-
set(target, null);
206-
}
207-
208-
public Class<?> getType()
209-
{
210-
return this.type;
211-
}
212-
213-
public String getPropertyName()
214-
{
215-
return this.propertyName;
216-
}
217-
218-
public BeanPropertyElementSelector getElementSelector()
201+
private static boolean tryToReplaceCollectionContent(final Collection<Object> target,
202+
final Collection<Object> value)
219203
{
220-
return new BeanPropertyElementSelector(this.propertyName);
204+
if (target == null)
205+
{
206+
return false;
207+
}
208+
try
209+
{
210+
target.clear();
211+
target.addAll(value);
212+
return true;
213+
}
214+
catch (final Exception unmodifiable)
215+
{
216+
logger.debug("Failed to replace content of existing Collection", unmodifiable);
217+
return false;
218+
}
221219
}
222220

223-
/**
224-
* @return The annotations of the getter used to access this property.
225-
*/
226-
public Set<Annotation> getReadMethodAnnotations()
221+
private static boolean tryToReplaceMapContent(final Map<Object, Object> target,
222+
final Map<Object, Object> value)
227223
{
228-
return new LinkedHashSet<Annotation>(Arrays.asList(readMethod.getAnnotations()));
224+
if (target == null)
225+
{
226+
return false;
227+
}
228+
try
229+
{
230+
target.clear();
231+
target.putAll(value);
232+
return true;
233+
}
234+
catch (final Exception unmodifiable)
235+
{
236+
logger.debug("Failed to replace content of existing Map", unmodifiable);
237+
return false;
238+
}
229239
}
230240

231-
public <T extends Annotation> T getReadMethodAnnotation(final Class<T> annotationClass)
241+
public Class<?> getType()
232242
{
233-
final Set<? extends Annotation> annotations = getReadMethodAnnotations();
234-
assert (annotations != null) : "Something is wrong here. " +
235-
"The contract of getReadAnnotations() guarantees a non-null return value.";
236-
for (final Annotation annotation : annotations)
237-
{
238-
if (annotationClass.isAssignableFrom(annotation.annotationType()))
239-
{
240-
return annotationClass.cast(annotation);
241-
}
242-
}
243-
return null;
243+
return this.type;
244244
}
245245

246246
@Override

src/main/java/de/danielbechler/diff/introspection/BeanPropertyException.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
/**
2020
* @author Daniel Bechler
2121
*/
22+
@SuppressWarnings("UnusedDeclaration")
2223
public class BeanPropertyException extends RuntimeException
2324
{
2425
private static final long serialVersionUID = 1L;

src/main/java/de/danielbechler/diff/introspection/DefaultPropertyAccessExceptionHandler.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.slf4j.Logger;
2121
import org.slf4j.LoggerFactory;
2222

23+
@SuppressWarnings("UnusedDeclaration")
2324
public class DefaultPropertyAccessExceptionHandler implements BeanPropertyAccessExceptionHandler
2425
{
2526
private static final Logger logger = LoggerFactory.getLogger(DefaultPropertyAccessExceptionHandler.class);

src/test/java/de/danielbechler/diff/access/InstancesSpec.groovy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013 Daniel Bechler
2+
* Copyright 2014 Daniel Bechler
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -76,13 +76,13 @@ class InstancesSpec extends Specification {
7676

7777
def "getType() returns most specific shared type for non-primitive objects (except for Map and Collection)"() {
7878
given:
79-
def instances = Instances.of(accessor, working, base);
79+
def instances = Instances.of(beanPropertyAccessor, working, base);
8080

8181
expect:
8282
instances.getType() == resultType
8383

8484
where:
85-
accessor | working | base | resultType
85+
beanPropertyAccessor | working | base | resultType
8686
RootAccessor.instance | BigInteger.ONE | BigDecimal.ONE | Number
8787
RootAccessor.instance | new LineNumberReader(new StringReader("")) | new BufferedReader(new StringReader("")) | BufferedReader
8888
RootAccessor.instance | new StringReader("") | new BufferedReader(new StringReader("")) | Reader

src/test/java/de/danielbechler/diff/introspection/BeanPropertyAccessorBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
/**
2222
* @author Daniel Bechler
2323
*/
24-
public final class BeanPropertyAccessorBuilder
24+
final class BeanPropertyAccessorBuilder
2525
{
2626
private BeanPropertyAccessorBuilder()
2727
{
@@ -85,7 +85,7 @@ public BeanPropertyAccessor build()
8585
}
8686
return new BeanPropertyAccessor(propertyName, readMethod, writeMethod);
8787
}
88-
catch (NoSuchMethodException e)
88+
catch (final NoSuchMethodException e)
8989
{
9090
throw new RuntimeException(e);
9191
}

0 commit comments

Comments
 (0)