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

implement and write tests for GeneralSkillsRepo #24

Merged
merged 7 commits into from
Apr 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,5 @@ org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
# Android operating system, and which are packaged with your app"s APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official
28 changes: 21 additions & 7 deletions testomania/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ android {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
testOptions {
unitTests {
includeAndroidResources = true
}
}
}

dependencies {
Expand All @@ -58,11 +63,10 @@ dependencies {
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.1'
implementation 'androidx.activity:activity-compose:1.4.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"

// Serialization
implementation("com.squareup.moshi:moshi-kotlin:1.13.0")
kapt("com.squareup.moshi:moshi-kotlin-codegen:1.13.0")

// Compose dependencies
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:2.4.1"
Expand All @@ -75,14 +79,24 @@ dependencies {
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2'

//Dagger - Hilt
implementation "com.google.dagger:hilt-android:2.38.1"
kapt "com.google.dagger:hilt-android-compiler:2.37"
implementation "com.google.dagger:hilt-android:2.41"
kapt "com.google.dagger:hilt-android-compiler:2.41"
kapt "androidx.hilt:hilt-compiler:1.0.0"

// Room
implementation "androidx.room:room-runtime:2.4.2"
implementation "androidx.room:room-ktx:2.4.2"
kapt "androidx.room:room-compiler:2.4.2"

// Testing
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.robolectric:robolectric:4.6'
testImplementation group: 'com.google.dagger', name: 'hilt-android-testing', version: '2.41'
kaptTest 'com.google.dagger:hilt-android-compiler:2.41'
testImplementation "com.google.truth:truth:1.1.3"
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.8.1'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.earth.testomania.skills.general;

import android.content.Context;

import com.earth.testomania.skills.GeneralSkillsMathematicalRepo;
import com.squareup.moshi.Moshi;
import dagger.internal.DaggerGenerated;
import dagger.internal.Factory;
import dagger.internal.QualifierMetadata;
import dagger.internal.ScopeMetadata;
import javax.annotation.processing.Generated;
import javax.inject.Provider;

@ScopeMetadata("javax.inject.Singleton")
@QualifierMetadata("dagger.hilt.android.qualifiers.ApplicationContext")
@DaggerGenerated
@Generated(
value = "dagger.internal.codegen.ComponentProcessor",
comments = "https://dagger.dev"
)
@SuppressWarnings({
"unchecked",
"rawtypes"
})
public final class GeneralSkillsMathematicalRepo_Factory implements Factory<GeneralSkillsMathematicalRepo> {
private final Provider<Context> appContextProvider;

private final Provider<Moshi> moshiProvider;

public GeneralSkillsMathematicalRepo_Factory(Provider<Context> appContextProvider,
Provider<Moshi> moshiProvider) {
this.appContextProvider = appContextProvider;
this.moshiProvider = moshiProvider;
}

@Override
public GeneralSkillsMathematicalRepo get() {
return newInstance(appContextProvider.get(), moshiProvider.get());
}

public static GeneralSkillsMathematicalRepo_Factory create(Provider<Context> appContextProvider,
Provider<Moshi> moshiProvider) {
return new GeneralSkillsMathematicalRepo_Factory(appContextProvider, moshiProvider);
}

public static GeneralSkillsMathematicalRepo newInstance(Context appContext, Moshi moshi) {
return new GeneralSkillsMathematicalRepo(appContext, moshi);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Code generated by moshi-kotlin-codegen. Do not edit.
@file:Suppress("DEPRECATION", "unused", "ClassName", "REDUNDANT_PROJECTION",
"RedundantExplicitType", "LocalVariableName", "RedundantVisibilityModifier",
"PLATFORM_CLASS_MAPPED_TO_KOTLIN", "IMPLICIT_NOTHING_TYPE_ARGUMENT_IN_RETURN_POSITION")

package com.earth.testomania.skills.general.dto

import com.earth.testomania.skills.dto.GeneralTestItemDTO
import com.earth.testomania.skills.dto.OptionDTO
import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.JsonReader
import com.squareup.moshi.JsonWriter
import com.squareup.moshi.Moshi
import com.squareup.moshi.Types
import com.squareup.moshi.`internal`.Util
import java.lang.NullPointerException
import kotlin.Int
import kotlin.String
import kotlin.Suppress
import kotlin.Unit
import kotlin.collections.List
import kotlin.collections.emptySet
import kotlin.text.buildString

public class GeneralTestItemDTOJsonAdapter(
moshi: Moshi
) : JsonAdapter<GeneralTestItemDTO>() {
private val options: JsonReader.Options = JsonReader.Options.of("id", "options", "ordering",
"question", "test_id")

private val intAdapter: JsonAdapter<Int> = moshi.adapter(Int::class.java, emptySet(), "id")

private val listOfOptionDTOAdapter: JsonAdapter<List<OptionDTO>> =
moshi.adapter(Types.newParameterizedType(List::class.java, OptionDTO::class.java), emptySet(),
"options")

private val stringAdapter: JsonAdapter<String> = moshi.adapter(String::class.java, emptySet(),
"question")

public override fun toString(): String = buildString(40) {
append("GeneratedJsonAdapter(").append("GeneralTestItemDTO").append(')') }

public override fun fromJson(reader: JsonReader): GeneralTestItemDTO {
var id: Int? = null
var options_: List<OptionDTO>? = null
var ordering: Int? = null
var question: String? = null
var test_id: Int? = null
reader.beginObject()
while (reader.hasNext()) {
when (reader.selectName(options)) {
0 -> id = intAdapter.fromJson(reader) ?: throw Util.unexpectedNull("id", "id", reader)
1 -> options_ = listOfOptionDTOAdapter.fromJson(reader) ?:
throw Util.unexpectedNull("options_", "options", reader)
2 -> ordering = intAdapter.fromJson(reader) ?: throw Util.unexpectedNull("ordering",
"ordering", reader)
3 -> question = stringAdapter.fromJson(reader) ?: throw Util.unexpectedNull("question",
"question", reader)
4 -> test_id = intAdapter.fromJson(reader) ?: throw Util.unexpectedNull("test_id",
"test_id", reader)
-1 -> {
// Unknown name, skip it.
reader.skipName()
reader.skipValue()
}
}
}
reader.endObject()
return GeneralTestItemDTO(
id = id ?: throw Util.missingProperty("id", "id", reader),
options = options_ ?: throw Util.missingProperty("options_", "options", reader),
ordering = ordering ?: throw Util.missingProperty("ordering", "ordering", reader),
question = question ?: throw Util.missingProperty("question", "question", reader),
test_id = test_id ?: throw Util.missingProperty("test_id", "test_id", reader)
)
}

public override fun toJson(writer: JsonWriter, value_: GeneralTestItemDTO?): Unit {
if (value_ == null) {
throw NullPointerException("value_ was null! Wrap in .nullSafe() to write nullable values.")
}
writer.beginObject()
writer.name("id")
intAdapter.toJson(writer, value_.id)
writer.name("options")
listOfOptionDTOAdapter.toJson(writer, value_.options)
writer.name("ordering")
intAdapter.toJson(writer, value_.ordering)
writer.name("question")
stringAdapter.toJson(writer, value_.question)
writer.name("test_id")
intAdapter.toJson(writer, value_.test_id)
writer.endObject()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Code generated by moshi-kotlin-codegen. Do not edit.
@file:Suppress("DEPRECATION", "unused", "ClassName", "REDUNDANT_PROJECTION",
"RedundantExplicitType", "LocalVariableName", "RedundantVisibilityModifier",
"PLATFORM_CLASS_MAPPED_TO_KOTLIN", "IMPLICIT_NOTHING_TYPE_ARGUMENT_IN_RETURN_POSITION")

package com.earth.testomania.skills.general.dto

import com.earth.testomania.skills.dto.OptionDTO
import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.JsonReader
import com.squareup.moshi.JsonWriter
import com.squareup.moshi.Moshi
import com.squareup.moshi.`internal`.Util
import java.lang.NullPointerException
import kotlin.Int
import kotlin.String
import kotlin.Suppress
import kotlin.Unit
import kotlin.collections.emptySet
import kotlin.text.buildString

public class OptionDTOJsonAdapter(
moshi: Moshi
) : JsonAdapter<OptionDTO>() {
private val options: JsonReader.Options = JsonReader.Options.of("correct", "id", "option",
"question_id")

private val intAdapter: JsonAdapter<Int> = moshi.adapter(Int::class.java, emptySet(), "correct")

private val stringAdapter: JsonAdapter<String> = moshi.adapter(String::class.java, emptySet(),
"option")

public override fun toString(): String = buildString(31) {
append("GeneratedJsonAdapter(").append("OptionDTO").append(')') }

public override fun fromJson(reader: JsonReader): OptionDTO {
var correct: Int? = null
var id: Int? = null
var option: String? = null
var question_id: Int? = null
reader.beginObject()
while (reader.hasNext()) {
when (reader.selectName(options)) {
0 -> correct = intAdapter.fromJson(reader) ?: throw Util.unexpectedNull("correct",
"correct", reader)
1 -> id = intAdapter.fromJson(reader) ?: throw Util.unexpectedNull("id", "id", reader)
2 -> option = stringAdapter.fromJson(reader) ?: throw Util.unexpectedNull("option",
"option", reader)
3 -> question_id = intAdapter.fromJson(reader) ?: throw Util.unexpectedNull("question_id",
"question_id", reader)
-1 -> {
// Unknown name, skip it.
reader.skipName()
reader.skipValue()
}
}
}
reader.endObject()
return OptionDTO(
correct = correct ?: throw Util.missingProperty("correct", "correct", reader),
id = id ?: throw Util.missingProperty("id", "id", reader),
option = option ?: throw Util.missingProperty("option", "option", reader),
question_id = question_id ?: throw Util.missingProperty("question_id", "question_id",
reader)
)
}

public override fun toJson(writer: JsonWriter, value_: OptionDTO?): Unit {
if (value_ == null) {
throw NullPointerException("value_ was null! Wrap in .nullSafe() to write nullable values.")
}
writer.beginObject()
writer.name("correct")
intAdapter.toJson(writer, value_.correct)
writer.name("id")
intAdapter.toJson(writer, value_.id)
writer.name("option")
stringAdapter.toJson(writer, value_.option)
writer.name("question_id")
intAdapter.toJson(writer, value_.question_id)
writer.endObject()
}
}
42 changes: 41 additions & 1 deletion testomania/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,44 @@

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
#-renamesourcefileattribute SourceFile

# Keep `Companion` object fields of serializable classes.
# This avoids serializer lookup through `getDeclaredClasses` as done for named companion objects.
-if @kotlinx.serialization.Serializable class **
-keepclassmembers class <1> {
static <1>$Companion Companion;
}

# Keep `serializer()` on companion objects (both default and named) of serializable classes.
-if @kotlinx.serialization.Serializable class ** {
static **$* *;
}
-keepclassmembers class <2>$<3> {
kotlinx.serialization.KSerializer serializer(...);
}

# Keep `INSTANCE.serializer()` of serializable objects.
-if @kotlinx.serialization.Serializable class ** {
public static ** INSTANCE;
}
-keepclassmembers class <1> {
public static <1> INSTANCE;
kotlinx.serialization.KSerializer serializer(...);
}

# @Serializable and @Polymorphic are used at runtime for polymorphic serialization.
-keepattributes RuntimeVisibleAnnotations,AnnotationDefault

# Serializer for classes with named companion objects are retrieved using `getDeclaredClasses`.
# If you have any, uncomment and replace classes with those containing named companion objects.
#-keepattributes InnerClasses # Needed for `getDeclaredClasses`.
#-if @kotlinx.serialization.Serializable class
#com.example.myapplication.HasNamedCompanion, # <-- List serializable classes with named companions.
#com.example.myapplication.HasNamedCompanion2
#{
# static **$* *;
#}
#-keepnames class <1>$$serializer { # -keepnames suffices; class is kept when serializer() is kept.
# static <1>$$serializer INSTANCE;
#}
11 changes: 11 additions & 0 deletions testomania/src/main/java/com/earth/testomania/di/AppModule.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
package com.earth.testomania.di

import com.squareup.moshi.Moshi
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object AppModule {

//TODO provide DB instance and so on
@Provides
@Singleton
fun jsonSerializer(): Moshi {
return Moshi.Builder()
.addLast(KotlinJsonAdapterFactory())
.build()
}

}
4 changes: 4 additions & 0 deletions testomania/src/main/java/com/earth/testomania/domain/Test.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.earth.testomania.domain

class Test {
}
Loading