From a52983693722869b56e6afddfb29ddd6f469e3a9 Mon Sep 17 00:00:00 2001 From: Dominik Korsa Date: Sat, 13 Jun 2020 14:12:01 +0200 Subject: [PATCH] Fix lint errors (#873) --- .../data/db/migrations/Migration13Test.kt | 30 +++++++-------- .../attendance/AttendanceLocalTest.kt | 37 +++++++++++++++++-- .../luckynumber/LuckyNumberLocalTest.kt | 1 - .../wulkanowy/utils/CrashlyticsUtils.kt | 1 - .../github/wulkanowy/data/RepositoryModule.kt | 6 +-- .../appcreator/AppCreatorRepository.kt | 2 +- .../data/repositories/exam/ExamLocal.kt | 2 +- .../repositories/recipient/RecipientLocal.kt | 2 +- .../reportingunit/ReportingUnitLocal.kt | 2 +- .../sync/works/GradeStatisticsWork.kt | 2 +- .../about/logviewer/LogViewerPresenter.kt | 6 +-- .../modules/attendance/AttendancePresenter.kt | 1 - .../completed/CompletedLessonsPresenter.kt | 2 +- .../wulkanowy/utils/LifecycleAwareVariable.kt | 2 +- app/src/main/res/values/strings.xml | 2 +- .../io/github/wulkanowy/TestEnityCreator.kt | 23 ++++++++++++ .../message/MessageRepositoryTest.kt | 13 +++---- 17 files changed, 91 insertions(+), 43 deletions(-) diff --git a/app/src/androidTest/java/io/github/wulkanowy/data/db/migrations/Migration13Test.kt b/app/src/androidTest/java/io/github/wulkanowy/data/db/migrations/Migration13Test.kt index 6f9406f6..da4284b0 100644 --- a/app/src/androidTest/java/io/github/wulkanowy/data/db/migrations/Migration13Test.kt +++ b/app/src/androidTest/java/io/github/wulkanowy/data/db/migrations/Migration13Test.kt @@ -120,23 +120,23 @@ class Migration13Test : AbstractMigrationTest() { assertEquals(2, first.diaryId) } - getSemesters(db, "SELECT * FROM Semesters WHERE student_id = 2 AND class_id = 5").let { - assertTrue { it.single { it.second }.second } - assertEquals(1970, it[0].first.schoolYear) - assertEquals(of(1970, 1, 1), it[0].first.end) - assertEquals(of(1970, 1, 1), it[0].first.start) - assertFalse(it[0].second) - assertFalse(it[1].second) - assertFalse(it[2].second) - assertTrue(it[3].second) + getSemesters(db, "SELECT * FROM Semesters WHERE student_id = 2 AND class_id = 5").let { semesters -> + assertTrue { semesters.single { it.second }.second } + assertEquals(1970, semesters[0].first.schoolYear) + assertEquals(of(1970, 1, 1), semesters[0].first.end) + assertEquals(of(1970, 1, 1), semesters[0].first.start) + assertFalse(semesters[0].second) + assertFalse(semesters[1].second) + assertFalse(semesters[2].second) + assertTrue(semesters[3].second) } - getSemesters(db, "SELECT * FROM Semesters WHERE student_id = 2 AND class_id = 5").let { - assertTrue { it.single { it.second }.second } - assertFalse(it[0].second) - assertFalse(it[1].second) - assertFalse(it[2].second) - assertTrue(it[3].second) + getSemesters(db, "SELECT * FROM Semesters WHERE student_id = 2 AND class_id = 5").let { semesters -> + assertTrue { semesters.single { it.second }.second } + assertFalse(semesters[0].second) + assertFalse(semesters[1].second) + assertFalse(semesters[2].second) + assertTrue(semesters[3].second) } } diff --git a/app/src/androidTest/java/io/github/wulkanowy/data/repositories/attendance/AttendanceLocalTest.kt b/app/src/androidTest/java/io/github/wulkanowy/data/repositories/attendance/AttendanceLocalTest.kt index c7ede6ae..cdfc524a 100644 --- a/app/src/androidTest/java/io/github/wulkanowy/data/repositories/attendance/AttendanceLocalTest.kt +++ b/app/src/androidTest/java/io/github/wulkanowy/data/repositories/attendance/AttendanceLocalTest.kt @@ -10,6 +10,7 @@ import org.junit.After import org.junit.Before import org.junit.Test import org.junit.runner.RunWith +import org.threeten.bp.LocalDate import org.threeten.bp.LocalDate.now import org.threeten.bp.LocalDate.of import kotlin.test.assertEquals @@ -35,9 +36,18 @@ class AttendanceLocalTest { @Test fun saveAndReadTest() { attendanceLocal.saveAttendance(listOf( - Attendance(1, 2, 3, of(2018, 9, 10), 0, "", "", false, false, false, false, false, false, false, SentExcuseStatus.ACCEPTED.name), - Attendance(1, 2, 3, of(2018, 9, 14), 0, "", "", false, false, false, false, false, false, false, SentExcuseStatus.WAITING.name), - Attendance(1, 2, 3, of(2018, 9, 17), 0, "", "", false, false, false, false, false, false, false, SentExcuseStatus.ACCEPTED.name) + getAttendanceEntity( + of(2018, 9, 10), + SentExcuseStatus.ACCEPTED + ), + getAttendanceEntity( + of(2018, 9, 14), + SentExcuseStatus.WAITING + ), + getAttendanceEntity( + of(2018, 9, 17), + SentExcuseStatus.ACCEPTED + ) )) val attendance = attendanceLocal @@ -50,4 +60,25 @@ class AttendanceLocalTest { assertEquals(attendance[0].date, of(2018, 9, 10)) assertEquals(attendance[1].date, of(2018, 9, 14)) } + + private fun getAttendanceEntity( + date: LocalDate, + excuseStatus: SentExcuseStatus + ) = Attendance( + studentId = 1, + diaryId = 2, + timeId = 3, + date = date, + number = 0, + subject = "", + name = "", + presence = false, + absence = false, + exemption = false, + lateness = false, + excused = false, + deleted = false, + excusable = false, + excuseStatus = excuseStatus.name + ) } diff --git a/app/src/androidTest/java/io/github/wulkanowy/data/repositories/luckynumber/LuckyNumberLocalTest.kt b/app/src/androidTest/java/io/github/wulkanowy/data/repositories/luckynumber/LuckyNumberLocalTest.kt index 65ef1fcb..efad0d4d 100644 --- a/app/src/androidTest/java/io/github/wulkanowy/data/repositories/luckynumber/LuckyNumberLocalTest.kt +++ b/app/src/androidTest/java/io/github/wulkanowy/data/repositories/luckynumber/LuckyNumberLocalTest.kt @@ -5,7 +5,6 @@ import androidx.test.core.app.ApplicationProvider import androidx.test.ext.junit.runners.AndroidJUnit4 import io.github.wulkanowy.data.db.AppDatabase import io.github.wulkanowy.data.db.entities.LuckyNumber -import io.github.wulkanowy.data.db.entities.Semester import io.github.wulkanowy.data.db.entities.Student import org.junit.After import org.junit.Before diff --git a/app/src/fdroid/java/io/github/wulkanowy/utils/CrashlyticsUtils.kt b/app/src/fdroid/java/io/github/wulkanowy/utils/CrashlyticsUtils.kt index 6351997d..d03a319a 100644 --- a/app/src/fdroid/java/io/github/wulkanowy/utils/CrashlyticsUtils.kt +++ b/app/src/fdroid/java/io/github/wulkanowy/utils/CrashlyticsUtils.kt @@ -2,7 +2,6 @@ package io.github.wulkanowy.utils -import android.content.Context import timber.log.Timber open class TimberTreeNoOp : Timber.Tree() { diff --git a/app/src/main/java/io/github/wulkanowy/data/RepositoryModule.kt b/app/src/main/java/io/github/wulkanowy/data/RepositoryModule.kt index 9540372f..19af1b2f 100644 --- a/app/src/main/java/io/github/wulkanowy/data/RepositoryModule.kt +++ b/app/src/main/java/io/github/wulkanowy/data/RepositoryModule.kt @@ -1,17 +1,15 @@ package io.github.wulkanowy.data -import android.app.AlarmManager import android.content.Context import android.content.SharedPreferences import android.content.res.AssetManager import android.content.res.Resources -import androidx.core.content.getSystemService import androidx.preference.PreferenceManager -import com.github.pwittchen.reactivenetwork.library.rx2.internet.observing.InternetObservingSettings -import com.github.pwittchen.reactivenetwork.library.rx2.internet.observing.strategy.WalledGardenInternetObservingStrategy import com.chuckerteam.chucker.api.ChuckerCollector import com.chuckerteam.chucker.api.ChuckerInterceptor import com.chuckerteam.chucker.api.RetentionManager +import com.github.pwittchen.reactivenetwork.library.rx2.internet.observing.InternetObservingSettings +import com.github.pwittchen.reactivenetwork.library.rx2.internet.observing.strategy.WalledGardenInternetObservingStrategy import dagger.Module import dagger.Provides import io.github.wulkanowy.data.db.AppDatabase diff --git a/app/src/main/java/io/github/wulkanowy/data/repositories/appcreator/AppCreatorRepository.kt b/app/src/main/java/io/github/wulkanowy/data/repositories/appcreator/AppCreatorRepository.kt index 6a0b2d32..76cf698c 100644 --- a/app/src/main/java/io/github/wulkanowy/data/repositories/appcreator/AppCreatorRepository.kt +++ b/app/src/main/java/io/github/wulkanowy/data/repositories/appcreator/AppCreatorRepository.kt @@ -10,7 +10,7 @@ import javax.inject.Singleton @Singleton class AppCreatorRepository @Inject constructor(private val assets: AssetManager) { fun getAppCreators(): Single> { - return Single.fromCallable> { + return Single.fromCallable { Gson().fromJson( assets.open("contributors.json").bufferedReader().use { it.readText() }, Array::class.java diff --git a/app/src/main/java/io/github/wulkanowy/data/repositories/exam/ExamLocal.kt b/app/src/main/java/io/github/wulkanowy/data/repositories/exam/ExamLocal.kt index 0f484d32..389eb583 100644 --- a/app/src/main/java/io/github/wulkanowy/data/repositories/exam/ExamLocal.kt +++ b/app/src/main/java/io/github/wulkanowy/data/repositories/exam/ExamLocal.kt @@ -13,7 +13,7 @@ class ExamLocal @Inject constructor(private val examDb: ExamDao) { fun getExams(semester: Semester, startDate: LocalDate, endDate: LocalDate): Maybe> { return examDb.loadAll(semester.diaryId, semester.studentId, startDate, endDate) - .filter { !it.isEmpty() } + .filter { it.isNotEmpty() } } fun saveExams(exams: List) { diff --git a/app/src/main/java/io/github/wulkanowy/data/repositories/recipient/RecipientLocal.kt b/app/src/main/java/io/github/wulkanowy/data/repositories/recipient/RecipientLocal.kt index 9b1d4ac2..ff817544 100644 --- a/app/src/main/java/io/github/wulkanowy/data/repositories/recipient/RecipientLocal.kt +++ b/app/src/main/java/io/github/wulkanowy/data/repositories/recipient/RecipientLocal.kt @@ -12,7 +12,7 @@ import javax.inject.Singleton class RecipientLocal @Inject constructor(private val recipientDb: RecipientDao) { fun getRecipients(student: Student, role: Int, unit: ReportingUnit): Maybe> { - return recipientDb.load(student.studentId, role, unit.realId).filter { !it.isEmpty() } + return recipientDb.load(student.studentId, role, unit.realId).filter { it.isNotEmpty() } } fun saveRecipients(recipients: List): List { diff --git a/app/src/main/java/io/github/wulkanowy/data/repositories/reportingunit/ReportingUnitLocal.kt b/app/src/main/java/io/github/wulkanowy/data/repositories/reportingunit/ReportingUnitLocal.kt index 6f9eec3f..0631c668 100644 --- a/app/src/main/java/io/github/wulkanowy/data/repositories/reportingunit/ReportingUnitLocal.kt +++ b/app/src/main/java/io/github/wulkanowy/data/repositories/reportingunit/ReportingUnitLocal.kt @@ -11,7 +11,7 @@ import javax.inject.Singleton class ReportingUnitLocal @Inject constructor(private val reportingUnitDb: ReportingUnitDao) { fun getReportingUnits(student: Student): Maybe> { - return reportingUnitDb.load(student.studentId).filter { !it.isEmpty() } + return reportingUnitDb.load(student.studentId).filter { it.isNotEmpty() } } fun getReportingUnit(student: Student, unitId: Int): Maybe { diff --git a/app/src/main/java/io/github/wulkanowy/services/sync/works/GradeStatisticsWork.kt b/app/src/main/java/io/github/wulkanowy/services/sync/works/GradeStatisticsWork.kt index 327c7174..c4681fb8 100644 --- a/app/src/main/java/io/github/wulkanowy/services/sync/works/GradeStatisticsWork.kt +++ b/app/src/main/java/io/github/wulkanowy/services/sync/works/GradeStatisticsWork.kt @@ -9,7 +9,7 @@ import javax.inject.Inject class GradeStatisticsWork @Inject constructor(private val gradeStatisticsRepository: GradeStatisticsRepository) : Work { override fun create(student: Student, semester: Semester): Completable { - return gradeStatisticsRepository.getGradesStatistics(student, semester, "Wszystkie", false, true) + return gradeStatisticsRepository.getGradesStatistics(student, semester, "Wszystkie", false, forceRefresh = true) .ignoreElement() } } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/about/logviewer/LogViewerPresenter.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/about/logviewer/LogViewerPresenter.kt index 4485cb3e..33eb1122 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/about/logviewer/LogViewerPresenter.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/about/logviewer/LogViewerPresenter.kt @@ -25,9 +25,9 @@ class LogViewerPresenter @Inject constructor( disposable.add(loggerRepository.getLogFiles() .subscribeOn(schedulers.backgroundThread) .observeOn(schedulers.mainThread) - .subscribe({ - Timber.i("Loading logs files result: ${it.joinToString { it.name }}") - view?.shareLogs(it) + .subscribe({ files -> + Timber.i("Loading logs files result: ${files.joinToString { it.name }}") + view?.shareLogs(files) }, { Timber.i("Loading logs files result: An exception occurred") errorHandler.dispatch(it) diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/attendance/AttendancePresenter.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/attendance/AttendancePresenter.kt index 437e06c9..f58d0617 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/attendance/AttendancePresenter.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/attendance/AttendancePresenter.kt @@ -20,7 +20,6 @@ import org.threeten.bp.LocalDate import org.threeten.bp.LocalDate.now import org.threeten.bp.LocalDate.ofEpochDay import timber.log.Timber -import java.util.concurrent.TimeUnit.MILLISECONDS import javax.inject.Inject class AttendancePresenter @Inject constructor( diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/timetable/completed/CompletedLessonsPresenter.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/timetable/completed/CompletedLessonsPresenter.kt index 92aeb581..f72d753a 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/timetable/completed/CompletedLessonsPresenter.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/timetable/completed/CompletedLessonsPresenter.kt @@ -43,7 +43,7 @@ class CompletedLessonsPresenter @Inject constructor( completedLessonsErrorHandler.showErrorMessage = ::showErrorViewOnError completedLessonsErrorHandler.onFeatureDisabled = { this.view?.showFeatureDisabled() - this.view?.showEmpty(true); + this.view?.showEmpty(true) Timber.i("Completed lessons feature disabled by school") } loadData(ofEpochDay(date ?: baseDate.toEpochDay())) diff --git a/app/src/main/java/io/github/wulkanowy/utils/LifecycleAwareVariable.kt b/app/src/main/java/io/github/wulkanowy/utils/LifecycleAwareVariable.kt index 2c49ee97..b96faeb2 100644 --- a/app/src/main/java/io/github/wulkanowy/utils/LifecycleAwareVariable.kt +++ b/app/src/main/java/io/github/wulkanowy/utils/LifecycleAwareVariable.kt @@ -52,4 +52,4 @@ class LifecycleAwareVariableActivity : ReadWriteProperty Fragment.lifecycleAwareVariable() = LifecycleAwareVariable() -fun AppCompatActivity.lifecycleAwareVariable() = LifecycleAwareVariableActivity() +fun lifecycleAwareVariable() = LifecycleAwareVariableActivity() diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 29e3460b..bec752cf 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -343,7 +343,7 @@ Prev Next Search - Search... + Search… diff --git a/app/src/test/java/io/github/wulkanowy/TestEnityCreator.kt b/app/src/test/java/io/github/wulkanowy/TestEnityCreator.kt index 5d003f27..f7d29220 100644 --- a/app/src/test/java/io/github/wulkanowy/TestEnityCreator.kt +++ b/app/src/test/java/io/github/wulkanowy/TestEnityCreator.kt @@ -1,5 +1,6 @@ package io.github.wulkanowy +import io.github.wulkanowy.data.db.entities.Message import io.github.wulkanowy.data.db.entities.Semester import io.github.wulkanowy.data.db.entities.Student import io.github.wulkanowy.data.db.entities.Timetable @@ -72,3 +73,25 @@ fun getTimetableEntity( teacher = "", teacherOld = "" ) + +fun getMessageEntity( + messageId: Int, + content: String, + unread: Boolean +) = Message( + studentId = 1, + realId = 1, + messageId = messageId, + sender = "", + senderId = 1, + recipient = "", + subject = "", + content = content, + date = now(), + folderId = 1, + unread = unread, + unreadBy = 1, + readBy = 1, + removed = false, + hasAttachments = false +) diff --git a/app/src/test/java/io/github/wulkanowy/data/repositories/message/MessageRepositoryTest.kt b/app/src/test/java/io/github/wulkanowy/data/repositories/message/MessageRepositoryTest.kt index b7963d43..fcc4188a 100644 --- a/app/src/test/java/io/github/wulkanowy/data/repositories/message/MessageRepositoryTest.kt +++ b/app/src/test/java/io/github/wulkanowy/data/repositories/message/MessageRepositoryTest.kt @@ -2,10 +2,10 @@ package io.github.wulkanowy.data.repositories.message import androidx.room.EmptyResultSetException import com.github.pwittchen.reactivenetwork.library.rx2.internet.observing.InternetObservingSettings -import io.github.wulkanowy.data.db.entities.Message import io.github.wulkanowy.data.db.entities.MessageWithAttachment import io.github.wulkanowy.data.db.entities.Student import io.github.wulkanowy.data.repositories.UnitTestInternetObservingStrategy +import io.github.wulkanowy.getMessageEntity import io.reactivex.Single import io.reactivex.observers.TestObserver import org.junit.Assert.assertEquals @@ -15,7 +15,6 @@ import org.mockito.Mock import org.mockito.Mockito.`when` import org.mockito.Mockito.verify import org.mockito.MockitoAnnotations -import org.threeten.bp.LocalDateTime.now import java.net.UnknownHostException class MessageRepositoryTest { @@ -44,7 +43,7 @@ class MessageRepositoryTest { @Test fun `throw error when message is not in the db`() { - val testMessage = Message(1, 1, 1, "", 1, "", "", "", now(), 1, false, 1, 1, false, false) + val testMessage = getMessageEntity(1, "", false) `when`(local.getMessageWithAttachment(student, testMessage)).thenReturn(Single.error(EmptyResultSetException("No message in database"))) val message = repo.getMessage(student, testMessage) @@ -55,7 +54,7 @@ class MessageRepositoryTest { @Test fun `get message when content already in db`() { - val testMessage = Message(1, 1, 123, "", 1, "", "", "Test", now(), 1, false, 1, 1, false, false) + val testMessage = getMessageEntity(123, "Test", false) val messageWithAttachment = MessageWithAttachment(testMessage, emptyList()) `when`(local.getMessageWithAttachment(student, testMessage)).thenReturn(Single.just(messageWithAttachment)) @@ -67,7 +66,7 @@ class MessageRepositoryTest { @Test fun `get message when content in db is empty`() { - val testMessage = Message(1, 1, 123, "", 1, "", "", "", now(), 1, true, 1, 1, false, false) + val testMessage = getMessageEntity(123, "", true) val testMessageWithContent = testMessage.copy(content = "Test") val mWa = MessageWithAttachment(testMessage, emptyList()) @@ -86,7 +85,7 @@ class MessageRepositoryTest { @Test fun `get message when content in db is empty and there is no internet connection`() { - val testMessage = Message(1, 1, 123, "", 1, "", "", "", now(), 1, false, 1, 1, false, false) + val testMessage = getMessageEntity(123, "", false) val messageWithAttachment = MessageWithAttachment(testMessage, emptyList()) testObservingStrategy.isInternetConnection = false @@ -100,7 +99,7 @@ class MessageRepositoryTest { @Test fun `get message when content in db is empty, unread and there is no internet connection`() { - val testMessage = Message(1, 1, 123, "", 1, "", "", "", now(), 1, true, 1, 1, false, false) + val testMessage = getMessageEntity(123, "", true) val messageWithAttachment = MessageWithAttachment(testMessage, emptyList()) testObservingStrategy.isInternetConnection = false