-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added unit test for use case GetNote
closes #4
- Loading branch information
Pooja shaji
committed
Oct 12, 2022
1 parent
cac6111
commit c4aabfb
Showing
6 changed files
with
156 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
@startuml | ||
|
||
title __MY NOTES's Component Diagram__\n | ||
|
||
component "My_Notes.app.unitTest" { | ||
[My_Notes.app.main] | ||
component "My_Notes.app.main" { | ||
[My_Notes.app.androidTest] | ||
component "My_Notes.app.androidTest" { | ||
[My_Notes.app] | ||
} | ||
|
||
|
||
} | ||
|
||
|
||
} | ||
|
||
|
||
[My_Notes.app.androidTest] --> [My_Notes.app.main] | ||
[My_Notes.app.unitTest] --> [My_Notes.app.main] | ||
|
||
|
||
right footer | ||
|
||
|
||
PlantUML diagram generated by SketchIt! (https://bitbucket.org/pmesmeur/sketch.it) | ||
For more information about this tool, please contact philippe.mesmeur@gmail.com | ||
endfooter | ||
|
||
@enduml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...rc/test/java/com/dlight/mynotes/feature_note/domain/data/repository/FakeNoteRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.dlight.mynotes.feature_note.domain.data.repository | ||
|
||
import com.dlight.mynotes.feature_note.domain.model.Note | ||
import com.dlight.mynotes.feature_note.domain.repository.NoteRepository | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.flow | ||
|
||
class FakeNoteRepository : NoteRepository { | ||
|
||
private val notes = mutableListOf<Note>() | ||
|
||
override fun getNotes(): Flow<List<Note>> { | ||
return flow { emit(notes) } | ||
} | ||
|
||
override suspend fun getNoteById(id: Int): Note? { | ||
return notes.find { it.id == id } | ||
} | ||
|
||
override suspend fun insertNote(note: Note) { | ||
notes.add(note) | ||
} | ||
|
||
override suspend fun deleteNote(note: Note) { | ||
notes.remove(note) | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
app/src/test/java/com/dlight/mynotes/feature_note/domain/use_cases/GetNotesTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package com.dlight.mynotes.feature_note.domain.use_cases | ||
|
||
import com.dlight.mynotes.feature_note.domain.data.repository.FakeNoteRepository | ||
import com.dlight.mynotes.feature_note.domain.model.Note | ||
import com.dlight.mynotes.feature_note.domain.util.NoteOrder | ||
import com.dlight.mynotes.feature_note.domain.util.OrderType | ||
import com.google.common.truth.Truth.assertThat | ||
import kotlinx.coroutines.flow.first | ||
import kotlinx.coroutines.runBlocking | ||
import org.junit.Before | ||
import org.junit.Test | ||
|
||
class GetNotesTest { | ||
|
||
private lateinit var getNotes: GetNotes | ||
private lateinit var fakeNoteRepository: FakeNoteRepository | ||
|
||
@Before | ||
fun setUp() { | ||
fakeNoteRepository = FakeNoteRepository() | ||
getNotes = GetNotes(fakeNoteRepository) | ||
|
||
val noteToInsert = mutableListOf<Note>() | ||
('a'..'z').forEachIndexed { index, c -> | ||
noteToInsert.add( | ||
Note( | ||
title = c.toString(), | ||
content = c.toString(), | ||
timestamp = index.toLong(), | ||
color = index | ||
) | ||
) | ||
} | ||
noteToInsert.shuffle() | ||
runBlocking { | ||
noteToInsert.forEach { fakeNoteRepository.insertNote(it) } | ||
} | ||
} | ||
|
||
@Test | ||
fun `Order notes by title ascending, correct order`() = runBlocking { | ||
val notes = getNotes(NoteOrder.Title(OrderType.Ascending)).first() | ||
|
||
for (i in 0..notes.size - 2) { | ||
assertThat(notes[i].title).isLessThan(notes[i + 1].title) | ||
} | ||
} | ||
|
||
@Test | ||
fun `Order notes by title descending, correct order`() = runBlocking { | ||
val notes = getNotes(NoteOrder.Title(OrderType.Descending)).first() | ||
|
||
for (i in 0..notes.size - 2) { | ||
assertThat(notes[i].title).isGreaterThan(notes[i + 1].title) | ||
} | ||
} | ||
|
||
@Test | ||
fun `Order notes by date ascending, correct order`() = runBlocking { | ||
val notes = getNotes(NoteOrder.Date(OrderType.Ascending)).first() | ||
|
||
for (i in 0..notes.size - 2) { | ||
assertThat(notes[i].timestamp).isLessThan(notes[i + 1].timestamp) | ||
} | ||
} | ||
|
||
@Test | ||
fun `Order notes by date descending, correct order`() = runBlocking { | ||
val notes = getNotes(NoteOrder.Date(OrderType.Descending)).first() | ||
|
||
for (i in 0..notes.size - 2) { | ||
assertThat(notes[i].timestamp).isGreaterThan(notes[i + 1].timestamp) | ||
} | ||
} | ||
|
||
@Test | ||
fun `Order notes by color ascending, correct order`() = runBlocking { | ||
val notes = getNotes(NoteOrder.Color(OrderType.Ascending)).first() | ||
|
||
for (i in 0..notes.size - 2) { | ||
assertThat(notes[i].color).isLessThan(notes[i + 1].color) | ||
} | ||
} | ||
|
||
@Test | ||
fun `Order notes by color descending, correct order`() = runBlocking { | ||
val notes = getNotes(NoteOrder.Color(OrderType.Descending)).first() | ||
|
||
for (i in 0..notes.size - 2) { | ||
assertThat(notes[i].color).isGreaterThan(notes[i + 1].color) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#Sun Jul 03 15:16:46 IST 2022 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip | ||
distributionPath=wrapper/dists | ||
zipStorePath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME |