Skip to content

Commit 3f97ab1

Browse files
marschallsnicoll
authored andcommitted
Avoid use of double constructor of BigDecimal
Codacy warns about an Error Prone [1] use of the double constructor of BigDecimal in tests. The reason given is that it is a source of precision loss if the number does not have an exact double representation. The recommendation is to use the String constructor of BigDecimal instead as it does not require using a lossy argument. This commit contains the following changes: - replace usage of the double constructor of BigDecimal with the String constructor of BigDecimal in JdbcTemplateQueryTests - update the copyright year [1] http://errorprone.info/bugpattern/BigDecimalLiteralDouble Issue: SPR-15077
1 parent df98d30 commit 3f97ab1

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

spring-jdbc/src/test/java/org/springframework/jdbc/core/JdbcTemplateQueryTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 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.
@@ -197,8 +197,8 @@ public void testQueryForObjectWithBigInteger() throws Exception {
197197
public void testQueryForObjectWithBigDecimal() throws Exception {
198198
String sql = "SELECT AGE FROM CUSTMR WHERE ID = 3";
199199
given(this.resultSet.next()).willReturn(true, false);
200-
given(this.resultSet.getBigDecimal(1)).willReturn(new BigDecimal(22.5));
201-
assertEquals(new BigDecimal(22.5), this.template.queryForObject(sql, BigDecimal.class));
200+
given(this.resultSet.getBigDecimal(1)).willReturn(new BigDecimal("22.5"));
201+
assertEquals(new BigDecimal("22.5"), this.template.queryForObject(sql, BigDecimal.class));
202202
verify(this.resultSet).close();
203203
verify(this.statement).close();
204204
}

0 commit comments

Comments
 (0)