Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.bober.notesapp.domain.use_case

import com.bober.notesapp.data.repository.FakeTestNoteRepository
import com.bober.notesapp.domain.model.Note
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Test

class DeleteNoteTest {

private lateinit var fakeRepository: FakeTestNoteRepository
private lateinit var deleteNote: DeleteNote

@Before
fun setUp() {
fakeRepository = FakeTestNoteRepository()
deleteNote = DeleteNote(fakeRepository)

runTest {
fakeRepository.insertNote(
Note(
id = 1,
title = "title",
content = "content",
timestamp = 1L,
color = 1
)
)
}
}

@Test
fun `Delete note by id, delete correct note`() = runTest{
val noteToDelete = fakeRepository.getNoteById(1)
noteToDelete?.let { deleteNote(it) }
val result = fakeRepository.getNoteById(1)
assertThat(result).isNull()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.bober.notesapp.domain.use_case

import com.bober.notesapp.data.repository.FakeTestNoteRepository
import com.bober.notesapp.domain.model.Note
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Test

class GetNoteTest {

private lateinit var fakeRepository: FakeTestNoteRepository
private lateinit var getNote: GetNote

@Before
fun setUp() {
fakeRepository = FakeTestNoteRepository()
getNote = GetNote(fakeRepository)

runTest {
fakeRepository.insertNote(
Note(
id = 1,
title = "title",
content = "content",
timestamp = 1L,
color = 1
)
)
}
}

@Test
fun `Get note by id, returns correct note`() = runTest {

val note = getNote(1)

assertThat(note).isNotNull()
assertThat(note?.title).isEqualTo("title")
assertThat(note?.id).isEqualTo(1)
}

@Test
fun `Get note by non-existing id, returns null`() = runTest {
val note = getNote(99)

assertThat(note).isNull()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,26 @@ class GetNotesTest {
}
}

@Test
fun `Get notes, returns updated list after insertion`() = runTest {

val initialNotes = getNotes().first()
assertThat(initialNotes.size).isEqualTo(26)

val newNote = Note(
title = "New Note",
content = "New Content",
timestamp = 999L,
color = 1,
id = 100
)
fakeRepository.insertNote(newNote)
val updatedNotes = getNotes().first()

assertThat(updatedNotes.size).isEqualTo(27)
assertThat(updatedNotes).contains(newNote)
}

@Test
fun `Order notes by title ascending, correct order`() = runTest {
val notes = getNotes(NoteOrder.Title(OrderType.Ascending)).first()
Expand Down
42 changes: 42 additions & 0 deletions app/src/test/java/com/bober/notesapp/domain/util/NoteOrderTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.bober.notesapp.domain.util

import com.google.common.truth.Truth.assertThat
import org.junit.Test

class NoteOrderTest {

@Test
fun `NoteOrder Title copy with Descending, returns Title Descending`() {
val noteOrder = NoteOrder.Title(OrderType.Ascending)
val newOrder = noteOrder.copy(OrderType.Descending)

assertThat(newOrder).isInstanceOf(NoteOrder.Title::class.java)
assertThat(newOrder.orderType).isEqualTo(OrderType.Descending)
}

@Test
fun `NoteOrder Date copy with Ascending, returns Date Ascending`() {
val noteOrder = NoteOrder.Date(OrderType.Descending)
val newOrder = noteOrder.copy(OrderType.Ascending)

assertThat(newOrder).isInstanceOf(NoteOrder.Date::class.java)
assertThat(newOrder.orderType).isEqualTo(OrderType.Ascending)
}

@Test
fun `NoteOrder Color copy with Descending, returns Color Descending`() {
val noteOrder = NoteOrder.Color(OrderType.Ascending)
val newOrder = noteOrder.copy(OrderType.Descending)

assertThat(newOrder).isInstanceOf(NoteOrder.Color::class.java)
assertThat(newOrder.orderType).isEqualTo(OrderType.Descending)
}

@Test
fun `NoteOrder Title with Ascending, has correct initial orderType`() {
val noteOrder = NoteOrder.Title(OrderType.Ascending)

assertThat(noteOrder.orderType).isEqualTo(OrderType.Ascending)
}

}
Loading