Skip to content

Commit

Permalink
Make tests more coverage, also other things
Browse files Browse the repository at this point in the history
  • Loading branch information
OAarne committed Apr 24, 2018
1 parent 5c5f479 commit d077e08
Show file tree
Hide file tree
Showing 13 changed files with 157 additions and 79 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ It can be used to collect and organize sources and research notes.

### Usage

Data will be loaded from and saved to `sources.json`, which will be created if it does not exist in the working directory

#### With the .zip

Unzip the distribution wherever and run `bin/zhuLi`.

#### From the repo

__All of the commands below are to be called from the zhuLi directory (not the root of the git repo!)__

zhuLi can be run by calling `./gradlew run`
Expand All @@ -22,4 +30,6 @@ The sources are pulled from `zhuLi/sampleSources.json`
Test report can be generated by calling `gradle jacocoTestReport`

Style can be checked (using ktlint) by calling `gradle check`.
If it doesn't say anything that means that there are no errors.
If it doesn't say anything that means that there are no errors.

Run `./gradlew assembleDist` to generate distributions in both zip and tarball form.
38 changes: 27 additions & 11 deletions zhuLi/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,25 @@ apply plugin: 'maven'
apply plugin: 'kotlin'
apply plugin: 'application'
apply plugin: 'jacoco'
apply plugin: 'com.github.johnrengelman.plugin-shadow'

mainClassName = "zhuLi.Main"
mainClassName = "zhuLi.MainKt"
group = 'zhuLi'
version = '1.0-SNAPSHOT'
version = '0.1'

buildscript {
ext.kotlin_version = '1.2.31'
ext.tornadofx_version = '1.7.15'

repositories {
mavenCentral()
jcenter()
}

dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'no.tornado:fxlauncher-gradle-plugin:1.0.15'
classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.3'
}

}
Expand Down Expand Up @@ -56,14 +59,6 @@ dependencies {
testCompile group: 'org.jetbrains.kotlin', name: 'kotlin-test', version:'1.2.31'
}

task ktlint(type: JavaExec, group: "verification") {
description = "Check Kotlin code style."
classpath = configurations.ktlint
main = "com.github.shyiko.ktlint.Main"
args "src/**/*.kt"
}
check.dependsOn ktlint

task ktlintFormat(type: JavaExec, group: "formatting") {
description = "Fix Kotlin code style deviations."
classpath = configurations.ktlint
Expand All @@ -74,11 +69,24 @@ task ktlintFormat(type: JavaExec, group: "formatting") {
}
}

task ktlint(type: JavaExec, group: "verification") {
description = "Check Kotlin code style."
classpath = configurations.ktlint
main = "com.github.shyiko.ktlint.Main"
args "src/**/*.kt"
}
check.dependsOn ktlint

jacoco {
toolVersion = "0.8.0"
}

jacocoTestReport {
afterEvaluate {
classDirectories = files(classDirectories.files.collect {
fileTree(dir: it, exclude: '**/ui/**')
})
}
reports {
xml.enabled true
csv.enabled true
Expand All @@ -88,4 +96,12 @@ jacocoTestReport {

sourceSets {
test.kotlin.srcDirs += 'src/test'
}
}

jar {
manifest {
attributes 'Main-Class': 'zhuLi.MainKt'
}
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
}

10 changes: 6 additions & 4 deletions zhuLi/documentation/todo.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@

#### Other stuff
* Make a way to generate runnable jar and add it to readme
* min 20% test coverage
* Exclude UI code from test report
* Keep the hours logged
* Make a sequence diagram of a central part of the program's functionality (making and saving a change?)
* Clean up the readme and add a more detailed user's manual
* Add a more detailed user's manual
* Make a release


### Extra Credit
* Make a sequence diagram of a central part of the program's functionality (making and saving a change?)
* Generate UML diagram of core classes and embed it into architecture.md in documentation

### Done
* min 20% test coverage
* Exclude UI code from test report
4 changes: 3 additions & 1 deletion zhuLi/documentation/tuntikirjanpito.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@
| 15.4 | 5 | Continued to implement 3-tier structure with JSON |
| 16.3 | 3 | ^ |
| 17.3 | 3 | Got loading from JSON to work, refactored tests |
| 23.3 | 5 | Adding, deleting sources and saving changes |
| 24.3 | 8 | Misc. BS trying to get a release together, testing, etc |

__Total hours: 29 __
__Total hours: 42__
5 changes: 3 additions & 2 deletions zhuLi/src/main/kotlin/zhuLi/Main.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package zhuLi

import javafx.application.Application
import tornadofx.App
import tornadofx.launch
import zhuLi.ui.views.MainView

class Main : App(MainView::class)

fun main(args: Array<String>) {
Application.launch(App::class.java)
// Application.launch(App::class.java)
launch<Main>(args)
}
39 changes: 23 additions & 16 deletions zhuLi/src/main/kotlin/zhuLi/dao/JsonSourceListDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.squareup.moshi.Rfc3339DateJsonAdapter
import com.squareup.moshi.Types
import zhuLi.domain.Source
import java.io.File
import java.io.IOException
import java.util.Date

class JsonSourceListDao(val file: File) : SourceListDao {
Expand Down Expand Up @@ -34,24 +35,30 @@ class JsonSourceListDao(val file: File) : SourceListDao {
sources = load()
}

fun test() {
var testSources = listOf(
Source(1, "Top research", Date(1981, 12, 4), "", "ArXiv"),
Source(2, "Important paper", Date(2001, 1, 23), "", "ArXiv"),
Source(3, "Pointless publication", Date(1989, 5, 23), "", "ArXiv"),
Source(4, "Awful article", Date(1998, 8, 11), "", "ArXiv")
)
var jsonList = listAdapter.toJson(testSources)
var jsonSource = sourceAdapter.toJson(Source(1, "Top research", Date(1981, 12, 4), "", "ArXiv"))
file.printWriter().use { out ->
out.println(jsonList)
}
}
// fun test() {
// var testSources = listOf(
// Source(1, "Top research", Date(1981, 12, 4), "", "ArXiv"),
// Source(2, "Important paper", Date(2001, 1, 23), "", "ArXiv"),
// Source(3, "Pointless publication", Date(1989, 5, 23), "", "ArXiv"),
// Source(4, "Awful article", Date(1998, 8, 11), "", "ArXiv")
// )
// var jsonList = listAdapter.toJson(testSources)
// var jsonSource = sourceAdapter.toJson(Source(1, "Top research", Date(1981, 12, 4), "", "ArXiv"))
// file.printWriter().use { out ->
// out.println(jsonList)
// }
// }

override fun load(): List<Source> {
val jsonList = file.readText()
val sourceList = listAdapter.fromJson(jsonList)
return sourceList!!
try {
val jsonList = file.readText()

val sourceList = listAdapter.fromJson(jsonList)

return sourceList!!
} catch (e: IOException) {
return listOf()
}
}

override fun save(sources: List<Source>) {
Expand Down
27 changes: 16 additions & 11 deletions zhuLi/src/main/kotlin/zhuLi/domain/Source.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import com.squareup.moshi.Json
import javafx.beans.property.SimpleIntegerProperty
import javafx.beans.property.SimpleObjectProperty
import javafx.beans.property.SimpleStringProperty
import tornadofx.ItemViewModel
import tornadofx.getValue
import tornadofx.setValue
import java.util.Date
Expand Down Expand Up @@ -40,14 +39,20 @@ class Source(

val publisherProperty = SimpleStringProperty(publisher)
var publisher by publisherProperty
}

// TODO: figure out what the point of this actually is
class SourceModel : ItemViewModel<Source>() {
val id = bind(Source::idProperty)
val title = bind(Source::titleProperty)
val pubDate = bind(Source::pubDateProperty)
val addDate = bind(Source::addDateProperty)
val bibTex = bind(Source::bibTexProperty)
val publisher = bind(Source::publisherProperty)
}
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false

other as Source

if (id != other.id) return false
if (title != other.title) return false
if (pubDate != other.pubDate) return false
if (addDate != other.addDate) return false
if (bibTex != other.bibTex) return false
if (publisher != other.publisher) return false

return true
}
}
13 changes: 9 additions & 4 deletions zhuLi/src/main/kotlin/zhuLi/ui/controllers/SourceController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,23 @@ import zhuLi.dao.JsonSourceListDao
import zhuLi.domain.Source
import zhuLi.domain.SourceListModel
import java.io.File
import java.util.Date

class SourceController() : Controller() {
// val sources: FXCollections.observableArrayList<Source>
var sources = FXCollections.observableArrayList<Source>()
val listModel: SourceListModel

init {
// TODO: pull the path from somewhere
var source = Source(1, "Top research", Date(1981, 12, 4), "", "ArXiv")
listModel = SourceListModel(JsonSourceListDao(File("sampleSources.json")))
// val sourceProperties = Properties()
// sourceProperties.load
// TODO: pull the path from somewhere, like a config file

var sourceFile = File("sources.json")
sourceFile.createNewFile()

listModel = SourceListModel(JsonSourceListDao(sourceFile))
sources = FXCollections.observableArrayList<Source>(listModel.sources)
// val resource = this.javaClass.getResourceAsStream("sampleSources.json")
}

fun addSource(source: Source) {
Expand Down
6 changes: 1 addition & 5 deletions zhuLi/src/main/kotlin/zhuLi/ui/views/MainView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@ import tornadofx.singleAssign
import tornadofx.smartResize
import tornadofx.tableview
import zhuLi.domain.Source
import zhuLi.domain.SourceModel
import zhuLi.ui.controllers.SourceController
import java.util.Date

class MainView : View("Zhu Li - Digital Research Assistant") {

private val controller: SourceController by inject()
private val sourceModel: SourceModel by inject()
private val sourceModel: SourceViewModel by inject()
private var sourceTable: TableView<Source> by singleAssign()

override val root = borderpane {
Expand All @@ -43,7 +42,6 @@ class MainView : View("Zhu Li - Digital Research Assistant") {
prefWidth = 800.0
smartResize()
}

}
bottom {
hbox {
Expand All @@ -54,7 +52,6 @@ class MainView : View("Zhu Li - Digital Research Assistant") {
}
}


private fun addSource() {
val newSource = Source(controller.sources.size + 1, "", Date(), "", "")
controller.addSource(newSource)
Expand All @@ -74,6 +71,5 @@ class MainView : View("Zhu Li - Digital Research Assistant") {
// controller = SourceController("sources.json")
root.setPrefSize(800.0, 600.0)
}

// TODO: Make it save on close?
}
21 changes: 0 additions & 21 deletions zhuLi/src/main/kotlin/zhuLi/ui/views/SourceTable.kt

This file was deleted.

15 changes: 15 additions & 0 deletions zhuLi/src/main/kotlin/zhuLi/ui/views/SourceViewModel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package zhuLi.ui.views

import tornadofx.ItemViewModel
import zhuLi.domain.Source

class SourceViewModel : ItemViewModel<Source>() {
val id = bind(Source::idProperty)
val title = bind(Source::titleProperty)
val pubDate = bind(Source::pubDateProperty)
val addDate = bind(Source::addDateProperty)
val bibTex = bind(Source::bibTexProperty)
val publisher = bind(Source::publisherProperty)

// TODO: Source editing logic goes here?
}
26 changes: 23 additions & 3 deletions zhuLi/src/test/kotlin/zhuLi/dao/JsonSourceListDaoTest.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,32 @@
package zhuLi.dao

import junit.framework.Assert.assertTrue
import org.junit.After
import org.junit.Before
import org.junit.Test
import zhuLi.domain.Source
import java.util.Date

class JsonSourceListDaoTest {

@Before
fun setUp() {
@Test
fun serializeToJsonAndParse() {
val testSources = listOf(
Source(1, "Top research", Date(1981, 12, 4), "", "ArXiv"),
Source(2, "Important paper", Date(2001, 1, 23), "", "ArXiv"),
Source(3, "Pointless publication", Date(1989, 5, 23), "", "ArXiv"),
Source(4, "Awful article", Date(1998, 8, 11), "", "ArXiv")
)

val tempFile = createTempFile("tmp", ".json")
val dao = JsonSourceListDao(tempFile)

dao.save(testSources)

val newSources = dao.load()

val pairs = testSources.zip(newSources)

pairs.forEach({ a -> assertTrue(a.first == a.second) })
}

@After
Expand Down
Loading

0 comments on commit d077e08

Please sign in to comment.