Skip to content

Commit 64cc223

Browse files
committed
Improving Unit test coverage
1 parent 4748ee5 commit 64cc223

File tree

78 files changed

+434
-176
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+434
-176
lines changed

src/main/java/org/socialsignin/spring/data/dynamodb/config/AbstractDynamoDBConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public DynamoDBMappingContext dynamoDBMappingContext() throws ClassNotFoundExcep
8888
*/
8989
protected Set<Class<?>> getInitialEntitySet() throws ClassNotFoundException {
9090

91-
Set<Class<?>> initialEntitySet = new HashSet<Class<?>>();
91+
Set<Class<?>> initialEntitySet = new HashSet<>();
9292

9393
String[] basePackages = getMappingBasePackages();
9494

src/main/java/org/socialsignin/spring/data/dynamodb/mapping/AbstractDynamoDBDateMarshaller.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
/**
2525
* @author Michael Lavelle
26+
* @author Sebastian Just
2627
* @deprecated According to {@code com.amazonaws.services.dynamodbv2.datamodeling.marshallers.CustomMarshaller.marshall(Object)}
2728
* at some point {@link DynamoDBMarshaller} might be cached - whereas {@link DateFormat} is not thread-safe. <br>
2829
* Use {@link org.socialsignin.spring.data.dynamodb.marshaller.DateDynamoDBMarshaller} instead.
@@ -39,15 +40,23 @@ public AbstractDynamoDBDateMarshaller(DateFormat dateFormat) {
3940

4041
@Override
4142
public String marshall(Date getterReturnResult) {
42-
return dateFormat.format(getterReturnResult);
43+
if (getterReturnResult == null) {
44+
return null;
45+
} else {
46+
return dateFormat.format(getterReturnResult);
47+
}
4348
}
4449

4550
@Override
46-
public Date unmarshall(Class<Date> clazz, String obj) {
47-
try {
48-
return dateFormat.parse(obj);
49-
} catch (ParseException e) {
50-
throw new RuntimeException(e);
51+
public Date unmarshall(Class<Date> clazz, String obj) throws IllegalArgumentException {
52+
if (obj == null) {
53+
return null;
54+
} else {
55+
try {
56+
return dateFormat.parse(obj);
57+
} catch (ParseException e) {
58+
throw new IllegalArgumentException("Could not unmarshall '" + obj + "' via " + dateFormat, e);
59+
}
5160
}
5261
}
5362

src/main/java/org/socialsignin/spring/data/dynamodb/mapping/DefaultDynamoDBDateMarshaller.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,26 @@
2020

2121
/**
2222
* @author Michael Lavelle
23+
* @author Sebastian Just
2324
* @deprecated Consider using {@link org.socialsignin.spring.data.dynamodb.marshaller.Date2IsoDynamoDBMarshaller}
2425
*/
2526
@Deprecated
2627
public class DefaultDynamoDBDateMarshaller extends AbstractDynamoDBDateMarshaller {
2728

29+
private static final class UTCSimpleDateFormat extends SimpleDateFormat {
30+
private static final long serialVersionUID = 1L;
31+
private UTCSimpleDateFormat() {
32+
super("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
33+
setTimeZone(TimeZone.getTimeZone("UTC"));
34+
}
35+
36+
@Override
37+
public String toString() {
38+
return toPattern();
39+
}
40+
}
41+
2842
public DefaultDynamoDBDateMarshaller() {
29-
super(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") {
30-
private static final long serialVersionUID = 1L;
31-
{
32-
setTimeZone(TimeZone.getTimeZone("UTC"));
33-
}
34-
});
43+
super(new UTCSimpleDateFormat());
3544
}
3645
}

src/main/java/org/socialsignin/spring/data/dynamodb/mapping/DynamoDBMappingContext.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
* as primary abstractions.
3333
*
3434
* @author Michael Lavelle
35+
* @author Sebastian Just
3536
*/
3637
public class DynamoDBMappingContext extends AbstractMappingContext<DynamoDBPersistentEntityImpl<?>, DynamoDBPersistentProperty> {
3738
/*
@@ -43,7 +44,7 @@ public class DynamoDBMappingContext extends AbstractMappingContext<DynamoDBPersi
4344
*/
4445
@Override
4546
protected <T> DynamoDBPersistentEntityImpl<?> createPersistentEntity(TypeInformation<T> typeInformation) {
46-
return new DynamoDBPersistentEntityImpl<T>(typeInformation, null);
47+
return new DynamoDBPersistentEntityImpl<>(typeInformation, null);
4748

4849
}
4950

src/main/java/org/socialsignin/spring/data/dynamodb/mapping/DynamoDBPersistentEntity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* Interface for a DynamoDB-specific entity.
2222
*
2323
* @author Michael Lavelle
24+
* @author Sebastian Just
2425
*/
2526
public interface DynamoDBPersistentEntity<T> extends PersistentEntity<T, DynamoDBPersistentProperty> {
2627

src/main/java/org/socialsignin/spring/data/dynamodb/mapping/DynamoDBPersistentEntityImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
* DynamoDB specific {@link DynamoDBPersistentEntity} implementation
2626
*
2727
* @author Michael Lavelle
28+
* @author Sebastian Just
2829
*/
2930
public class DynamoDBPersistentEntityImpl<T> extends BasicPersistentEntity<T, DynamoDBPersistentProperty> implements
3031
DynamoDBPersistentEntity<T> {

src/main/java/org/socialsignin/spring/data/dynamodb/mapping/DynamoDBPersistentProperty.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@
2121
* Interface for a DynamoDB-specific {@link PersistentProperty}.
2222
*
2323
* @author Michael Lavelle
24+
* @author Sebastian Just
2425
*/
2526
public interface DynamoDBPersistentProperty extends PersistentProperty<DynamoDBPersistentProperty> {
2627

27-
public boolean isHashKeyProperty();
28+
boolean isHashKeyProperty();
2829

29-
public boolean isCompositeIdProperty();
30+
boolean isCompositeIdProperty();
3031

3132
}

src/main/java/org/socialsignin/spring/data/dynamodb/mapping/DynamoDBPersistentPropertyImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
* {@link DynamoDBPersistentProperty} implementation
3737
*
3838
* @author Michael Lavelle
39+
* @author Sebastian Just
3940
*/
4041
class DynamoDBPersistentPropertyImpl extends AnnotationBasedPersistentProperty<DynamoDBPersistentProperty> implements
4142
DynamoDBPersistentProperty {
@@ -50,7 +51,7 @@ class DynamoDBPersistentPropertyImpl extends AnnotationBasedPersistentProperty<D
5051
annotations.add(Reference.class); // Reference not yet supported
5152
ASSOCIATION_ANNOTATIONS = Collections.unmodifiableSet(annotations);
5253

53-
annotations = new HashSet<Class<? extends Annotation>>();
54+
annotations = new HashSet<>();
5455
annotations.add(Id.class);
5556
annotations.add(DynamoDBHashKey.class);
5657
ID_ANNOTATIONS = annotations;

src/main/java/org/socialsignin/spring/data/dynamodb/mapping/event/AbstractDynamoDBEventListener.java

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
* Base class to implement domain class specific {@link ApplicationListener}s.
4646
*
4747
* @author Michael Lavelle
48+
* @author Sebastian Just
4849
*/
4950
public abstract class AbstractDynamoDBEventListener<E> implements
5051
ApplicationListener<DynamoDBMappingEvent<?>> {
@@ -75,18 +76,16 @@ public void onApplicationEvent(DynamoDBMappingEvent<?> event) {
7576
@SuppressWarnings("unchecked")
7677
E source = (E) event.getSource();
7778

78-
if (source == null) {
79-
return;
80-
}
79+
// source can not be null as java.util.EventObject can not be constructed with null
80+
assert source != null;
8181

8282
if (event instanceof AfterScanEvent) {
83-
if (source instanceof PaginatedScanList) {
84-
publishEachElement((PaginatedScanList<?>)source, this::onAfterScan);
85-
}
83+
84+
publishEachElement((PaginatedScanList<?>)source, this::onAfterScan);
85+
8686
} else if (event instanceof AfterQueryEvent) {
87-
if (source instanceof PaginatedQueryList) {
88-
publishEachElement((PaginatedQueryList<?>)source, this::onAfterQuery);
89-
}
87+
88+
publishEachElement((PaginatedQueryList<?>)source, this::onAfterQuery);
9089
}
9190
// Check for matching domain type and invoke callbacks
9291
else if (domainClass.isAssignableFrom(source.getClass())) {
@@ -117,45 +116,31 @@ private void publishEachElement(List<?> list, Consumer<E> publishMethod) {
117116
}
118117

119118
public void onBeforeSave(E source) {
120-
if (LOG.isDebugEnabled()) {
121-
LOG.debug("onBeforeSave({}, {})", source);
122-
}
119+
LOG.debug("onBeforeSave({}, {})", source);
123120
}
124121

125122
public void onAfterSave(E source) {
126-
if (LOG.isDebugEnabled()) {
127-
LOG.debug("onAfterSave({}, {})", source);
128-
}
123+
LOG.debug("onAfterSave({}, {})", source);
129124
}
130125

131126
public void onAfterLoad(E source) {
132-
if (LOG.isDebugEnabled()) {
133-
LOG.debug("onAfterLoad({})", source);
134-
}
127+
LOG.debug("onAfterLoad({})", source);
135128
}
136129

137130
public void onAfterDelete(E source) {
138-
if (LOG.isDebugEnabled()) {
139-
LOG.debug("onAfterDelete({})", source);
140-
}
131+
LOG.debug("onAfterDelete({})", source);
141132
}
142133

143134
public void onBeforeDelete(E source) {
144-
if (LOG.isDebugEnabled()) {
145-
LOG.debug("onBeforeDelete({})", source);
146-
}
135+
LOG.debug("onBeforeDelete({})", source);
147136
}
148137

149138
public void onAfterScan(E source) {
150-
if (LOG.isDebugEnabled()) {
151-
LOG.debug("onAfterScan({})", source);
152-
}
139+
LOG.debug("onAfterScan({})", source);
153140
}
154141

155142
public void onAfterQuery(E source) {
156-
if (LOG.isDebugEnabled()) {
157-
LOG.debug("onAfterQuery({})", source);
158-
}
143+
LOG.debug("onAfterQuery({})", source);
159144
}
160145

161146
}

src/main/java/org/socialsignin/spring/data/dynamodb/mapping/event/AfterDeleteEvent.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
/**
2020
* @author Michael Lavelle
21+
* @author Sebastian Just
2122
*/
2223
public class AfterDeleteEvent<T> extends DynamoDBMappingEvent<T> {
2324

0 commit comments

Comments
 (0)