Skip to content

Commit

Permalink
Merge pull request romellfudi#92 from romellfudi/feature/regex_pattern
Browse files Browse the repository at this point in the history
feature/regex pattern
  • Loading branch information
romellfudi authored Jun 24, 2021
2 parents 4ee917c + 132352d commit c52e19f
Show file tree
Hide file tree
Showing 12 changed files with 145 additions and 61 deletions.
27 changes: 26 additions & 1 deletion .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2
- name: set up JDK 1.8
uses: actions/setup-java@v1
with:
Expand Down Expand Up @@ -44,3 +44,28 @@ jobs:
with:
name: ussd-library-kotlin-aar
path: ussd-library-kotlin/build/outputs/aar/ussd-library-kotlin-debug.aar

# android_testing:
# name: Instrumented tests
# runs-on: macos-latest
# timeout-minutes: 25
#
# steps:
# - uses: actions/checkout@v2
#
# - name: Set Up JDK 1.8
# uses: actions/setup-java@v1
# with:
# java-version: 1.8
#
## - name: Execute Unit Tests (gradlew test)
## run: bash ./gradlew test --stacktrace
#
# - name: Run Android instrumented tests
# uses: reactivecircus/android-emulator-runner@v2
# with:
# api-level: 23
# target: default
# arch: x86
# profile: Nexus 6
# script: ./gradlew :app-kotlin:connectedDemoDebugCheck --stacktrace
23 changes: 13 additions & 10 deletions app-kotlin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,20 @@ android {

dependencies {
implementation project(':ussd-library-kotlin')

// implementation 'com.romellfudi.permission:kotlin-fudi-permission:2.0.a'
implementation 'com.github.romellfudi.FudiPermission:kotlin-fudi-permission:main-SNAPSHOT'
}
dependencies {
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'com.google.android.material:material:1.0.0'
// implementation 'com.romellfudi.permission:kotlin-fudi-permission:2.0.a'
implementation 'com.github.romellfudi.FudiPermission:kotlin-fudi-permission:main-SNAPSHOT'

implementation 'com.orhanobut:logger:2.2.0'
implementation 'com.jakewharton.timber:timber:4.7.1'

implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

implementation 'com.google.android.play:core:1.10.0'

implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
Expand All @@ -105,15 +110,13 @@ dependencies {
implementation "org.koin:koin-android:$koin"
implementation "org.koin:koin-androidx-viewmodel:$koin"

implementation "io.reactivex.rxjava2:rxjava:2.0.6"
implementation "io.reactivex.rxjava2:rxandroid:2.0.1"
implementation 'io.reactivex.rxjava2:rxjava:2.0.6'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'

implementation 'com.airbnb.android:lottie:3.7.0'
implementation "com.google.android.material:material:1.3.0-alpha03"
implementation 'com.google.android.material:material:1.3.0-alpha03'
}
dependencies {
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.7'

androidTestImplementation 'com.kaspersky.android-components:kaspresso:1.2.0'
}
repositories {
mavenCentral()
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ object MainScreen : KScreen<MainScreen>() {
override val viewClass: Class<*> = MainActivity::class.java

val dialUpButton = KButton { withId(R.id.accessibility) }
val radioSplash = KButton { withId(R.id.splash)}
val phone = KEditText { withId(R.id.phone) }
val result = KTextView { withId(R.id.result) }
val call_scroll = KScrollView { withId(R.id.call_scroll) }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright (c) 2021. BoostTag E.I.R.L. Romell D.Z.
* All rights reserved
* portfolio.romellfudi.com
*/
package com.romellfudi.ussd.test

import org.hamcrest.Description
import org.hamcrest.TypeSafeMatcher

class RegexMatcher(private val regex: String) : TypeSafeMatcher<String>() {
override fun describeTo(description: Description) {
description.appendText("matches regular expression=`$regex`")
}

public override fun matchesSafely(string: String): Boolean {
return string.matches(regex.toRegex())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class SimpleTest : TestCase() {
)
device.screenshots.take("splash_screenshot")
}
step("Make the USSD call") {
step("Make the USSD call & not show the splashView") {
MainScreen {
testLogger.i("Writing the short number in the input...")
result { hasText("Empty") }
Expand All @@ -66,10 +66,7 @@ class SimpleTest : TestCase() {
SERVICE_CLASS_NAME
)
testLogger.i("Dial up...")
dialUpButton {
isClickable()
click()
}
dialUpButton { click() }
device.screenshots.take("dial_screenshot")
}
}
Expand All @@ -81,8 +78,29 @@ class SimpleTest : TestCase() {
isDisplayed()
hasNoText("Empty")
hasAnyText()
startsWithText("\n-\n[")
containsText("]")
hasText(RegexMatcher("^\\n-\\n\\[.+(,\\s+.*)*\\]$"))
}
device.screenshots.take("over_screenshot")
}
}
step("Make the USSD call & show the splashView") {
MainScreen {
testLogger.i("Closing soft keyboard...")
closeSoftKeyboard()
radioSplash { click() }
testLogger.i("Dial up...")
dialUpButton { click() }
device.screenshots.take("dial_splash_screenshot")
}
}
step("Verify the result of the sdk after showing SplashView") {
MainScreen {
testLogger.i("Scrolling the page and display the result")
call_scroll { swipeUp() }
result {
hasNoText("Empty")
hasAnyText()
hasText(RegexMatcher("^\\n-\\n\\[.+(,\\s+.*)*\\]$"))
}
device.screenshots.take("over_screenshot")
}
Expand Down
45 changes: 27 additions & 18 deletions app-kotlin/src/main/java/com/romellfudi/ussd/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,51 @@ package com.romellfudi.ussd

import android.app.Application
import com.airbnb.lottie.L
import com.orhanobut.logger.AndroidLogAdapter
import com.orhanobut.logger.FormatStrategy
import com.orhanobut.logger.Logger
import com.orhanobut.logger.PrettyFormatStrategy
import com.romellfudi.ussd.accessibility.di.accessibilityModule
import com.romellfudi.ussd.main.di.appModule
import org.koin.android.ext.koin.androidContext
import org.koin.core.context.startKoin
import timber.log.Timber

/**
* Specially check the logcat in DEBUG flavor
*
* @autor Romell Domínguez
* @date 2020-04-20
* @version 1.0
*/
class App : Application() {
override fun onCreate() {
super.onCreate()
if (BuildConfig.DEBUG) {
L.DBG = true
Timber.plant(object : Timber.DebugTree(){
override fun log(priority: Int, tag: String?, message: String, t: Throwable?) {
super.log(priority, "timber_tag_$tag", message, t)
}

override fun createStackElementTag(element: StackTraceElement): String? {
return String.format(
"%s:%s",
element.methodName,
element.lineNumber,
super.createStackElementTag(element))
}
})
}
val formatStrategy: FormatStrategy = PrettyFormatStrategy.newBuilder()
.showThreadInfo(true) // (Optional) Whether to show thread info or not. Default true
.methodCount(1) // (Optional) How many method line to show. Default 2
.methodOffset(5) // Set methodOffset to 5 in order to hide internal method calls
.tag("") // To replace the default PRETTY_LOGGER tag with a dash (-).
.build() // CHECK THE Logcat /-
Logger.addLogAdapter(AndroidLogAdapter(formatStrategy))

Timber.plant(object : Timber.DebugTree() {
override fun log(priority: Int, tag: String?, message: String, t: Throwable?) {
Logger.log(priority, "$tag", message, t) // Must not drop $ format
}
})
Timber.d("Init Application\nSetting Koin Architecture...")

startKoin {
printLogger()
if (BuildConfig.DEBUG) {
L.DBG = true
printLogger()
}
androidContext(this@App)
modules(
appModule,
accessibilityModule
appModule,
accessibilityModule
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.appcompat.app.AppCompatActivity
import com.romellfudi.ussd.R
import com.romellfudi.ussd.accessibility.goActivity
import kotlinx.coroutines.*
import timber.log.Timber

class SplashActivity : AppCompatActivity() {

Expand All @@ -19,10 +20,12 @@ class SplashActivity : AppCompatActivity() {
// window.setFlags(
// WindowManager.LayoutParams.FLAG_FULLSCREEN,
// WindowManager.LayoutParams.FLAG_FULLSCREEN)
Timber.i("Splash Activity")

activityScope.launch {
delay(3000)
goActivity<MainActivity>()
Timber.i("starting Main Activity")
finish()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

package com.romellfudi.ussd.main.view

import android.annotation.SuppressLint
import android.app.Activity
import android.os.Bundle
import android.os.Handler
Expand Down Expand Up @@ -126,8 +127,10 @@ class MainFragmentView : Fragment(), MainFragmentMVPView, KoinComponent {
handler.postDelayed(::dismissOverlay, 12000)
}

override fun showResult(result: String) =
override fun showResult(result: String) {
callViewModel.result.postValue(result)
Timber.d("$result")
}

override fun dismissOverlay() {
handler.removeCallbacksAndMessages(null)
Expand Down
7 changes: 2 additions & 5 deletions local.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
## This file is automatically generated by Android Studio.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must *NOT* be checked into Version Control Systems,
## This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
#Wed Aug 22 05:19:06 PET 2018
#Mon Jun 14 13:29:47 PET 2021
21 changes: 13 additions & 8 deletions ussd-library-kotlin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ ext {

licenseName = 'The Apache Software License, Version 2.0'
licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
allLicenses = ["Apache-2.0"]
allLicenses = ["GPL-3.0"]
}

android {
Expand Down Expand Up @@ -82,22 +82,27 @@ dokkaHtml.configure {
}
}

repositories {
mavenCentral()
}

dependencies {
implementation 'com.android.support:appcompat-v7:30.0.0'
implementation 'com.jakewharton.timber:timber:4.7.1'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "androidx.navigation:navigation-fragment-ktx:$navigationVersion"
implementation "androidx.navigation:navigation-ui-ktx:$navigationVersion"
}

dependencies {
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-all:1.10.19'
testImplementation 'org.powermock:powermock-module-junit4:1.6.2'
testImplementation 'com.nhaarman.mockitokotlin2:mockito-kotlin:2.1.0'
testImplementation 'org.powermock:powermock-api-mockito:1.6.2'
testImplementation 'io.mockk:mockk:1.9.3'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

implementation "androidx.navigation:navigation-fragment-ktx:$navigationVersion"
implementation "androidx.navigation:navigation-ui-ktx:$navigationVersion"
}

apply from: 'https://raw.githubusercontent.com/romellfudi/assets/bintray/artifactory_bintray.gradle'
apply from: 'https://raw.githubusercontent.com/romellfudi/assets/bintray/artifactory_install.gradle'
repositories {
mavenCentral()
}

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import android.os.SystemClock
import android.util.AttributeSet
import android.util.Log
import android.view.View
import timber.log.Timber

import java.io.FileNotFoundException
import java.io.InputStream
Expand Down Expand Up @@ -89,7 +90,7 @@ class GifImageView : View {
mInputStream = mContext!!.contentResolver.openInputStream(uri)
init()
} catch (e: FileNotFoundException) {
Log.e("GIfImageView", "File not found")
Timber.e( "File not found")
}

}
Expand Down
Loading

0 comments on commit c52e19f

Please sign in to comment.