Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Android Studio
.idea/
*.iml
.gradle/
build/
captures/

# Kotlin
*.class
*.kotlin_module

# Gradle
local.properties
/out/

# Logs
*.log

# Virtual Machine
.DS_Store

# Dependency directories
/node_modules/

# Compiled class files
*.class

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs
hs_err_pid*
16 changes: 16 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.9.0'
}

dependencies {
testImplementation 'junit:junit:4.13.2'
testImplementation "org.jetbrains.kotlin:kotlin-test-junit"
}

repositories {
mavenCentral()
}

test {
useJUnit()
}
16 changes: 16 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
plugins {
kotlin("jvm") version "1.9.0"
}

dependencies {
testImplementation("junit:junit:4.13.2")
testImplementation(kotlin("test"))
}

repositories {
mavenCentral()
}

tasks.test {
useJUnitPlatform()
}
27 changes: 27 additions & 0 deletions src/main/kotlin/com/todoapp/validation/TodoValidation.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.todoapp.validation

/**
* Provides validation methods for Todo items
*/
object TodoValidation {
/**
* Validates the title of a todo item
*
* @param title The title to validate
* @return Boolean indicating if the title is valid
*/
fun isValidTitle(title: String?): Boolean {
// Check if title is null or empty after trimming whitespace
return !title.isNullOrBlank()
}

/**
* Throws an exception if the title is invalid
*
* @param title The title to validate
* @throws IllegalArgumentException if title is invalid
*/
fun validateTitle(title: String?) {
require(isValidTitle(title)) { "Todo item title cannot be empty" }
}
}
67 changes: 67 additions & 0 deletions src/test/kotlin/com/todoapp/validation/TodoValidationTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.todoapp.validation

import org.junit.Assert.*
import org.junit.Test

class TodoValidationTest {
@Test
fun `test valid title returns true`() {
// Arrange
val validTitle = "Buy groceries"

// Act
val result = TodoValidation.isValidTitle(validTitle)

// Assert
assertTrue("Valid title should return true", result)
}

@Test
fun `test empty title returns false`() {
// Arrange
val emptyTitle = ""

// Act
val result = TodoValidation.isValidTitle(emptyTitle)

// Assert
assertFalse("Empty title should return false", result)
}

@Test
fun `test null title returns false`() {
// Arrange
val nullTitle: String? = null

// Act
val result = TodoValidation.isValidTitle(nullTitle)

// Assert
assertFalse("Null title should return false", result)
}

@Test
fun `test whitespace-only title returns false`() {
// Arrange
val whitespaceTitle = " "

// Act
val result = TodoValidation.isValidTitle(whitespaceTitle)

// Assert
assertFalse("Whitespace-only title should return false", result)
}

@Test(expected = IllegalArgumentException::class)
fun `test validateTitle throws exception for invalid title`() {
// Act
TodoValidation.validateTitle("")
}

@Test
fun `test validateTitle does not throw for valid title`() {
// Act
TodoValidation.validateTitle("Valid Title")
// Assert (no exception thrown)
}
}