Skip to content
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

Replace JUnit asserts with AssertJ in HistoryRecordManagerTest #7654

Merged
merged 3 commits into from
Jan 16, 2022

Conversation

XiangRongLin
Copy link
Collaborator

@XiangRongLin XiangRongLin commented Jan 14, 2022

What is it?

  • Bugfix (user facing)
  • Feature (user facing)
  • Codebase improvement (dev facing)
  • Meta improvement to the project (dev facing)

Description of the changes in your PR

Replace JUnit asserts with AssertJ in HistoryRecordManagerTest
They provide a wider range of assertions, which allow for more detailed error messages.
Also convert SearchHistoryEntry to kotlin data class for better error messages, since toString() is implemented.

examples

java.lang.AssertionError: 
Actual and expected have the same elements but not in the same order, at index 1 actual element was:
  "B"
whereas expected element was:
  "AA"

	at org.schabi.newpipe.local.history.HistoryRecordManagerTest.getRelatedSearches_emptyQuery(HistoryRecordManagerTest.kt:114)

java.lang.AssertionError: 
Expecting actual:
  [SearchHistoryEntry(creationDate=2022-01-14T10:31:08.273Z, serviceId=1, search=B),
    SearchHistoryEntry(creationDate=2022-01-14T10:31:08.273Z, serviceId=0, search=B)]
to contain exactly (and in same order):
  [SearchHistoryEntry(creationDate=2022-01-14T11:31:08.273+01:00, serviceId=1, search=B)]
but some elements were not expected:
  [SearchHistoryEntry(creationDate=2022-01-14T10:31:08.273Z, serviceId=0, search=B)]
when comparing values using HistoryRecordManagerTest$$ExternalSyntheticLambda0
	at org.schabi.newpipe.local.history.HistoryRecordManagerTest.deleteSearchHistory(HistoryRecordManagerTest.kt:79)

Fixes the following issue(s)

Due diligence

❗ Squash merge

@XiangRongLin XiangRongLin added the codequality Improvements to the codebase to improve the code quality label Jan 14, 2022
@XiangRongLin
Copy link
Collaborator Author

Can I just say how stupid this ktLint is. There is no profil for Android Studio for the codestyle used in ktLint, so I'm using the default one. The output of that breaks ktLint 🤦‍♂️

They provide a wider range of assertions, which allow for more detailed error messages.
Also convert SearchHistoryEntry to kotlin data class for better error messages, since toString() is implemented.
litetex
litetex previously approved these changes Jan 14, 2022
Copy link
Member

@litetex litetex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Tested the app seems to work also as expected 😄

app/build.gradle Outdated Show resolved Hide resolved
Co-authored-by: Mohammed Anas <triallax@tutanota.com>
@sonarcloud
Copy link

sonarcloud bot commented Jan 15, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@XiangRongLin XiangRongLin merged commit 5b9c28b into TeamNewPipe:dev Jan 16, 2022
@XiangRongLin XiangRongLin deleted the assertJ branch January 16, 2022 08:10
@tsiflimagas
Copy link
Contributor

tsiflimagas commented Jan 21, 2022

I made a build on dev branch and when I installed it, I got this

Exception

  • User Action: ui error
  • Request: ACRA report
  • Content Country: US
  • Content Language: en-US
  • App Language: en_US
  • Service: none
  • Version: 0.21.15
  • OS: Linux Android 12 - 31
Crash log

java.lang.IllegalStateException: Room cannot verify the data integrity. Looks like you've changed schema but forgot to update the version number. You can simply fix this by increasing the version number.
	at androidx.room.RoomOpenHelper.checkIdentity(RoomOpenHelper.java:154)
	at androidx.room.RoomOpenHelper.onOpen(RoomOpenHelper.java:135)
	at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.onOpen(FrameworkSQLiteOpenHelper.java:195)
	at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:427)
	at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:316)
	at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.getWritableSupportDatabase(FrameworkSQLiteOpenHelper.java:145)
	at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper.getWritableDatabase(FrameworkSQLiteOpenHelper.java:106)
	at androidx.room.RoomDatabase.inTransaction(RoomDatabase.java:622)
	at androidx.room.RoomDatabase.assertNotSuspendingTransaction(RoomDatabase.java:399)
	at androidx.room.RoomDatabase.query(RoomDatabase.java:442)
	at androidx.room.util.DBUtil.query(DBUtil.java:83)
	at org.schabi.newpipe.database.feed.dao.FeedDAO_Impl$12.call(FeedDAO_Impl.java:909)
	at org.schabi.newpipe.database.feed.dao.FeedDAO_Impl$12.call(FeedDAO_Impl.java:906)
	at io.reactivex.rxjava3.internal.operators.maybe.MaybeFromCallable.subscribeActual(MaybeFromCallable.java:47)
	at io.reactivex.rxjava3.core.Maybe.subscribe(Maybe.java:5330)
	at io.reactivex.rxjava3.internal.operators.flowable.FlowableFlatMapMaybe$FlatMapMaybeSubscriber.onNext(FlowableFlatMapMaybe.java:131)
	at io.reactivex.rxjava3.internal.operators.flowable.FlowableObserveOn$ObserveOnSubscriber.runAsync(FlowableObserveOn.java:402)
	at io.reactivex.rxjava3.internal.operators.flowable.FlowableObserveOn$BaseObserveOnSubscriber.run(FlowableObserveOn.java:176)
	at io.reactivex.rxjava3.internal.schedulers.ExecutorScheduler$ExecutorWorker$BooleanRunnable.run(ExecutorScheduler.java:322)
	at io.reactivex.rxjava3.internal.schedulers.ExecutorScheduler$ExecutorWorker.runEager(ExecutorScheduler.java:287)
	at io.reactivex.rxjava3.internal.schedulers.ExecutorScheduler$ExecutorWorker.run(ExecutorScheduler.java:248)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
	at java.lang.Thread.run(Thread.java:920)


So I reset some commits back, and found out that it was caused by this PR.

@AudricV
Copy link
Member

AudricV commented Jan 21, 2022

@XiangRongLin ^

@XiangRongLin
Copy link
Collaborator Author

@TiA4f8R I already saw it


I don't see any reason why this change would cause that error

java -> kotlin 🤦

@XiangRongLin
Copy link
Collaborator Author

So the exact reason is because of ambiguous nullability in java, which then were made explicit in kotlin during the conversion. see the error messag below

java.lang.IllegalStateException: Migration didn't properly handle: search_history(org.schabi.newpipe.database.history.model.SearchHistoryEntry).
 Expected:
TableInfo{name='search_history', columns={search=Column{name='search', type='TEXT', affinity='2', notNull=true, primaryKeyPosition=0, defaultValue='null'}, creation_date=Column{name='creation_date', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, id=Column{name='id', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=1, defaultValue='null'}, service_id=Column{name='service_id', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}}, foreignKeys=[], indices=[Index{name='index_search_history_search', unique=false, columns=[search]}]}
 Found:
TableInfo{name='search_history', columns={search=Column{name='search', type='TEXT', affinity='2', notNull=false, primaryKeyPosition=0, defaultValue='null'}, service_id=Column{name='service_id', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, id=Column{name='id', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=1, defaultValue='null'}, creation_date=Column{name='creation_date', type='INTEGER', affinity='3', notNull=false, primaryKeyPosition=0, defaultValue='null'}}, foreignKeys=[], indices=[Index{name='index_search_history_search', unique=false, columns=[search]}]}

@XiangRongLin
Copy link
Collaborator Author

@tsiflimagas fix with #7674

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
codequality Improvements to the codebase to improve the code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants