Skip to content

Commit 2e44b77

Browse files
authored
Improved task 3220
1 parent 555bf6b commit 2e44b77

File tree

1 file changed

+80
-0
lines changed
  • src/test/kotlin/g3201_3300/s3220_odd_and_even_transactions

1 file changed

+80
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package g3201_3300.s3220_odd_and_even_transactions
2+
3+
import org.hamcrest.CoreMatchers.equalTo
4+
import org.hamcrest.MatcherAssert.assertThat
5+
import org.junit.jupiter.api.Test
6+
import org.zapodot.junit.db.annotations.EmbeddedDatabase
7+
import org.zapodot.junit.db.annotations.EmbeddedDatabaseTest
8+
import org.zapodot.junit.db.common.CompatibilityMode
9+
import java.io.BufferedReader
10+
import java.io.FileNotFoundException
11+
import java.io.FileReader
12+
import java.sql.SQLException
13+
import java.util.stream.Collectors
14+
import javax.sql.DataSource
15+
16+
@EmbeddedDatabaseTest(
17+
compatibilityMode = CompatibilityMode.MySQL,
18+
initialSqls = [
19+
(
20+
"CREATE TABLE transactions(transaction_id INTEGER PRIMARY KEY, amount INTEGER" +
21+
", transaction_date DATE); " +
22+
"INSERT INTO transactions(transaction_id, amount, transaction_date)" +
23+
" VALUES (1, 150, '2024-07-01'); " +
24+
"INSERT INTO transactions(transaction_id, amount, transaction_date)" +
25+
" VALUES (2, 200, '2024-07-01'); " +
26+
"INSERT INTO transactions(transaction_id, amount, transaction_date)" +
27+
" VALUES (3, 75, '2024-07-01'); " +
28+
"INSERT INTO transactions(transaction_id, amount, transaction_date)" +
29+
" VALUES (4, 300, '2024-07-02'); " +
30+
"INSERT INTO transactions(transaction_id, amount, transaction_date)" +
31+
" VALUES (5, 50, '2024-07-02'); " +
32+
"INSERT INTO transactions(transaction_id, amount, transaction_date)" +
33+
" VALUES (6, 120, '2024-07-03'); "
34+
)
35+
]
36+
)
37+
internal class MysqlTest {
38+
@Test
39+
@Throws(SQLException::class, FileNotFoundException::class)
40+
fun testScript(@EmbeddedDatabase dataSource: DataSource) {
41+
dataSource.connection.use { connection ->
42+
connection.createStatement().use { statement ->
43+
statement.executeQuery(
44+
BufferedReader(
45+
FileReader(
46+
"src/main/kotlin/g3201_3300/" +
47+
"s3220_odd_and_even_transactions/script.sql"
48+
)
49+
)
50+
.lines()
51+
.collect(Collectors.joining("\n"))
52+
.replace("#.*?\\r?\\n".toRegex(), "")
53+
).use { resultSet ->
54+
assertThat<Boolean>(resultSet.next(), equalTo<Boolean>(true))
55+
assertThat<String>(
56+
resultSet.getNString(1),
57+
equalTo<String>("2024-07-01")
58+
)
59+
assertThat<String>(resultSet.getNString(2), equalTo<String>("75"))
60+
assertThat<String>(resultSet.getNString(3), equalTo<String>("350"))
61+
assertThat<Boolean>(resultSet.next(), equalTo<Boolean>(true))
62+
assertThat<String>(
63+
resultSet.getNString(1),
64+
equalTo<String>("2024-07-02")
65+
)
66+
assertThat<String>(resultSet.getNString(2), equalTo<String>("0"))
67+
assertThat<String>(resultSet.getNString(3), equalTo<String>("350"))
68+
assertThat<Boolean>(resultSet.next(), equalTo<Boolean>(true))
69+
assertThat<String>(
70+
resultSet.getNString(1),
71+
equalTo<String>("2024-07-03")
72+
)
73+
assertThat<String>(resultSet.getNString(2), equalTo<String>("0"))
74+
assertThat<String>(resultSet.getNString(3), equalTo<String>("120"))
75+
assertThat<Boolean>(resultSet.next(), equalTo<Boolean>(false))
76+
}
77+
}
78+
}
79+
}
80+
}

0 commit comments

Comments
 (0)