Skip to content

Commit d856776

Browse files
committed
kotlin: change :one to rely on null assertions
1 parent a3d663a commit d856776

File tree

20 files changed

+48
-48
lines changed

20 files changed

+48
-48
lines changed

examples/kotlin/src/main/kotlin/com/example/authors/mysql/Queries.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ interface Queries {
1414
fun deleteAuthor(id: Long)
1515

1616
@Throws(SQLException::class)
17-
fun getAuthor(id: Long): Author
17+
fun getAuthor(id: Long): Author?
1818

1919
@Throws(SQLException::class)
2020
fun listAuthors(): List<Author>

examples/kotlin/src/main/kotlin/com/example/authors/mysql/QueriesImpl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class QueriesImpl(private val conn: Connection) : Queries {
5757
}
5858

5959
@Throws(SQLException::class)
60-
override fun getAuthor(id: Long): Author {
60+
override fun getAuthor(id: Long): Author? {
6161
return conn.prepareStatement(getAuthor).use { stmt ->
6262
stmt.setLong(1, id)
6363

examples/kotlin/src/main/kotlin/com/example/authors/postgresql/Queries.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ import java.sql.Statement
88

99
interface Queries {
1010
@Throws(SQLException::class)
11-
fun createAuthor(name: String, bio: String?): Author
11+
fun createAuthor(name: String, bio: String?): Author?
1212

1313
@Throws(SQLException::class)
1414
fun deleteAuthor(id: Long)
1515

1616
@Throws(SQLException::class)
17-
fun getAuthor(id: Long): Author
17+
fun getAuthor(id: Long): Author?
1818

1919
@Throws(SQLException::class)
2020
fun listAuthors(): List<Author>

examples/kotlin/src/main/kotlin/com/example/authors/postgresql/QueriesImpl.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ ORDER BY name
3333
class QueriesImpl(private val conn: Connection) : Queries {
3434

3535
@Throws(SQLException::class)
36-
override fun createAuthor(name: String, bio: String?): Author {
36+
override fun createAuthor(name: String, bio: String?): Author? {
3737
return conn.prepareStatement(createAuthor).use { stmt ->
3838
stmt.setString(1, name)
3939
stmt.setString(2, bio)
@@ -64,7 +64,7 @@ class QueriesImpl(private val conn: Connection) : Queries {
6464
}
6565

6666
@Throws(SQLException::class)
67-
override fun getAuthor(id: Long): Author {
67+
override fun getAuthor(id: Long): Author? {
6868
return conn.prepareStatement(getAuthor).use { stmt ->
6969
stmt.setLong(1, id)
7070

examples/kotlin/src/main/kotlin/com/example/booktest/mysql/Queries.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ interface Queries {
3434
fun deleteBook(bookId: Int)
3535

3636
@Throws(SQLException::class)
37-
fun getAuthor(authorId: Int): Author
37+
fun getAuthor(authorId: Int): Author?
3838

3939
@Throws(SQLException::class)
40-
fun getBook(bookId: Int): Book
40+
fun getBook(bookId: Int): Book?
4141

4242
@Throws(SQLException::class)
4343
fun updateBook(

examples/kotlin/src/main/kotlin/com/example/booktest/mysql/QueriesImpl.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ class QueriesImpl(private val conn: Connection) : Queries {
197197
}
198198

199199
@Throws(SQLException::class)
200-
override fun getAuthor(authorId: Int): Author {
200+
override fun getAuthor(authorId: Int): Author? {
201201
return conn.prepareStatement(getAuthor).use { stmt ->
202202
stmt.setInt(1, authorId)
203203

@@ -217,7 +217,7 @@ class QueriesImpl(private val conn: Connection) : Queries {
217217
}
218218

219219
@Throws(SQLException::class)
220-
override fun getBook(bookId: Int): Book {
220+
override fun getBook(bookId: Int): Book? {
221221
return conn.prepareStatement(getBook).use { stmt ->
222222
stmt.setInt(1, bookId)
223223

examples/kotlin/src/main/kotlin/com/example/booktest/postgresql/Queries.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ interface Queries {
1616
fun booksByTitleYear(title: String, year: Int): List<Book>
1717

1818
@Throws(SQLException::class)
19-
fun createAuthor(name: String): Author
19+
fun createAuthor(name: String): Author?
2020

2121
@Throws(SQLException::class)
2222
fun createBook(
@@ -26,16 +26,16 @@ interface Queries {
2626
title: String,
2727
year: Int,
2828
available: OffsetDateTime,
29-
tags: List<String>): Book
29+
tags: List<String>): Book?
3030

3131
@Throws(SQLException::class)
3232
fun deleteBook(bookId: Int)
3333

3434
@Throws(SQLException::class)
35-
fun getAuthor(authorId: Int): Author
35+
fun getAuthor(authorId: Int): Author?
3636

3737
@Throws(SQLException::class)
38-
fun getBook(bookId: Int): Book
38+
fun getBook(bookId: Int): Book?
3939

4040
@Throws(SQLException::class)
4141
fun updateBook(

examples/kotlin/src/main/kotlin/com/example/booktest/postgresql/QueriesImpl.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class QueriesImpl(private val conn: Connection) : Queries {
133133
}
134134

135135
@Throws(SQLException::class)
136-
override fun createAuthor(name: String): Author {
136+
override fun createAuthor(name: String): Author? {
137137
return conn.prepareStatement(createAuthor).use { stmt ->
138138
stmt.setString(1, name)
139139

@@ -160,7 +160,7 @@ class QueriesImpl(private val conn: Connection) : Queries {
160160
title: String,
161161
year: Int,
162162
available: OffsetDateTime,
163-
tags: List<String>): Book {
163+
tags: List<String>): Book? {
164164
return conn.prepareStatement(createBook).use { stmt ->
165165
stmt.setInt(1, authorId)
166166
stmt.setString(2, isbn)
@@ -201,7 +201,7 @@ class QueriesImpl(private val conn: Connection) : Queries {
201201
}
202202

203203
@Throws(SQLException::class)
204-
override fun getAuthor(authorId: Int): Author {
204+
override fun getAuthor(authorId: Int): Author? {
205205
return conn.prepareStatement(getAuthor).use { stmt ->
206206
stmt.setInt(1, authorId)
207207

@@ -221,7 +221,7 @@ class QueriesImpl(private val conn: Connection) : Queries {
221221
}
222222

223223
@Throws(SQLException::class)
224-
override fun getBook(bookId: Int): Book {
224+
override fun getBook(bookId: Int): Book? {
225225
return conn.prepareStatement(getBook).use { stmt ->
226226
stmt.setInt(1, bookId)
227227

examples/kotlin/src/main/kotlin/com/example/jets/Queries.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import java.sql.Statement
88

99
interface Queries {
1010
@Throws(SQLException::class)
11-
fun countPilots(): Long
11+
fun countPilots(): Long?
1212

1313
@Throws(SQLException::class)
1414
fun deletePilot(id: Int)

examples/kotlin/src/main/kotlin/com/example/jets/QueriesImpl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ SELECT id, name FROM pilots LIMIT 5
2121
class QueriesImpl(private val conn: Connection) : Queries {
2222

2323
@Throws(SQLException::class)
24-
override fun countPilots(): Long {
24+
override fun countPilots(): Long? {
2525
return conn.prepareStatement(countPilots).use { stmt ->
2626

2727
val results = stmt.executeQuery()

examples/kotlin/src/main/kotlin/com/example/ondeck/mysql/Queries.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ interface Queries {
2626
fun deleteVenue(slug: String, slug_2: String)
2727

2828
@Throws(SQLException::class)
29-
fun getCity(slug: String): City
29+
fun getCity(slug: String): City?
3030

3131
@Throws(SQLException::class)
32-
fun getVenue(slug: String, city: String): Venue
32+
fun getVenue(slug: String, city: String): Venue?
3333

3434
@Throws(SQLException::class)
3535
fun listCities(): List<City>

examples/kotlin/src/main/kotlin/com/example/ondeck/mysql/QueriesImpl.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ class QueriesImpl(private val conn: Connection) : Queries {
147147
}
148148

149149
@Throws(SQLException::class)
150-
override fun getCity(slug: String): City {
150+
override fun getCity(slug: String): City? {
151151
return conn.prepareStatement(getCity).use { stmt ->
152152
stmt.setString(1, slug)
153153

@@ -167,7 +167,7 @@ class QueriesImpl(private val conn: Connection) : Queries {
167167
}
168168

169169
@Throws(SQLException::class)
170-
override fun getVenue(slug: String, city: String): Venue {
170+
override fun getVenue(slug: String, city: String): Venue? {
171171
return conn.prepareStatement(getVenue).use { stmt ->
172172
stmt.setString(1, slug)
173173
stmt.setString(2, city)

examples/kotlin/src/main/kotlin/com/example/ondeck/postgresql/Queries.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import java.time.LocalDateTime
1010

1111
interface Queries {
1212
@Throws(SQLException::class)
13-
fun createCity(name: String, slug: String): City
13+
fun createCity(name: String, slug: String): City?
1414

1515
@Throws(SQLException::class)
1616
fun createVenue(
@@ -20,16 +20,16 @@ interface Queries {
2020
spotifyPlaylist: String,
2121
status: Status,
2222
statuses: List<Status>,
23-
tags: List<String>): Int
23+
tags: List<String>): Int?
2424

2525
@Throws(SQLException::class)
2626
fun deleteVenue(slug: String)
2727

2828
@Throws(SQLException::class)
29-
fun getCity(slug: String): City
29+
fun getCity(slug: String): City?
3030

3131
@Throws(SQLException::class)
32-
fun getVenue(slug: String, city: String): Venue
32+
fun getVenue(slug: String, city: String): Venue?
3333

3434
@Throws(SQLException::class)
3535
fun listCities(): List<City>
@@ -41,7 +41,7 @@ interface Queries {
4141
fun updateCityName(name: String, slug: String)
4242

4343
@Throws(SQLException::class)
44-
fun updateVenueName(name: String, slug: String): Int
44+
fun updateVenueName(name: String, slug: String): Int?
4545

4646
@Throws(SQLException::class)
4747
fun venueCountByCity(): List<VenueCountByCityRow>

examples/kotlin/src/main/kotlin/com/example/ondeck/postgresql/QueriesImpl.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class QueriesImpl(private val conn: Connection) : Queries {
104104
// This is the third line
105105

106106
@Throws(SQLException::class)
107-
override fun createCity(name: String, slug: String): City {
107+
override fun createCity(name: String, slug: String): City? {
108108
return conn.prepareStatement(createCity).use { stmt ->
109109
stmt.setString(1, name)
110110
stmt.setString(2, slug)
@@ -132,7 +132,7 @@ class QueriesImpl(private val conn: Connection) : Queries {
132132
spotifyPlaylist: String,
133133
status: Status,
134134
statuses: List<Status>,
135-
tags: List<String>): Int {
135+
tags: List<String>): Int? {
136136
return conn.prepareStatement(createVenue).use { stmt ->
137137
stmt.setString(1, slug)
138138
stmt.setString(2, name)
@@ -165,7 +165,7 @@ class QueriesImpl(private val conn: Connection) : Queries {
165165
}
166166

167167
@Throws(SQLException::class)
168-
override fun getCity(slug: String): City {
168+
override fun getCity(slug: String): City? {
169169
return conn.prepareStatement(getCity).use { stmt ->
170170
stmt.setString(1, slug)
171171

@@ -185,7 +185,7 @@ class QueriesImpl(private val conn: Connection) : Queries {
185185
}
186186

187187
@Throws(SQLException::class)
188-
override fun getVenue(slug: String, city: String): Venue {
188+
override fun getVenue(slug: String, city: String): Venue? {
189189
return conn.prepareStatement(getVenue).use { stmt ->
190190
stmt.setString(1, slug)
191191
stmt.setString(2, city)
@@ -265,7 +265,7 @@ class QueriesImpl(private val conn: Connection) : Queries {
265265
}
266266

267267
@Throws(SQLException::class)
268-
override fun updateVenueName(name: String, slug: String): Int {
268+
override fun updateVenueName(name: String, slug: String): Int? {
269269
return conn.prepareStatement(updateVenueName).use { stmt ->
270270
stmt.setString(1, name)
271271
stmt.setString(2, slug)

examples/kotlin/src/test/kotlin/com/example/authors/postgresql/QueriesImplTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class QueriesImplTest() {
2525
val insertedAuthor = db.createAuthor(
2626
name = name,
2727
bio = bio
28-
)
28+
)!!
2929
val expectedAuthor = Author(insertedAuthor.id, name, bio)
3030
Assertions.assertEquals(expectedAuthor, insertedAuthor)
3131

@@ -46,7 +46,7 @@ class QueriesImplTest() {
4646

4747
val name = "Brian Kernighan"
4848
val bio = null
49-
val insertedAuthor = db.createAuthor(name, bio)
49+
val insertedAuthor = db.createAuthor(name, bio)!!
5050
val expectedAuthor = Author(insertedAuthor.id, name, bio)
5151
Assertions.assertEquals(expectedAuthor, insertedAuthor)
5252

examples/kotlin/src/test/kotlin/com/example/booktest/mysql/QueriesImplTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class QueriesImplTest {
1818
val conn = dbtest.getConnection()
1919
val db = QueriesImpl(conn)
2020
val authorId = db.createAuthor("Unknown Master")
21-
val author = db.getAuthor(authorId.toInt())
21+
val author = db.getAuthor(authorId.toInt())!!
2222

2323
// Start a transaction
2424
conn.autoCommit = false
@@ -84,7 +84,7 @@ class QueriesImplTest {
8484
val formatter = DateTimeFormatter.ISO_DATE_TIME
8585
for (book in books0) {
8686
println("Book ${book.bookId} (${book.bookType}): ${book.title} available: ${book.available.format(formatter)}")
87-
val author2 = db.getAuthor(book.authorId)
87+
val author2 = db.getAuthor(book.authorId)!!
8888
println("Book ${book.bookId} author: ${author2.name}")
8989
}
9090

examples/kotlin/src/test/kotlin/com/example/booktest/postgresql/QueriesImplTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class QueriesImplTest {
1515
fun testQueries() {
1616
val conn = dbtest.getConnection()
1717
val db = QueriesImpl(conn)
18-
val author = db.createAuthor("Unknown Master")
18+
val author = db.createAuthor("Unknown Master")!!
1919

2020
// Start a transaction
2121
conn.autoCommit = false
@@ -37,7 +37,7 @@ class QueriesImplTest {
3737
year = 2016,
3838
available = OffsetDateTime.now(),
3939
tags = listOf("cool", "unique")
40-
)
40+
)!!
4141

4242
db.updateBook(
4343
bookId = b1.bookId,
@@ -53,7 +53,7 @@ class QueriesImplTest {
5353
year = 2001,
5454
available = OffsetDateTime.now(),
5555
tags = listOf("cool")
56-
)
56+
)!!
5757

5858
db.createBook(
5959
authorId = author.authorId,
@@ -83,7 +83,7 @@ class QueriesImplTest {
8383
val formatter = DateTimeFormatter.ISO_DATE_TIME
8484
for (book in books0) {
8585
println("Book ${book.bookId} (${book.bookType}): ${book.title} available: ${book.available.format(formatter)}")
86-
val author2 = db.getAuthor(book.authorId)
86+
val author2 = db.getAuthor(book.authorId)!!
8787
println("Book ${book.bookId} author: ${author2.name}")
8888
}
8989

examples/kotlin/src/test/kotlin/com/example/ondeck/mysql/QueriesImplTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class QueriesImplTest {
3232
val venue = q.getVenue(
3333
slug = "the-fillmore",
3434
city = city.slug
35-
)
35+
)!!
3636
assertEquals(venueId, venue.id)
3737

3838
assertEquals(city, q.getCity(city.slug))
@@ -42,7 +42,7 @@ class QueriesImplTest {
4242

4343
q.updateCityName(slug = city.slug, name = "SF")
4444
q.updateVenueName(slug = venue.slug, name = "Fillmore")
45-
val fresh = q.getVenue(venue.slug, city.slug)
45+
val fresh = q.getVenue(venue.slug, city.slug)!!
4646
assertEquals("Fillmore", fresh.name)
4747

4848
q.deleteVenue(venue.slug, venue.slug)

examples/kotlin/src/test/kotlin/com/example/ondeck/postgresql/QueriesImplTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class QueriesImplTest {
1616
val city = q.createCity(
1717
slug = "san-francisco",
1818
name = "San Francisco"
19-
)
19+
)!!
2020
val venueId = q.createVenue(
2121
slug = "the-fillmore",
2222
name = "The Fillmore",
@@ -29,7 +29,7 @@ class QueriesImplTest {
2929
val venue = q.getVenue(
3030
slug = "the-fillmore",
3131
city = city.slug
32-
)
32+
)!!
3333
assertEquals(venueId, venue.id)
3434

3535
assertEquals(city, q.getCity(city.slug))

0 commit comments

Comments
 (0)