Sign in Go Pro

Android Clean Architecture

Testing the cached project model mapper

This lesson is for PRO members.

Upgrade today to get access to all the PRO lessons.

Unlock this lesson
Autoplay

Up next

Previous

About

The Cache layer allows us to abstract the local source of data that our application uses. In this lesson, we're going to be writing a test for our cached project model mapper to ensure that it remains operational as intended whenever the project is maintained.

Instructor

Links

Comments

Hi Joe, Great course so far, here is my version of this test using KStubbing, just to make sure I am doing it right.

class CachedProjectMapperTest {

private val cachedProject = ProjectDataFactory.makeCachedProject()
private val projectEntity = ProjectDataFactory.makeProjectEntity()
private val cachedProjectMapper = mock {
on {
mapFromCached(cachedProject)
}.thenReturn(projectEntity)

on {
mapToCache(projectEntity)
}.thenReturn(cachedProject)
}

@Before
fun setup() {
MockitoAnnotations.initMocks(this)
}

@Test
fun projectEntityCachedProjectMapper() {

assertEquals(cachedProjectMapper.mapToCache(projectEntity), cachedProject)
}

@Test
fun cachedProjectProjectEntityMapper() {
assertEquals(cachedProjectMapper.mapFromCached(cachedProject), projectEntity)
}

}

Joe, when I tried to run those tests A LOT of errors appeared. A LOT!!!
You need to fix the source code that is showed in the videos, man.

For instance: to avoid some of the errors, in the build.gradle from module Cache I added the following line:
implementation cacheDependencies.roomRxJava

Another error happened into file /cache/model/Config.java:
error: An entity must have at least 1 field annotated with @PrimaryKey
public final class Config {
^

If I am not mistaken, Steve Zaske alerted you about it some lessons ago, right?

Hey Rodrigo,

Thanks for your comment! The room rx java dependencies is listed in the dependencies array in this lesson (https://caster.io/lessons/android-clean-architecture-setting-up-the-cache-module-cache-layer-6), I have that already on my list to fix being added in the build.gradle file.

The primary key annotation is reflected here https://github.com/hitherejoe/GithubTrending/blob/task/cache/cache/src/main/java/co/joebirch/cache/model/Config.kt#L9 - we do the same for the cached project in this lesson: https://caster.io/lessons/android-clean-architecture-setting-up-the-cache-layer-data-models-cache-layer-2. I'll make sure that this is reflected clearly here

More errors:

1) At file ProjectConstants.kt the syntax of DELETE_PROJECTS must be changed from "DELETE * FROM $TABLENAME" to "DELETE FROM $TABLENAME"

2) As this error states,
error: Dao class must be annotated with @Dao
public abstract class ConfigDao {
^

at file ConfigDao.kt it is missing the annotation @Dao.

Hey Rodrigo,

We created the DAO with the correct annotation in this lesson: https://caster.io/lessons/android-clean-architecture-creating-the-configuration-data-access-object-cache-layer-5 - would you be able to check that your code matches here?

Now it matches.

Joe, my test is not running. See:
http://bit.ly/2Tb3yQV

Why is Android Studio not recognizing "assertEquals", "Test", "JUnit4", "test" and "junit"?
Why is your test from the video working, and mine not?

I found the solution. Well, in Lesson 40 "Setting up the Cache module", the files "build.gradle" from module Cache and "dependencies.gradle" are INCORRECT.

Searching through your Github I found inconsistencies between the video from this lesson and the content from the Github.
That's why my Android Studio wasn't recognizing "assertEquals", "Test", "JUnit4", "test" and "junit".

Could you please fix the Lesson 40 to prevent future students to spent some big time trying to figure out what is wrong with the code?

Hey Rodrigo Cericatto,

I'll update the build.gradle file in the video! For now if it helps, all the cache producton / test dependencies listed at 0:46 in this lesson https://caster.io/lessons/android-clean-architecture-setting-up-the-cache-module-cache-layer-6 need to be added to the build.gradle file!

>
You need to go PRO to post comments.

Lessons in Android Clean Architecture

Introduction to Clean Architecture
03:40
Joe Birch
GDE
Android and Clean Architecture
03:51
Joe Birch
GDE
Setting up a Multi-Module project
02:24
Joe Birch
GDE
Setting up the Domain layer module
02:24
Joe Birch
GDE
Creating the abstraction for our RxJava Observation Thread
02:02
Joe Birch
GDE
Setting up the Business Data for the Domain Layer
01:47
Joe Birch
GDE
Setting up the data access interface for the Domain Layer
01:49
Joe Birch
GDE
Setting up the Domain Layer Interactor classes
Pro
03:28
Joe Birch
GDE
Implementing the Get Projects use case
Pro
01:49
Joe Birch
GDE
Implementing the get Bookmarked Projects use case
Pro
01:33
Joe Birch
GDE
Implementing the Bookmark Project use case
Pro
01:57
Joe Birch
GDE
Implementing the UnBookmark Project use case (Domain layer 8)
Pro
02:03
Joe Birch
GDE
Testing the Get Projects use case
Pro
02:41
Joe Birch
GDE
Testing the Get Bookmarked Projects use case
Pro
02:04
Joe Birch
GDE
Testing the Bookmark Project use case
Pro
02:10
Joe Birch
GDE
Testing the UnBookmark Project use case
Pro
02:06
Joe Birch
GDE
Setting up the data module
Pro
02:17
Joe Birch
GDE
Creating the data models for the data layer
Pro
02:48
Joe Birch
GDE
Creating the external source interfaces for our data layer
Pro
02:24
Joe Birch
GDE
Creating the data layer store interface
Pro
01:19
Joe Birch
GDE
Creating the data layer cache data store
Pro
01:21
Joe Birch
GDE
Creating the data layer remote data store
Pro
01:39
Joe Birch
GDE
Creating the data store factory class
Pro
01:24
Joe Birch
GDE
Creating the central access point for the data layer
Pro
03:00
Joe Birch
GDE
Setting up the tests for the Data Layer
Pro
00:46
Joe Birch
GDE
Testing the data store factory class
Pro
01:39
Joe Birch
GDE
Testing the project entity mapper
Pro
01:18
Joe Birch
GDE
Testing the projects data repository
Pro
06:02
Joe Birch
GDE
Testing the projects cache data store
Pro
06:30
Joe Birch
GDE
Testing the projects remote data store
Pro
02:17
Joe Birch
GDE
Setting up the remote module
Pro
02:21
Joe Birch
GDE
Creating the data models for the remote layer
Pro
02:06
Joe Birch
GDE
Creating the Retrofit Service for the remote data source
Pro
01:58
Joe Birch
GDE
Creating the Retrofit Service Factory for the remote service interface
Pro
02:52
Joe Birch
GDE
Creating the data model mapper for the Remote Layer
Pro
01:59
Joe Birch
GDE
Creating the Remote Source implementation
Pro
01:55
Joe Birch
GDE
Setting up the Remote layer for testing
Pro
02:13
Joe Birch
GDE
Testing the remote model mapper class
Pro
01:39
Joe Birch
GDE
Testing the remote source implementation
Pro
05:09
Joe Birch
GDE
Setting up the Cache module
Pro
02:45
Joe Birch
GDE
Setting up the Cache layer data models
Pro
02:02
Joe Birch
GDE
Creating the database for the cache layer
Pro
01:34
Joe Birch
GDE
Creating the cached project Data Access Object
Pro
02:42
Joe Birch
GDE
Creating the Configuration Data Access Object
Pro
02:07
Joe Birch
GDE
Creating the cache model mapper
Pro
02:06
Joe Birch
GDE
Creating the Projects Cache data source Implementation
Pro
03:57
Joe Birch
GDE
Setting up the tests for our cache layer
Pro
01:17
Joe Birch
GDE
Testing the cached project model mapper
Pro
01:44
Joe Birch
GDE
Testing the Cached project DAO
Pro
04:33
Joe Birch
GDE
Testing the Configuration DAO
Pro
02:05
Joe Birch
GDE
Testing the projects cache implementation
Pro
05:48
Joe Birch
GDE
Setting up the presentation module
Pro
02:05
Joe Birch
GDE
Creating the data models for the presentation layer
Pro
01:13
Joe Birch
GDE
Creating the data model mapper for the presentation layer
Pro
01:26
Joe Birch
GDE
Creating the presentation state model
Pro
01:39
Joe Birch
GDE
Creating the browse projects view model
Pro
04:25
Joe Birch
GDE
Creating the bookmarked projects view model
Pro
03:05
Joe Birch
GDE
Setting up the presentation module tests
Pro
02:09
Joe Birch
GDE
Testing the view model mapper
Pro
01:17
Joe Birch
GDE
Testing our Browse Projects View Model implementation
Pro
04:36
Joe Birch
GDE
Testing our Browse Bookmarked Projects View Model implementation
Pro
04:34
Joe Birch
GDE
Setting up the UI module
Pro
02:22
Joe Birch
GDE
Creating the Post Execution Thread Implementation
Pro
01:26
Joe Birch
GDE
Setting up the application class
Pro
00:50
Joe Birch
GDE
Setting up the Dependency Injection for the UI module
Pro
02:46
Joe Birch
GDE
Creating the UI modules Project representation
Pro
00:50
Joe Birch
GDE
Creating the the Project model mapper for the UI module
Pro
01:24
Joe Birch
GDE
Setting up the Browse Projects Activity
Pro
01:08
Joe Birch
GDE
Configuring the DI for the project
Pro
04:37
Joe Birch
GDE
Creating the Project item view
Pro
01:51
Joe Birch
GDE
Creating the Browse Projects Adapter
Pro
03:27
Joe Birch
GDE
Creating the browse bookmarked projects adapter
Pro
03:54
Joe Birch
GDE
Creating the browse bookmarked projects activity
Pro
03:18
Joe Birch
GDE
Tying together the browse projects and bookmarked projects activity
Pro
02:30
Joe Birch
GDE
Setting up Unit Tests for the UI module
Pro
00:54
Joe Birch
GDE
Test the project model mapper
Pro
01:10
Joe Birch
GDE
Configuring the Dependency Injection for our User Interface tests
Pro
06:10
Joe Birch
GDE
Writing Espresso tests for the Browse Projects Activity
Pro
03:15
Joe Birch
GDE
Writing Espresso tests for the Bookmarked Projects Activity
Pro
02:34
Joe Birch
GDE
Simplifying the work we have done
Pro
05:14
Joe Birch
GDE