Skip to content
This repository has been archived by the owner on Dec 1, 2018. It is now read-only.

Commit

Permalink
added more tests
Browse files Browse the repository at this point in the history
added values to configWriter
  • Loading branch information
max-wittig committed Jan 19, 2017
1 parent b7ad33d commit 2d18b88
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/com/maxwittig/configbuilder/ConfigWriter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@ import java.io.File

class ConfigWriter(val file : File)
{
fun write(fromAddress : String, toAddress : String, password : String, smtpHost : String, port : Int)
fun write(fromAddress : String, toAddress : String, password : String, smtpHost : String, port : Int,
dailyReport : Boolean, weeklyReport : Boolean, monthlyReport : Boolean, yearlyReport : Boolean)
{
val root = JsonObject()
root.addProperty("fromAddress", fromAddress)
root.addProperty("toAddress", toAddress)
root.addProperty("password", password)
root.addProperty("smtpHost", smtpHost)
root.addProperty("port", port)
root.addProperty("dailyReport", dailyReport)
root.addProperty("weeklyReport", weeklyReport)
root.addProperty("monthlyReport", monthlyReport)
root.addProperty("yearlyReport", yearlyReport)
val gsonString = Gson().toJson(root)
file.writeText(gsonString)
}
Expand Down
24 changes: 22 additions & 2 deletions src/com/maxwittig/configbuilder/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,30 @@ fun main(args: Array<String>)

print("Input the port of the smtpHost to send from: ")
val portString = readLine()
if(portString != null && smtpHost != null && password != null && toAddress != null && fromAddress != null)

print("Would you like to receive daily reports?: (y/n)")
val dailyReportString = readLine()

print("Would you like to receive weekly reports?: (y/n)")
val weeklyReportString = readLine()

print("Would you like to receive monthly reports?: (y/n)")
val monthlyReportString = readLine()

print("Would you like to receive yearly reports?: (y/n)")
val yearlyReportString = readLine()

if(portString != null && smtpHost != null && password != null && toAddress != null && fromAddress != null
&& dailyReportString != null && weeklyReportString != null && monthlyReportString != null
&& yearlyReportString != null)
{
val dailyReport = dailyReportString.toLowerCase() == "y"
val weeklyReport = weeklyReportString.toLowerCase() == "y"
val monthlyReport = monthlyReportString.toLowerCase() == "y"
val yearlyReport = yearlyReportString.toLowerCase() == "y"

val port = portString.toInt()
configWriter.write(fromAddress, toAddress, password, smtpHost, port)
configWriter.write(fromAddress, toAddress, password, smtpHost, port, dailyReport, weeklyReport, monthlyReport, yearlyReport)
println(file.name + " created. This is now your config for the ReportGenerator")
}
}
34 changes: 34 additions & 0 deletions src/com/maxwittig/configbuilder/tests/ConfigWriterTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.maxwittig.configbuilder.tests

import com.maxwittig.configbuilder.ConfigWriter
import org.junit.Assert.assertEquals
import org.junit.Test
import java.io.File

class ConfigWriterTest
{
@Test
fun writeTest()
{
val stringBuilder = StringBuilder()

stringBuilder.append("{")
stringBuilder.append("\"fromAddress\":\"max@example.com\",")
stringBuilder.append("\"toAddress\":\"max@example.com\",")
stringBuilder.append("\"password\":\"Testing123\",")
stringBuilder.append("\"smtpHost\":\"smtp.example.com\",")
stringBuilder.append("\"port\":500,")
stringBuilder.append("\"dailyReport\":true,")
stringBuilder.append("\"weeklyReport\":true,")
stringBuilder.append("\"monthlyReport\":true,")
stringBuilder.append("\"yearlyReport\":true")
stringBuilder.append("}")


val file = File.createTempFile("config","json")
file.deleteOnExit()
val writer = ConfigWriter(file)
writer.write("max@example.com","max@example.com","Testing123","smtp.example.com", 500, true, true, true, true)
assertEquals(stringBuilder.toString(), file.readText())
}
}

0 comments on commit 2d18b88

Please sign in to comment.