Skip to content

Commit 2165121

Browse files
Merge pull request #816 from timis1/BAEL-102141
BAEL-102141 Review warnings in kotlin-build job
2 parents b5bafd1 + 8509a23 commit 2165121

File tree

80 files changed

+210
-162
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+210
-162
lines changed

core-kotlin-modules/core-kotlin-advanced/src/test/kotlin/com/baeldung/reflection/KClassUnitTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class KClassUnitTest {
4343
val listClass = ArrayList::class
4444

4545
val list = listClass.createInstance()
46+
@Suppress("USELESS_IS_CHECK")
4647
assertTrue(list is ArrayList)
4748
}
4849

core-kotlin-modules/core-kotlin-advanced/src/test/kotlin/com/baeldung/reflection/KMethodUnitTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class KMethodUnitTest {
7070
assertEquals("mutableProperty", mProperty.name)
7171
assertTrue(mProperty.isLateinit)
7272
assertFalse(mProperty.isConst)
73+
@Suppress("USELESS_IS_CHECK")
7374
assertTrue(mProperty is KMutableProperty<*>)
7475
}
7576

core-kotlin-modules/core-kotlin-arrays/src/main/kotlin/com/baeldung/array/ArrayAssociate.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.baeldung.array
22

3-
fun main(args: Array<String>) {
3+
fun main() {
44
val fruits = arrayOf("Pear", "Apple", "Papaya", "Banana")
55
println(fruits.associate { Pair(it, it.length) })
66
println(fruits.associateBy { it.length })

core-kotlin-modules/core-kotlin-arrays/src/main/kotlin/com/baeldung/array/ArrayReorder.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fun printArray(array: Array<Int>) {
1111
println()
1212
}
1313

14-
fun main(args: Array<String>) {
14+
fun main() {
1515
var numbers = initArray()
1616
printArray(numbers)
1717

core-kotlin-modules/core-kotlin-arrays/src/main/kotlin/com/baeldung/array/arrayTraversalUnitTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package com.baeldung.array
22

33
val dice = arrayOf(1, 2, 3, 4, 5, 6)
44

5-
fun main(args: Array<String>) {
5+
fun main() {
66
// Traversal using for loop
77
for (faceValue in dice) {
88
println(faceValue)

core-kotlin-modules/core-kotlin-collections-list-2/src/test/kotlin/removeNullAndEmptyValues/RemoveNullAndEmptyValuesUnitTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class RemoveNullAndEmptyValuesUnitTest {
3939
iterator.remove()
4040
}
4141
}
42+
@Suppress("UNCHECKED_CAST")
4243
return listWithNullsAndEmpty as List<String>
4344
}
4445
}

core-kotlin-modules/core-kotlin-collections/src/main/kotlin/com/baeldung/sorting/SortingExample.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ fun <T : kotlin.Comparable<T>> getSimpleComparator() : Comparator<T> {
2525

2626
fun getComplexComparator() {
2727
val complexComparator = compareBy<Pair<Int, String>>({it.first}, {it.second})
28+
print("Complex comparator result: $complexComparator" )
2829
}
2930

3031
fun nullHandlingUsage() {

core-kotlin-modules/core-kotlin-files/src/test/kotlin/com/baeldung/deletefile/DeleteFileUnitTest.kt

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,31 @@ package com.baeldung.deletefile
33
import org.junit.jupiter.api.Assertions.*
44
import org.junit.jupiter.api.Test
55
import java.io.File
6+
import kotlin.io.path.ExperimentalPathApi
7+
import kotlin.io.path.deleteRecursively
8+
import kotlin.io.path.exists
9+
import kotlin.io.path.pathString
610

711
class DeleteFileUnitTest {
812

913
@Test
1014
fun `given file path when deleteFile called then file is deleted`() {
11-
val tempFile = createTempFile()
15+
val tempFile = kotlin.io.path.createTempFile()
1216
assertTrue(tempFile.exists())
1317

14-
deleteFile(tempFile.absolutePath)
18+
deleteFile(tempFile.pathString)
1519

1620
assertFalse(tempFile.exists())
1721
}
1822

1923
@Test
2024
fun `given directory when deleteDirectory called then directory and its contents are deleted`() {
21-
val tempDir = createTempDir()
22-
val tempFileInDir = File(tempDir, "tempFile.txt").apply { createNewFile() }
25+
val tempDir = kotlin.io.path.createTempDirectory()
26+
val tempFileInDir = File(tempDir.toFile(), "tempFile.txt").apply { createNewFile() }
2327
assertTrue(tempDir.exists())
2428
assertTrue(tempFileInDir.exists())
2529

26-
deleteDirectory(tempDir)
30+
deleteDirectory(tempDir.toFile())
2731

2832
assertFalse(tempDir.exists())
2933
assertFalse(tempFileInDir.exists())
@@ -38,17 +42,18 @@ class DeleteFileUnitTest {
3842
}
3943
}
4044

45+
@OptIn(ExperimentalPathApi::class)
4146
@Test
4247
fun `given directory when deleteDirectory called then directory and its contents are deleted recursively`() {
43-
val tempDir = createTempDir()
44-
val innerTempDir = File(tempDir, "innerTempDir").apply { mkdir() }
48+
val tempDir = kotlin.io.path.createTempDirectory()
49+
val innerTempDir = File(tempDir.toFile(), "innerTempDir").apply { mkdir() }
4550
val tempFileInDir = File(innerTempDir, "tempFile.txt").apply { createNewFile() }
4651

4752
assertTrue(tempDir.exists())
4853
assertTrue(innerTempDir.exists())
4954
assertTrue(tempFileInDir.exists())
5055

51-
tempDir.deleteContentsRecursively()
56+
tempDir.deleteRecursively()
5257

5358
assertFalse(tempDir.exists())
5459
assertFalse(innerTempDir.exists())

core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/nullsafety/NullSafetyUnitTest.kt

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class NullSafetyUnitTest {
1111
@Test
1212
fun givenNonNullableField_whenAssignValueToIt_thenNotNeedToCheckAgainstNull() {
1313
//given
14-
var a: String = "value"
14+
val a: String = "value"
1515
//a = null compilation error
1616

1717
//then
@@ -21,15 +21,11 @@ class NullSafetyUnitTest {
2121
@Test
2222
fun givenNullableField_whenReadValue_thenNeedToCheckAgainstNull() {
2323
//given
24-
var b: String? = "value"
24+
val b: String?
2525
b = null
2626

2727
//when
28-
if (b != null) {
29-
30-
} else {
31-
assertNull(b)
32-
}
28+
assertNull(b)
3329
}
3430

3531
@Test
@@ -122,7 +118,7 @@ class NullSafetyUnitTest {
122118
@Test
123119
fun givenNullableField_whenUsingDoubleExclamationMarkOperatorOnNull_thenThrowNPE() {
124120
//given
125-
var b: String? = "value"
121+
val b: String?
126122
b = null
127123

128124
//when

core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/scope/ScopeFunctionsUnitTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class ScopeFunctionsUnitTest {
1010
var called : Boolean = false
1111

1212
fun info(message: String) {
13+
println("Message is: $message")
1314
called = true
1415
}
1516

0 commit comments

Comments
 (0)