package com.tqdev.metrics.jdbc;

import static org.assertj.core.api.Assertions.assertThat;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.junit.Before;
import org.junit.Test;

public class InstrumentedDataSourceTest extends InstrumentedDataSourceTestBase {

	@Before
	public void initialize() {
		registry.reset();
	}

	@Test
	public void shouldMeasureSelectSingleUserOnceWithPreparedStatement() throws SQLException {
		String sql = "select * from users where id = ?";
		PreparedStatement statement = dataSource.getConnection().prepareStatement(sql);
		statement.setInt(1, 1);
		ResultSet resultSet = statement.executeQuery();
		assertThat(resultSet).isInstanceOf(ResultSet.class);
		assertThat(registry.get("jdbc.Statement.Invocations", sql)).isEqualTo(1);
		assertThat(registry.get("jdbc.Statement.Durations", sql)).isEqualTo(123456789);
	}

	@Test
	public void shouldMeasureSelectSingleUserTwiceWithPreparedStatement() throws SQLException {
		String sql = "select * from users where id = ?";
		PreparedStatement statement = dataSource.getConnection().prepareStatement(sql);
		statement.setInt(1, 1);
		statement.executeQuery();
		statement.executeQuery();
		assertThat(registry.get("jdbc.Statement.Invocations", sql)).isEqualTo(2);
		assertThat(registry.get("jdbc.Statement.Durations", sql)).isEqualTo(246913578);
	}

}
@@ -124,35 +124,8 @@
 nt;%0A
-import java.sql.ResultSet;%0A
 impo
@@ -150,16 +150,16 @@
 eption;%0A
+
 %0Aimport 
@@ -607,30 +607,19 @@
 ;%0A%09%09
-ResultSet resultSet = 
+assertThat(
 stat
@@ -642,62 +642,20 @@
 ry()
-;%0A%09%09assertThat(resultSet).isInstanceOf(ResultSet.class
+).isNotNull(
 );%0A%09
@@ -1072,24 +1072,35 @@
 nt(1, 1);%0A%09%09
+assertThat(
 statement.ex
@@ -1111,20 +1111,44 @@
 eQuery()
-;%0A%09%09
+).isNotNull();%0A%09%09assertThat(
 statemen
@@ -1163,16 +1163,29 @@
 eQuery()
+).isNotNull()
 ;%0A%09%09asse

Improve tests