-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #95 from vsukharew/dev-release-2.1.0
release 2.1.0
- Loading branch information
Showing
10 changed files
with
133 additions
and
58 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
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
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
55 changes: 55 additions & 0 deletions
55
library/src/test/java/vsukharev/anytypeadapter/adapter/AnyTypeAdapterTest.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,55 @@ | ||
package vsukharev.anytypeadapter.adapter | ||
|
||
import androidx.viewbinding.ViewBinding | ||
import kotlinx.coroutines.test.TestCoroutineDispatcher | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import org.mockito.Mockito.* | ||
import org.mockito.kotlin.argumentCaptor | ||
import vsukharev.anytypeadapter.common.MainDispatcherExtension | ||
import vsukharev.anytypeadapter.common.MockInitializer | ||
import vsukharev.anytypeadapter.domain.Track | ||
import vsukharev.anytypeadapter.holder.AnyTypeViewHolder | ||
|
||
@ExtendWith(MainDispatcherExtension::class) | ||
class AnyTypeAdapterTest : MockInitializer() { | ||
|
||
private val dispatcher = TestCoroutineDispatcher() | ||
|
||
@Test | ||
fun `onBindViewHolder - call with non-empty payload - verify holder applyPayload get called`() { | ||
val adapter = AnyTypeAdapter() | ||
val captor = argumentCaptor<List<Any>>() | ||
val payload = mutableListOf(Any()) | ||
adapter.onBindViewHolder(trackHolder as AnyTypeViewHolder<Any, ViewBinding>, 0, payload) | ||
verify(trackHolder).applyPayload(captor.capture()) | ||
assert(payload == captor.firstValue) | ||
} | ||
|
||
@Test | ||
fun `onBindViewHolder - call with empty payload - verify holder applyPayload not called`() { | ||
val adapter = AnyTypeAdapter().apply { | ||
diffStrategy = DiffStrategy.DiscardLatest(dispatcher) | ||
} | ||
AnyTypeCollection.Builder() | ||
.add(listOf(Track(), Track()), trackDelegate) | ||
.build() | ||
.let { adapter.setCollection(it) } | ||
val payload = mutableListOf<Any>() | ||
adapter.onBindViewHolder(trackHolder as AnyTypeViewHolder<Any, ViewBinding>, 0, payload) | ||
verify(trackHolder, times(0)).applyPayload(anyList()) | ||
} | ||
|
||
@Test | ||
fun `onBindViewHolder - call with overload with no payload - verify holder applyPayload not called`() { | ||
val adapter = AnyTypeAdapter().apply { | ||
diffStrategy = DiffStrategy.DiscardLatest(dispatcher) | ||
} | ||
AnyTypeCollection.Builder() | ||
.add(listOf(Track(), Track()), trackDelegate) | ||
.build() | ||
.let { adapter.setCollection(it) } | ||
adapter.onBindViewHolder(trackHolder as AnyTypeViewHolder<Any, ViewBinding>, 0) | ||
verify(trackHolder, times(0)).applyPayload(anyList()) | ||
} | ||
} |
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
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