DATAMONGO-2307 - Polishing.
Remove unused import and turn static variable into method reference. Original Pull Request: #765
This commit is contained in:
@@ -85,7 +85,6 @@ import org.springframework.data.mongodb.core.query.Query;
|
||||
import org.springframework.data.mongodb.core.query.Update;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import com.mongodb.DB;
|
||||
@@ -1565,7 +1564,7 @@ public class MongoTemplateUnitTests extends MongoOperationsUnitTests {
|
||||
public void beforeSaveCallbackAllowsTargetEntityModificationsUsingSave() {
|
||||
|
||||
StaticApplicationContext ctx = new StaticApplicationContext();
|
||||
ctx.registerBean(BeforeSaveCallback.class, () -> markPersonAsPersistedCallback);
|
||||
ctx.registerBean(BeforeSaveCallback.class, this::beforeSaveCallbackReturningNewPersonWithTransientAttribute);
|
||||
ctx.refresh();
|
||||
|
||||
template.setApplicationContext(ctx);
|
||||
@@ -1583,7 +1582,7 @@ public class MongoTemplateUnitTests extends MongoOperationsUnitTests {
|
||||
public void beforeSaveCallbackAllowsTargetEntityModificationsUsingInsert() {
|
||||
|
||||
StaticApplicationContext ctx = new StaticApplicationContext();
|
||||
ctx.registerBean(BeforeSaveCallback.class, () -> markPersonAsPersistedCallback);
|
||||
ctx.registerBean(BeforeSaveCallback.class, this::beforeSaveCallbackReturningNewPersonWithTransientAttribute);
|
||||
ctx.refresh();
|
||||
|
||||
template.setApplicationContext(ctx);
|
||||
@@ -1681,20 +1680,9 @@ public class MongoTemplateUnitTests extends MongoOperationsUnitTests {
|
||||
|
||||
static class PersonWithTransientAttribute extends Person {
|
||||
|
||||
@Transient
|
||||
boolean isNew = true;
|
||||
@Transient boolean isNew = true;
|
||||
}
|
||||
|
||||
static BeforeSaveCallback<PersonWithTransientAttribute> markPersonAsPersistedCallback = (entity, document, collection) -> {
|
||||
|
||||
// Return a completely new instance, ie in case of an immutable entity;
|
||||
PersonWithTransientAttribute newEntity = new PersonWithTransientAttribute();
|
||||
newEntity.id = entity.id;
|
||||
newEntity.firstname = entity.firstname;
|
||||
newEntity.isNew = false;
|
||||
return newEntity;
|
||||
};
|
||||
|
||||
interface PersonProjection {
|
||||
String getFirstname();
|
||||
}
|
||||
@@ -1772,6 +1760,18 @@ public class MongoTemplateUnitTests extends MongoOperationsUnitTests {
|
||||
return this.template;
|
||||
}
|
||||
|
||||
private BeforeSaveCallback<PersonWithTransientAttribute> beforeSaveCallbackReturningNewPersonWithTransientAttribute() {
|
||||
return (entity, document, collection) -> {
|
||||
|
||||
// Return a completely new instance, ie in case of an immutable entity;
|
||||
PersonWithTransientAttribute newEntity = new PersonWithTransientAttribute();
|
||||
newEntity.id = entity.id;
|
||||
newEntity.firstname = entity.firstname;
|
||||
newEntity.isNew = false;
|
||||
return newEntity;
|
||||
};
|
||||
}
|
||||
|
||||
static class ValueCapturingEntityCallback<T> {
|
||||
|
||||
private final List<T> values = new ArrayList<>(1);
|
||||
|
||||
Reference in New Issue
Block a user