Skip to content

Commit 18781e5

Browse files
committed
Polish contribution
See gh-27870
1 parent ed4e228 commit 18781e5

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/H2SequenceMaxValueIncrementer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -23,6 +23,7 @@
2323
* of a given H2 sequence.
2424
*
2525
* @author Thomas Risberg
26+
* @author Henning Pöttker
2627
* @since 2.5
2728
*/
2829
public class H2SequenceMaxValueIncrementer extends AbstractSequenceMaxValueIncrementer {

spring-jdbc/src/test/java/org/springframework/jdbc/support/incrementer/H2SequenceMaxValueIncrementerTests.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,40 @@
1616

1717
package org.springframework.jdbc.support.incrementer;
1818

19-
import javax.sql.DataSource;
20-
2119
import org.junit.jupiter.api.Test;
2220

21+
import org.springframework.jdbc.core.JdbcTemplate;
22+
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
2323
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
2424
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
2525

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

2828
/**
29+
* Integration tests for {@link H2SequenceMaxValueIncrementer}.
30+
*
2931
* @author Henning Pöttker
32+
* @author Sam Brannen
33+
* @since 5.3.15
3034
*/
3135
class H2SequenceMaxValueIncrementerTests {
3236

3337
@Test
34-
void testH2SequenceMaxValueIncrementer() {
35-
DataSource dataSource = new EmbeddedDatabaseBuilder()
38+
void incrementsSequence() {
39+
EmbeddedDatabase database = new EmbeddedDatabaseBuilder()
3640
.setType(EmbeddedDatabaseType.H2)
41+
.generateUniqueName(true)
3742
.addScript("classpath:/org/springframework/jdbc/support/incrementer/schema.sql")
3843
.build();
39-
H2SequenceMaxValueIncrementer incrementer = new H2SequenceMaxValueIncrementer(dataSource, "SEQ");
4044

41-
assertThat(incrementer.nextIntValue()).isEqualTo(1);
42-
assertThat(incrementer.nextStringValue()).isEqualTo("2");
45+
JdbcTemplate jdbcTemplate = new JdbcTemplate(database);
46+
assertThat(jdbcTemplate.queryForObject("values next value for SEQ", int.class)).isEqualTo(1);
47+
48+
H2SequenceMaxValueIncrementer incrementer = new H2SequenceMaxValueIncrementer(database, "SEQ");
49+
assertThat(incrementer.nextIntValue()).isEqualTo(2);
50+
assertThat(incrementer.nextStringValue()).isEqualTo("3");
51+
52+
database.shutdown();
4353
}
4454

4555
}

0 commit comments

Comments
 (0)