Skip to content

Commit a4ee52e

Browse files
committed
added DeprecatedTest. updated kotlin version
1 parent d4e8854 commit a4ee52e

File tree

5 files changed

+62
-22
lines changed

5 files changed

+62
-22
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ Coveralls and Cobertura are not good with generated code, so Delegates example w
7070
- `SpringExampleTest` integration with spring framework
7171
- `ObservableTest` observable feature example (kind of value changed listener)
7272
- `Mapping` mapping from Map to class fields example
73+
- `DeprecatedTest` example of kotlin deprecation and tooling of Intellij idea for deprecation
7374

7475
# Ideas
7576
- From reference https://kotlinlang.org/docs/reference/

pom.xml

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
34

45
<modelVersion>4.0.0</modelVersion>
56

@@ -32,13 +33,13 @@
3233

3334
<properties>
3435
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
35-
<kotlin.version>1.2.10</kotlin.version>
36+
<kotlin.version>1.2.21</kotlin.version>
3637
<java.version>1.8</java.version>
3738
<junit.version>4.12</junit.version>
38-
<spring.version>5.0.2.RELEASE</spring.version>
39-
<kotlin.compiler.incremental>true</kotlin.compiler.incremental>
40-
<jacoco.ratio.instruction>0.50</jacoco.ratio.instruction>
41-
<jacoco.ratio.bundle>0.50</jacoco.ratio.bundle>
39+
<spring.version>5.0.3.RELEASE</spring.version>
40+
<kotlin.compiler.incremental>false</kotlin.compiler.incremental>
41+
<jacoco.ratio.instruction>0.87</jacoco.ratio.instruction>
42+
<jacoco.ratio.bundle>0.72</jacoco.ratio.bundle>
4243
</properties>
4344

4445
<dependencies>
@@ -92,18 +93,16 @@
9293
<scope>test</scope>
9394
</dependency>
9495

95-
<dependency>
96-
<groupId>org.jetbrains.kotlin</groupId>
97-
<artifactId>kotlin-test</artifactId>
98-
<version>${kotlin.version}</version>
99-
<scope>test</scope>
100-
</dependency>
101-
10296
</dependencies>
10397

10498
<build>
10599
<sourceDirectory>src/main/kotlin</sourceDirectory>
106100
<testSourceDirectory>src/test/kotlin</testSourceDirectory>
101+
<testResources>
102+
<testResource>
103+
<directory>src/test/resources</directory>
104+
</testResource>
105+
</testResources>
107106

108107
<plugins>
109108
<plugin>
@@ -126,6 +125,14 @@
126125
</goals>
127126
</execution>
128127
</executions>
128+
<configuration>
129+
<experimentalCoroutines>enable</experimentalCoroutines>
130+
<nowarn>false</nowarn>
131+
<args>
132+
<arg>-Xjsr305=strict</arg>
133+
</args>
134+
<jvmTarget>1.8</jvmTarget>
135+
</configuration>
129136
</plugin>
130137

131138
<plugin>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package org.kotlin.examples
2+
3+
import org.junit.Test
4+
import kotlin.ReplaceWith
5+
6+
/**
7+
* Example of using kotlin Intellij tooling for deprecation
8+
*
9+
* https://dzone.com/articles/deprecated-annotation-in-kotlin
10+
*/
11+
class DeprecatedTest {
12+
13+
@Test
14+
fun deprecated() {
15+
val s = ""
16+
assert(isEmpty(s));
17+
}
18+
19+
@Deprecated(message = "we are going to replace with String.isEmpty", replaceWith = ReplaceWith(expression = "input.isEmpty()", imports = ["kotlin.String"]))
20+
fun isEmpty(input: String): Boolean {
21+
return input == ""
22+
}
23+
}

src/test/kotlin/org/kotlin/examples/DollarTest.kt

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ package org.kotlin.examples
33
import org.junit.Test
44
import org.kotlin.examples.override_operators.Dollar
55
import org.slf4j.LoggerFactory
6-
import kotlin.test.assertEquals
7-
import kotlin.test.assertFalse
8-
import kotlin.test.assertTrue
9-
import kotlin.test.fail
6+
import kotlin.test.*
107

118
/**
129
* Created by iurii.dziuban on 01.09.2016.
@@ -101,17 +98,29 @@ class DollarTest {
10198
assertEquals(Dollar(100), dollarProperty.oneDollar)
10299
}
103100

101+
@Test(expected = AssertionError::class)
102+
fun nullAndStringTemplate() {
103+
val dollar = null;
104+
dollar?.let {
105+
LOGGER.info("Dollar is not null")
106+
// not working for properties...
107+
LOGGER.info("Dollar is not null and $dollar.cents")
108+
assertNull(dollar)
109+
return
110+
}
111+
fail("dollar should not be null")
112+
}
113+
104114
@Test
105-
fun nullCheckAndStringTemplate() {
115+
fun nonNullAndStringTemplate() {
106116
val dollar = Dollar(50);
107-
dollar?.let {
117+
dollar.let {
108118
LOGGER.info("Dollar is not null and " + dollar.cents)
109119
// not working for properties...
110120
LOGGER.info("Dollar is not null and $dollar.cents")
111121
assertEquals(Dollar(50), dollar)
112122
return
113123
}
114-
fail("dollar should not be null")
115124
}
116125

117126
@Test

src/test/kotlin/org/kotlin/examples/SpringExampleTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ import kotlin.test.assertEquals
1313
* Simple kotlin spring integration example
1414
*/
1515
@RunWith(SpringJUnit4ClassRunner::class)
16-
@ContextConfiguration(locations = arrayOf("classpath:application-context.xml"))
16+
@ContextConfiguration(locations = ["classpath:application-context.xml"])
1717
class SpringExampleTest {
1818

1919
@Autowired
2020
lateinit var transaction : Transaction
2121

2222
@Test
23-
fun test() {
23+
fun `basic test`() {
2424
assertEquals(2, transaction.id)
2525
assertEquals("Iurii", transaction.name)
2626
}

0 commit comments

Comments
 (0)