Skip to content

Commit

Permalink
Merge remote-tracking branch 'x/kotlin'
Browse files Browse the repository at this point in the history
  • Loading branch information
codecop committed Oct 3, 2023
2 parents a2f5c09 + cd81636 commit 9b5a3bc
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Kotlin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
build
out
.gradle
.idea
*.iml
33 changes: 33 additions & 0 deletions Kotlin/build.gradle
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 Kotlin/src/main/kotlin/org/codecop/dependencies/b/Assignment.md
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.
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
}
}
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)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mock-maker-inline

0 comments on commit 9b5a3bc

Please sign in to comment.