@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
/ *
* Copyright 2002 - 2019 the original author or authors .
* Copyright 2002 - 202 1 the original author or authors .
*
* Licensed under the Apache License , Version 2 . 0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
@ -25,6 +25,7 @@ import javax.sql.DataSource;
@@ -25,6 +25,7 @@ import javax.sql.DataSource;
import org.junit.jupiter.api.Test ;
import org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer ;
import org.springframework.jdbc.support.incrementer.HanaSequenceMaxValueIncrementer ;
import org.springframework.jdbc.support.incrementer.HsqlMaxValueIncrementer ;
import org.springframework.jdbc.support.incrementer.MySQLMaxValueIncrementer ;
@ -38,10 +39,13 @@ import static org.mockito.Mockito.times;
@@ -38,10 +39,13 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify ;
/ * *
* Unit tests for { @link DataFieldMaxValueIncrementer } implementations .
*
* @author Juergen Hoeller
* @author Sam Brannen
* @since 27 . 02 . 2004
* /
public class DataFieldMaxValueIncrementerTests {
class DataFieldMaxValueIncrementerTests {
private final DataSource dataSource = mock ( DataSource . class ) ;
@ -53,7 +57,7 @@ public class DataFieldMaxValueIncrementerTests {
@@ -53,7 +57,7 @@ public class DataFieldMaxValueIncrementerTests {
@Test
public void testH anaSequenceMaxValueIncrementer( ) throws SQLException {
void h anaSequenceMaxValueIncrementer( ) throws SQLException {
given ( dataSource . getConnection ( ) ) . willReturn ( connection ) ;
given ( connection . createStatement ( ) ) . willReturn ( statement ) ;
given ( statement . executeQuery ( "select myseq.nextval from dummy" ) ) . willReturn ( resultSet ) ;
@ -75,7 +79,7 @@ public class DataFieldMaxValueIncrementerTests {
@@ -75,7 +79,7 @@ public class DataFieldMaxValueIncrementerTests {
}
@Test
public void testH sqlMaxValueIncrementer( ) throws SQLException {
void h sqlMaxValueIncrementer( ) throws SQLException {
given ( dataSource . getConnection ( ) ) . willReturn ( connection ) ;
given ( connection . createStatement ( ) ) . willReturn ( statement ) ;
given ( statement . executeQuery ( "select max(identity()) from myseq" ) ) . willReturn ( resultSet ) ;
@ -105,7 +109,7 @@ public class DataFieldMaxValueIncrementerTests {
@@ -105,7 +109,7 @@ public class DataFieldMaxValueIncrementerTests {
}
@Test
public void testH sqlMaxValueIncrementerWithDeleteSpecificValues( ) throws SQLException {
void h sqlMaxValueIncrementerWithDeleteSpecificValues( ) throws SQLException {
given ( dataSource . getConnection ( ) ) . willReturn ( connection ) ;
given ( connection . createStatement ( ) ) . willReturn ( statement ) ;
given ( statement . executeQuery ( "select max(identity()) from myseq" ) ) . willReturn ( resultSet ) ;
@ -136,7 +140,7 @@ public class DataFieldMaxValueIncrementerTests {
@@ -136,7 +140,7 @@ public class DataFieldMaxValueIncrementerTests {
}
@Test
public void testM ySQLMaxValueIncrementer( ) throws SQLException {
void m ySQLMaxValueIncrementer( ) throws SQLException {
given ( dataSource . getConnection ( ) ) . willReturn ( connection ) ;
given ( connection . createStatement ( ) ) . willReturn ( statement ) ;
given ( statement . executeQuery ( "select last_insert_id()" ) ) . willReturn ( resultSet ) ;
@ -156,14 +160,14 @@ public class DataFieldMaxValueIncrementerTests {
@@ -156,14 +160,14 @@ public class DataFieldMaxValueIncrementerTests {
assertThat ( incrementer . nextStringValue ( ) ) . isEqualTo ( "3" ) ;
assertThat ( incrementer . nextLongValue ( ) ) . isEqualTo ( 4 ) ;
verify ( statement , times ( 2 ) ) . executeUpdate ( "update myseq set seq = last_insert_id(seq + 2)" ) ;
verify ( statement , times ( 2 ) ) . executeUpdate ( "update myseq set seq = last_insert_id(seq + 2) limit 1 " ) ;
verify ( resultSet , times ( 2 ) ) . close ( ) ;
verify ( statement , times ( 2 ) ) . close ( ) ;
verify ( connection , times ( 2 ) ) . close ( ) ;
}
@Test
public void testO racleSequenceMaxValueIncrementer( ) throws SQLException {
void o racleSequenceMaxValueIncrementer( ) throws SQLException {
given ( dataSource . getConnection ( ) ) . willReturn ( connection ) ;
given ( connection . createStatement ( ) ) . willReturn ( statement ) ;
given ( statement . executeQuery ( "select myseq.nextval from dual" ) ) . willReturn ( resultSet ) ;
@ -185,7 +189,7 @@ public class DataFieldMaxValueIncrementerTests {
@@ -185,7 +189,7 @@ public class DataFieldMaxValueIncrementerTests {
}
@Test
public void testP ostgresSequenceMaxValueIncrementer( ) throws SQLException {
void p ostgresSequenceMaxValueIncrementer( ) throws SQLException {
given ( dataSource . getConnection ( ) ) . willReturn ( connection ) ;
given ( connection . createStatement ( ) ) . willReturn ( statement ) ;
given ( statement . executeQuery ( "select nextval('myseq')" ) ) . willReturn ( resultSet ) ;