Skip to content

Commit 4d5a382

Browse files
committed
Polishing.
Original pull request #1901
1 parent 08daf47 commit 4d5a382

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/Identifier.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import java.util.Objects;
2525

2626
import org.springframework.data.relational.core.sql.SqlIdentifier;
27-
import org.springframework.lang.NonNull;
2827
import org.springframework.lang.Nullable;
2928
import org.springframework.util.Assert;
3029
import org.springframework.util.ClassUtils;
@@ -60,15 +59,15 @@ public static Identifier empty() {
6059
/**
6160
* Creates an {@link Identifier} from {@code name}, {@code value}, and a {@link Class target type}.
6261
*
63-
* @param name must not be {@literal null} or empty.
64-
* @param value must not be null
62+
* @param name must not be {@literal null}.
63+
* @param value must not be {@literal null}.
6564
* @param targetType must not be {@literal null}.
6665
* @return the {@link Identifier} for {@code name}, {@code value}, and a {@link Class target type}.
6766
*/
6867
public static Identifier of(SqlIdentifier name, Object value, Class<?> targetType) {
6968

70-
Assert.notNull(name, "Name must not be empty");
71-
Assert.notNull(value, "Value must not be empty");
69+
Assert.notNull(name, "Name must not be null");
70+
Assert.notNull(value, "Value must not be null");
7271
Assert.notNull(targetType, "Target type must not be null");
7372

7473
return new Identifier(Collections.singletonList(new SingleIdentifierValue(name, value, targetType)));
@@ -92,7 +91,8 @@ public static Identifier from(Map<SqlIdentifier, Object> map) {
9291

9392
map.forEach((k, v) -> {
9493

95-
Assert.notNull(v, "The source map for identifier cannot contain null values");
94+
Assert.notNull(v, "The source map for identifier must not contain null values");
95+
9696
values.add(new SingleIdentifierValue(k, v, ClassUtils.getUserClass(v)));
9797
});
9898

spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/IdentifierUnitTests.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,28 @@ public void getParametersByName() {
4747
}
4848

4949
@Test // DATAJDBC-326
50-
public void parametersWithStringKeysUseObjectAsTypeForNull() {
50+
public void typeIsCalculatedCorrectly() {
5151

5252
HashMap<SqlIdentifier, Object> parameters = new HashMap<>();
53-
Object value = new Object();
53+
Object objectValue = new Object();
54+
Object stringValue = "text";
55+
Object intValue = 23;
56+
Object integerValue = 42;
5457

55-
parameters.put(unquoted("one"), value);
58+
parameters.put(unquoted("one"), objectValue);
59+
parameters.put(unquoted("two"), stringValue);
60+
parameters.put(unquoted("three"), intValue);
61+
parameters.put(unquoted("four"), integerValue);
5662

5763
Identifier identifier = Identifier.from(parameters);
5864

5965
assertThat(identifier.getParts()) //
6066
.extracting("name", "value", "targetType") //
61-
.containsExactly( //
62-
Assertions.tuple(unquoted("one"), value, Object.class) //
67+
.containsExactlyInAnyOrder( //
68+
Assertions.tuple(unquoted("one"), objectValue, Object.class), //
69+
Assertions.tuple(unquoted("two"), stringValue, String.class), //
70+
Assertions.tuple(unquoted("three"), intValue, Integer.class), //
71+
Assertions.tuple(unquoted("four"), integerValue, Integer.class) //
6372
);
6473
}
6574

0 commit comments

Comments
 (0)