-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'x/kotlin'
- Loading branch information
Showing
6 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
build | ||
out | ||
.gradle | ||
.idea | ||
*.iml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
apply plugin: 'kotlin' | ||
|
||
buildscript { | ||
ext { | ||
kotlin_version = "1.2+" | ||
} | ||
repositories { | ||
mavenCentral() | ||
} | ||
dependencies { | ||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" | ||
classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.1' | ||
} | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" | ||
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version" | ||
testCompile "org.jetbrains.kotlin:kotlin-test:$kotlin_version" | ||
testCompile "org.assertj:assertj-core:3.8.0" | ||
testCompile "org.mockito:mockito-core:2.12.0" | ||
testCompile "com.nhaarman:mockito-kotlin:1.6.0" | ||
testCompile "junit:junit:4.12" | ||
testCompile "pl.pragmatists:JUnitParams:1.1.1" | ||
} | ||
|
||
task wrapper(type: Wrapper) { | ||
gradleVersion = "4.1" | ||
} |
32 changes: 32 additions & 0 deletions
32
Kotlin/src/main/kotlin/org/codecop/dependencies/b/Assignment.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
Assignment B | ||
============ | ||
|
||
Goal | ||
---- | ||
|
||
We have some legacy code. We need to make changes. | ||
To make changes we need to introduce tests first. | ||
We might have to change some code to enable testing. | ||
We need to introduce so-called Seams (see Michael | ||
Feathers' Working Effectively with Legacy Code). | ||
Changing code without test is risky, so we want to | ||
|
||
* Only change as little code as possible. | ||
* Rely on automated Refactoring tools as much as possible. | ||
* You must not change the public API of the class. | ||
|
||
Problem Category | ||
---------------- | ||
|
||
The system under test contains non deterministic behaviour, | ||
which is located in a few methods. The system under test can | ||
be sub-classed. | ||
|
||
Task | ||
---- | ||
|
||
The given `MarketingCampaign` controls the marketing actions which | ||
run on our online shop. During campaigns we e.g. offer discounts. | ||
|
||
* Bring `MarketingCampaign` under test. Make sure to cover all paths in the core logic. | ||
* There is an existing `MarketingCampaignTest` with a first test case which might or might not work. |
22 changes: 22 additions & 0 deletions
22
Kotlin/src/main/kotlin/org/codecop/dependencies/b/MarketingCampaign.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.codecop.dependencies.b | ||
|
||
import java.time.DayOfWeek | ||
import java.time.LocalDateTime | ||
|
||
class MarketingCampaign { | ||
fun isActive(): Boolean { | ||
return milliSeconds() % 2 == 0L | ||
} | ||
|
||
private fun milliSeconds(): Long { | ||
return System.currentTimeMillis() | ||
} | ||
|
||
fun isCrazySalesDay(): Boolean { | ||
return dayOfWeek().compareTo(DayOfWeek.FRIDAY) == 0 | ||
} | ||
|
||
protected fun dayOfWeek(): DayOfWeek { | ||
return LocalDateTime.now().dayOfWeek | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
Kotlin/src/test/kotlin/org/codecop/dependencies/b/MarketingCampaignTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.codecop.dependencies.b | ||
|
||
import org.junit.Assert.assertFalse | ||
import org.junit.Test | ||
|
||
class MarketingCampaignTest { | ||
|
||
@Test | ||
fun test2() { | ||
val campaign = MarketingCampaign() | ||
|
||
val isCrazySalesDay = campaign.isCrazySalesDay() | ||
|
||
assertFalse(isCrazySalesDay) | ||
} | ||
|
||
} |
1 change: 1 addition & 0 deletions
1
Kotlin/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
mock-maker-inline |