Polishing.

Simplify assertions, reformat code.

See #3921
Original pull request: #3930.
This commit is contained in:
Mark Paluch
2022-01-13 11:01:27 +01:00
parent f00e8ed93c
commit 6c21eab84b
2 changed files with 19 additions and 19 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2011-2021 the original author or authors.
* Copyright 2011-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -1389,11 +1389,11 @@ public class QueryMapper {
}
String nextToken() {
return pathParts.get(currentIndex+1);
return pathParts.get(currentIndex + 1);
}
boolean hasNexToken() {
return pathParts.size() > currentIndex+1;
return pathParts.size() > currentIndex + 1;
}
/**
@@ -1405,24 +1405,25 @@ public class QueryMapper {
protected String mapPropertyName(MongoPersistentProperty property) {
StringBuilder mappedName = new StringBuilder(PropertyToFieldNameConverter.INSTANCE.convert(property));
if(!hasNexToken()) {
if (!hasNexToken()) {
return mappedName.toString();
}
String nextToken = nextToken();
if(isPositionalParameter(nextToken)) {
if (isPositionalParameter(nextToken)) {
mappedName.append(".").append(nextToken);
currentIndex+=2;
currentIndex += 2;
return mappedName.toString();
}
if(property.isMap()) {
if (property.isMap()) {
mappedName.append(".").append(nextToken);
currentIndex+=2;
currentIndex += 2;
return mappedName.toString();
}
currentIndex++;
return mappedName.toString();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2021 the original author or authors.
* Copyright 2013-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -1208,7 +1208,7 @@ class UpdateMapperUnitTests {
Document mappedUpdate = mapper.getMappedObject(update.getUpdateObject(),
context.getPersistentEntity(EntityWithNestedMap.class));
assertThat(mappedUpdate).isEqualTo(new org.bson.Document("$set",new org.bson.Document("levelOne.a.b.d","e")));
assertThat(mappedUpdate).isEqualTo(new org.bson.Document("$set", new org.bson.Document("levelOne.a.b.d", "e")));
}
@Test // GH-3775
@@ -1218,7 +1218,7 @@ class UpdateMapperUnitTests {
Document mappedUpdate = mapper.getMappedObject(update.getUpdateObject(),
context.getPersistentEntity(EntityWithNestedMap.class));
assertThat(mappedUpdate).isEqualTo(new org.bson.Document("$set",new org.bson.Document("levelOne.0.1.3","4")));
assertThat(mappedUpdate).isEqualTo(new org.bson.Document("$set", new org.bson.Document("levelOne.0.1.3", "4")));
}
@Test // GH-3775
@@ -1228,7 +1228,7 @@ class UpdateMapperUnitTests {
Document mappedUpdate = mapper.getMappedObject(update.getUpdateObject(),
context.getPersistentEntity(EntityWithNestedMap.class));
assertThat(mappedUpdate).isEqualTo(new org.bson.Document("$set",new org.bson.Document("levelOne.0.1.c","4")));
assertThat(mappedUpdate).isEqualTo(new org.bson.Document("$set", new org.bson.Document("levelOne.0.1.c", "4")));
}
@Test // GH-3775
@@ -1238,7 +1238,7 @@ class UpdateMapperUnitTests {
Document mappedUpdate = mapper.getMappedObject(update.getUpdateObject(),
context.getPersistentEntity(EntityWithNestedMap.class));
assertThat(mappedUpdate).isEqualTo(new org.bson.Document("$set",new org.bson.Document("levelOne.0a.1b.3c","4")));
assertThat(mappedUpdate).isEqualTo(new org.bson.Document("$set", new org.bson.Document("levelOne.0a.1b.3c", "4")));
}
@Test // GH-3688
@@ -1258,7 +1258,7 @@ class UpdateMapperUnitTests {
Document mappedUpdate = mapper.getMappedObject(update.getUpdateObject(),
context.getPersistentEntity(TestData.class));
assertThat(mappedUpdate).isEqualTo(new org.bson.Document("$set",new org.bson.Document("testInnerData.testMap.1.intValue","4")));
assertThat(mappedUpdate).isEqualTo("{ $set: { 'testInnerData.testMap.1.intValue': '4' }}");
}
@Test // GH-3921
@@ -1268,7 +1268,7 @@ class UpdateMapperUnitTests {
Document mappedUpdate = mapper.getMappedObject(update.getUpdateObject(),
context.getPersistentEntity(TestData.class));
assertThat(mappedUpdate).isEqualTo(new org.bson.Document("$set",new org.bson.Document("testInnerData.imaginaryMap.1.noExistingProperty","4")));
assertThat(mappedUpdate).isEqualTo("{ $set: { 'testInnerData.imaginaryMap.1.nonExistingProperty': '4' }}");
}
@Test // GH-3921
@@ -1278,7 +1278,7 @@ class UpdateMapperUnitTests {
Document mappedUpdate = mapper.getMappedObject(update.getUpdateObject(),
context.getPersistentEntity(TestData.class));
assertThat(mappedUpdate).isEqualTo(new org.bson.Document("$set",new org.bson.Document("testInnerData.testMap.1.nonExistingProperty.2.someValue","4")));
assertThat(mappedUpdate).isEqualTo("{ $set: { 'testInnerData.testMap.1.nonExistingProperty.2.someValue': '4' }}");
}
static class DomainTypeWrappingConcreteyTypeHavingListOfInterfaceTypeAttributes {
@@ -1517,7 +1517,7 @@ class UpdateMapperUnitTests {
Map<Object, NestedDocument> concreteMap;
}
static class EntityWithIntKeyedMap{
static class EntityWithIntKeyedMap {
Map<Integer, EntityWithObjectMap> intKeyedMap;
}
@@ -1653,8 +1653,7 @@ class UpdateMapperUnitTests {
@Data
private static class TestData {
@Id
private String id;
@Id private String id;
private TestInnerData testInnerData;
}