Skip to content

Try with resources implementation in JUnit FW - Part 1#520

Merged
cheenamalhotra merged 8 commits intomicrosoft:devfrom
cheenamalhotra:JavaImprovements
Oct 10, 2017
Merged

Try with resources implementation in JUnit FW - Part 1#520
cheenamalhotra merged 8 commits intomicrosoft:devfrom
cheenamalhotra:JavaImprovements

Conversation

@cheenamalhotra
Copy link
Copy Markdown
Member

Improvements in JUnit Tests:

try-with-resources is available since Java 7 and must be used for defining closeable class objects eg, Connection, Statement, PreparedStatement, ResultSet, Streams, etc. It not only reduces code length, but ensures closure of objects preventing object leaks and also improves code readability. It doesn't make much impact on performance, but prevents memory leaks.

  • A few class level connection and statement objects have been removed as they were being initialized in all class functions.
  • Statement objects are passed in a few functions instead of using class variables to maintain encapsulation.
  • try-with-resources is avoided in places where connection and statement objects need not be re-initialized and can be reused in a single class. (A few existing classes may need to be modified to reuse connection to improve test running speed, but will be implemented as part of separate PR)

Since lot of files are impacted by this change, it will be pushed in parts.

@cheenamalhotra cheenamalhotra changed the title Try with resources implementation - Part 1 Try with resources implementation in JUnit FW - Part 1 Oct 4, 2017
@codecov-io
Copy link
Copy Markdown

codecov-io commented Oct 4, 2017

Codecov Report

Merging #520 into dev will increase coverage by 0.1%.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff             @@
##                dev     #520     +/-   ##
===========================================
+ Coverage     46.55%   46.65%   +0.1%     
- Complexity     2221     2226      +5     
===========================================
  Files           108      108             
  Lines         25316    25316             
  Branches       4182     4182             
===========================================
+ Hits          11785    11811     +26     
+ Misses        11501    11473     -28     
- Partials       2030     2032      +2
Flag Coverage Δ Complexity Δ
#JDBC41 46.34% <ø> (+0.06%) 2209 <ø> (+3) ⬆️
#JDBC42 46.58% <ø> (+0.08%) 2224 <ø> (+5) ⬆️
Impacted Files Coverage Δ Complexity Δ
...c/main/java/com/microsoft/sqlserver/jdbc/Util.java 59.17% <0%> (-1.08%) 88% <0%> (-2%)
...in/java/com/microsoft/sqlserver/jdbc/IOBuffer.java 53.88% <0%> (-0.07%) 0% <0%> (ø)
...om/microsoft/sqlserver/jdbc/SQLServerBulkCopy.java 52.7% <0%> (-0.07%) 238% <0%> (-3%)
.../microsoft/sqlserver/jdbc/SQLServerConnection.java 45.98% <0%> (-0.04%) 277% <0%> (ø)
...m/microsoft/sqlserver/jdbc/SQLServerStatement.java 59.47% <0%> (+0.1%) 131% <0%> (+1%) ⬆️
...m/microsoft/sqlserver/jdbc/SQLServerResultSet.java 33.06% <0%> (+0.24%) 244% <0%> (+2%) ⬆️
...rc/main/java/com/microsoft/sqlserver/jdbc/dtv.java 63.24% <0%> (+0.48%) 0% <0%> (ø) ⬇️
...rc/main/java/com/microsoft/sqlserver/jdbc/DDC.java 44.81% <0%> (+1.57%) 105% <0%> (+2%) ⬆️
...om/microsoft/sqlserver/jdbc/ReaderInputStream.java 44.94% <0%> (+3.37%) 16% <0%> (+2%) ⬆️
...oft/sqlserver/jdbc/SQLServerBulkCSVFileRecord.java 45.92% <0%> (+4.29%) 30% <0%> (+2%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b8daa42...eb7efe3. Read the comment docs.

@cheenamalhotra cheenamalhotra merged commit e7b68fd into microsoft:dev Oct 10, 2017
@cheenamalhotra cheenamalhotra added this to the 6.3.4 milestone Oct 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants