Skip to content
This repository has been archived by the owner on Mar 24, 2021. It is now read-only.

Added Input Validation tests and Imroved Modularity of code #173

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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: 2 additions & 0 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ dependencies {
implementation 'com.google.code.gson:gson:2.8.5'

testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:2.7.22'
androidTestImplementation 'org.mockito:mockito-android:2.7.22'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,30 @@ package org.aerogear.graphqlandroid

import android.support.test.InstrumentationRegistry
import android.support.test.runner.AndroidJUnit4
import org.aerogear.offix.getDao

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*
import org.junit.runners.JUnit4

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@RunWith(JUnit4::class)
class InstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getTargetContext()
val args = InstrumentationRegistry.getArguments()
assertEquals("com.lavanya.graphqlandroid", appContext.packageName)
assertEquals(0.1010001, args.getDouble("0.1010001"))
assertEquals(true, "test".contains("s"))
assertEquals("TasksApp", appContext.resources.getString(R.string.app_name)) //TODO: change it if you ever change the app name
assertEquals(0, getDao()?.getAllMutations()?.size);
}
}
33 changes: 33 additions & 0 deletions sample/src/main/java/org/aerogear/graphqlandroid/InputValidator.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.aerogear.graphqlandroid

import java.util.regex.Pattern

object InputValidator{
val EMAIL_PATTERN = Pattern.compile(
"[a-zA-Z0-9\\+\\.\\_\\%\\-\\+]{1,256}" +
"\\@" +
"[a-zA-Z0-9][a-zA-Z0-9\\-]{0,64}" +
"(" +
"\\." +
"[a-zA-Z0-9][a-zA-Z0-9\\-]{0,25}" +
")+"
)
fun taskValidation(id: String, title: String, description: String): Boolean{
return (description.length <= 360
&& id.length!=0
&& title.length<100)
}
fun userValidation(idUser: String,
taskId: String,
title: String,
firstName: String,
lastName: String,
email: String): Boolean{
return (firstName.length<20
&& lastName.length<20
&& EMAIL_PATTERN.matcher(email).matches()
&& idUser.length!=0
&& taskId.length!=0
&& title.length<100)
}
}
Loading