New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cache test #10
Cache test #10
Conversation
Library.coroutinesTest | ||
) | ||
kapt( | ||
Library.daggerHiltCompiler, | ||
Library.roomCompiler |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try not to add module specific dependencies to the general Android Library plugin
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, thank you
@larmie56 I added robolectric dependency to the cache module, which seems to provide the remaining classes that were missing in your build. I also fixed the tests cos they were failing. Changed runblockingTest to just runBlocking{} cos the former was causing tests to fail. There's a thread about the issue . Also, since the database is generating the This also fixes a problem where calling |
Hi Tobey! Thanks for the detailed explanation, I now understand why the tests were failing/not running. I was thinking it'll be better not to replace on conflict, in the Dao::insert. When we replace on insertion, I'm not sure we know it's the same expense entry (since update will handle same expense entry). So replacing might cause data to be loss. If I have it figured out wrongly, please can you help clear it up? |
If two expense objects have the same ID, then they're assumed to be the same. The insert method will check if a record with that primary key already exists before deciding what to do. That's why the on conflict strategy exists. |
Okay it clears it up. Thanks alot |
I changed |
Nope. Copy the existing expense object in order to create a new one with the updated info. We only use vars in very exceptional cases. Also remove the I think the id stuff I did might be wrong even, but I'll check it further |
Immutability helps to eliminate some family of bugs. So we will mostly use read only properties everywhere. |
Okay, thank you for pointing out the
Yeaa... I was thinking of a way to update without altering the immutability, but then I remembered a couple of repos I had seen that used mutable fields, so I just decided to do that. Thank you for pointing it out |
Okay thank you, I will fix them. And about the id, I think it can stay in the constructor, still as a default parameter. But that doesn't solve the mutability. Also, in the Kotlin fundamental course, they used an example where the id was mutable. Although that might be because they were more concerned with teaching a concept, than immutability. |
I think we can move it back to the constructor then. It may need to stay mutable since the database is supposed to increment it. But I'm not sure, you can confirm |
Okay sure, I'll confirm it |
I tried to move the id to the constructor but some previous tests were failing. And from what I found after doing some searching, doing it the way you did it was a sort of norm. So I left it the way you did it |
Yea I noticed moving the id out of constructor makes the tests pass cos the |
Yea I think so. Most of the other tests I saw while searching for options did the same thing |
val id = expenseRepository.insertExpense(expense) | ||
val id2 = expenseRepository.insertExpense(expense) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really understand inserting the expense into the database twice. Is it like to sort of simulate multiple entries?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, all clear now. Thank you
Just insert into the db and it'll replace the existing entry. Hm but with auto generated keys I wonder if that will work. Maybe not |
Okay. Yeaaa... the ids might vary |
The db will increment the id before inserting, thereby duplicating the record. |
Okay, I'll do that |
Nice work |
What does this PR do?