Skip to content

Commit 6c21eab

Browse files
committed
Polishing.
Simplify assertions, reformat code. See #3921 Original pull request: #3930.
1 parent f00e8ed commit 6c21eab

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/QueryMapper.java

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2011-2021 the original author or authors.
2+
* Copyright 2011-2022 the original author or authors.
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.
@@ -1389,11 +1389,11 @@ public KeyMapper(String key,
13891389
}
13901390

13911391
String nextToken() {
1392-
return pathParts.get(currentIndex+1);
1392+
return pathParts.get(currentIndex + 1);
13931393
}
13941394

13951395
boolean hasNexToken() {
1396-
return pathParts.size() > currentIndex+1;
1396+
return pathParts.size() > currentIndex + 1;
13971397
}
13981398

13991399
/**
@@ -1405,24 +1405,25 @@ boolean hasNexToken() {
14051405
protected String mapPropertyName(MongoPersistentProperty property) {
14061406

14071407
StringBuilder mappedName = new StringBuilder(PropertyToFieldNameConverter.INSTANCE.convert(property));
1408-
if(!hasNexToken()) {
1408+
if (!hasNexToken()) {
14091409
return mappedName.toString();
14101410
}
14111411

14121412
String nextToken = nextToken();
1413-
if(isPositionalParameter(nextToken)) {
1413+
if (isPositionalParameter(nextToken)) {
14141414

14151415
mappedName.append(".").append(nextToken);
1416-
currentIndex+=2;
1416+
currentIndex += 2;
14171417
return mappedName.toString();
14181418
}
14191419

1420-
if(property.isMap()) {
1420+
if (property.isMap()) {
14211421

14221422
mappedName.append(".").append(nextToken);
1423-
currentIndex+=2;
1423+
currentIndex += 2;
14241424
return mappedName.toString();
14251425
}
1426+
14261427
currentIndex++;
14271428
return mappedName.toString();
14281429
}

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/UpdateMapperUnitTests.java

+10-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2021 the original author or authors.
2+
* Copyright 2013-2022 the original author or authors.
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.
@@ -1208,7 +1208,7 @@ void mapNestedStringFieldCorrectly() {
12081208
Document mappedUpdate = mapper.getMappedObject(update.getUpdateObject(),
12091209
context.getPersistentEntity(EntityWithNestedMap.class));
12101210

1211-
assertThat(mappedUpdate).isEqualTo(new org.bson.Document("$set",new org.bson.Document("levelOne.a.b.d","e")));
1211+
assertThat(mappedUpdate).isEqualTo(new org.bson.Document("$set", new org.bson.Document("levelOne.a.b.d", "e")));
12121212
}
12131213

12141214
@Test // GH-3775
@@ -1218,7 +1218,7 @@ void mapNestedIntegerFieldCorrectly() {
12181218
Document mappedUpdate = mapper.getMappedObject(update.getUpdateObject(),
12191219
context.getPersistentEntity(EntityWithNestedMap.class));
12201220

1221-
assertThat(mappedUpdate).isEqualTo(new org.bson.Document("$set",new org.bson.Document("levelOne.0.1.3","4")));
1221+
assertThat(mappedUpdate).isEqualTo(new org.bson.Document("$set", new org.bson.Document("levelOne.0.1.3", "4")));
12221222
}
12231223

12241224
@Test // GH-3775
@@ -1228,7 +1228,7 @@ void mapNestedMixedStringIntegerFieldCorrectly() {
12281228
Document mappedUpdate = mapper.getMappedObject(update.getUpdateObject(),
12291229
context.getPersistentEntity(EntityWithNestedMap.class));
12301230

1231-
assertThat(mappedUpdate).isEqualTo(new org.bson.Document("$set",new org.bson.Document("levelOne.0.1.c","4")));
1231+
assertThat(mappedUpdate).isEqualTo(new org.bson.Document("$set", new org.bson.Document("levelOne.0.1.c", "4")));
12321232
}
12331233

12341234
@Test // GH-3775
@@ -1238,7 +1238,7 @@ void mapNestedMixedStringIntegerWithStartNumberFieldCorrectly() {
12381238
Document mappedUpdate = mapper.getMappedObject(update.getUpdateObject(),
12391239
context.getPersistentEntity(EntityWithNestedMap.class));
12401240

1241-
assertThat(mappedUpdate).isEqualTo(new org.bson.Document("$set",new org.bson.Document("levelOne.0a.1b.3c","4")));
1241+
assertThat(mappedUpdate).isEqualTo(new org.bson.Document("$set", new org.bson.Document("levelOne.0a.1b.3c", "4")));
12421242
}
12431243

12441244
@Test // GH-3688
@@ -1258,7 +1258,7 @@ void mapNumericKeyInPathHavingComplexMapValyeTypes() {
12581258
Document mappedUpdate = mapper.getMappedObject(update.getUpdateObject(),
12591259
context.getPersistentEntity(TestData.class));
12601260

1261-
assertThat(mappedUpdate).isEqualTo(new org.bson.Document("$set",new org.bson.Document("testInnerData.testMap.1.intValue","4")));
1261+
assertThat(mappedUpdate).isEqualTo("{ $set: { 'testInnerData.testMap.1.intValue': '4' }}");
12621262
}
12631263

12641264
@Test // GH-3921
@@ -1268,7 +1268,7 @@ void mapNumericKeyInPathNotMatchingExistingProperties() {
12681268
Document mappedUpdate = mapper.getMappedObject(update.getUpdateObject(),
12691269
context.getPersistentEntity(TestData.class));
12701270

1271-
assertThat(mappedUpdate).isEqualTo(new org.bson.Document("$set",new org.bson.Document("testInnerData.imaginaryMap.1.noExistingProperty","4")));
1271+
assertThat(mappedUpdate).isEqualTo("{ $set: { 'testInnerData.imaginaryMap.1.nonExistingProperty': '4' }}");
12721272
}
12731273

12741274
@Test // GH-3921
@@ -1278,7 +1278,7 @@ void mapNumericKeyInPathPartiallyMatchingExistingProperties() {
12781278
Document mappedUpdate = mapper.getMappedObject(update.getUpdateObject(),
12791279
context.getPersistentEntity(TestData.class));
12801280

1281-
assertThat(mappedUpdate).isEqualTo(new org.bson.Document("$set",new org.bson.Document("testInnerData.testMap.1.nonExistingProperty.2.someValue","4")));
1281+
assertThat(mappedUpdate).isEqualTo("{ $set: { 'testInnerData.testMap.1.nonExistingProperty.2.someValue': '4' }}");
12821282
}
12831283

12841284
static class DomainTypeWrappingConcreteyTypeHavingListOfInterfaceTypeAttributes {
@@ -1517,7 +1517,7 @@ static class EntityWithObjectMap {
15171517
Map<Object, NestedDocument> concreteMap;
15181518
}
15191519

1520-
static class EntityWithIntKeyedMap{
1520+
static class EntityWithIntKeyedMap {
15211521
Map<Integer, EntityWithObjectMap> intKeyedMap;
15221522
}
15231523

@@ -1653,8 +1653,7 @@ static class EntityWithNestedMap {
16531653

16541654
@Data
16551655
private static class TestData {
1656-
@Id
1657-
private String id;
1656+
@Id private String id;
16581657
private TestInnerData testInnerData;
16591658
}
16601659

0 commit comments

Comments
 (0)