Skip to content

Commit

Permalink
up-to-date codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
pot8os committed Jan 28, 2024
1 parent 4df8514 commit 92e398a
Show file tree
Hide file tree
Showing 11 changed files with 135 additions and 127 deletions.
14 changes: 9 additions & 5 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
uses: actions/setup-java@v1
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: 1.8
- uses: actions/cache@v1
distribution: 'adopt'
java-version: 17
cache: gradle
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
- uses: actions/cache@v4
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
Expand Down
24 changes: 13 additions & 11 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
plugins {
id("com.android.application")
kotlin("android")
kotlin("kapt")
id("com.google.devtools.ksp") version "1.9.22-1.0.17" apply false
}

android {
compileSdkVersion(29)
namespace = "net.pot8os.kotlintestsample"
compileSdk = 34

defaultConfig {
applicationId = "net.pot8os.kotlintestsample"
minSdkVersion(23)
targetSdkVersion(29)
minSdk = 23
targetSdk = 34
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

buildTypes {
Expand All @@ -40,13 +41,14 @@ android {
}

kotlinOptions {
jvmTarget = "1.8"
jvmTarget = "17"
}

buildFeatures.dataBinding = true

packagingOptions {
exclude("META-INF/proguard/androidx-annotations.pro")
packaging {
resources {
excludes += setOf("META-INF/proguard/androidx-annotations.pro")
}
}

testOptions {
Expand All @@ -67,5 +69,5 @@ dependencies {

repositories {
google()
jcenter()
mavenCentral()
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package net.pot8os.kotlintestsample

import androidx.test.ext.junit.runners.AndroidJUnit4
import net.pot8s.kotlintestsample.CalculatorSpec
import net.pot8os.kotlintestsample.CalculatorSpec
import org.junit.runner.RunWith

/**
Expand Down
32 changes: 16 additions & 16 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.pot8os.kotlintestsample">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.MyApp">
<activity android:name="net.pot8os.kotlintestsample.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.MyApp">
<activity
android:name="net.pot8os.kotlintestsample.MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package net.pot8os.kotlintestsample

import android.os.Build
import androidx.test.ext.junit.runners.AndroidJUnit4
import net.pot8s.kotlintestsample.CalculatorSpec
import org.junit.runner.RunWith
import org.robolectric.annotation.Config

Expand All @@ -11,6 +10,6 @@ import org.robolectric.annotation.Config
*/
@RunWith(AndroidJUnit4::class)
@Config(
sdk = [Build.VERSION_CODES.P]
sdk = [Build.VERSION_CODES.UPSIDE_DOWN_CAKE]
)
class RobolectricCalculatorTest : CalculatorSpec()
75 changes: 75 additions & 0 deletions app/src/testShared/kotlin/CalculatorSpec.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package net.pot8os.kotlintestsample

import androidx.fragment.app.testing.launchFragmentInContainer
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import org.junit.Before
import org.junit.Test
import java.text.DecimalFormat

/**
* @author So Nakamura, 2020-Feb-15
*/
abstract class CalculatorSpec {

@Before
fun setup() {
launchFragmentInContainer<CalculatorFragment>(themeResId = R.style.Theme_MyApp)
}

@Test
fun testSum() {
onView(withId(R.id.button_1)).perform(click())
onView(withId(R.id.button_2)).perform(click())
onView(withId(R.id.button_3)).perform(click())
onView(withId(R.id.button_sum)).perform(click())
onView(withId(R.id.button_3)).perform(click())
onView(withId(R.id.button_2)).perform(click())
onView(withId(R.id.button_1)).perform(click())
onView(withId(R.id.button_calc)).perform(click())
onView(withId(R.id.field)).check(matches(withText("${123 + 321}")))
}

@Test
fun testSub() {
onView(withId(R.id.button_9)).perform(click())
onView(withId(R.id.button_9)).perform(click())
onView(withId(R.id.button_9)).perform(click())
onView(withId(R.id.button_sub)).perform(click())
onView(withId(R.id.button_3)).perform(click())
onView(withId(R.id.button_3)).perform(click())
onView(withId(R.id.button_3)).perform(click())
onView(withId(R.id.button_calc)).perform(click())
onView(withId(R.id.field)).check(matches(withText("${999 - 333}")))
}

@Test
fun testMul() {
onView(withId(R.id.button_1)).perform(click())
onView(withId(R.id.button_0)).perform(click())
onView(withId(R.id.button_0)).perform(click())
onView(withId(R.id.button_mul)).perform(click())
onView(withId(R.id.button_2)).perform(click())
onView(withId(R.id.button_0)).perform(click())
onView(withId(R.id.button_0)).perform(click())
onView(withId(R.id.button_calc)).perform(click())
val formatter = DecimalFormat("#,###")
onView(withId(R.id.field)).check(matches(withText(formatter.format(100 * 200))))
}

@Test
fun testDiv() {
onView(withId(R.id.button_3)).perform(click())
onView(withId(R.id.button_3)).perform(click())
onView(withId(R.id.button_3)).perform(click())
onView(withId(R.id.button_div)).perform(click())
onView(withId(R.id.button_1)).perform(click())
onView(withId(R.id.button_0)).perform(click())
onView(withId(R.id.button_0)).perform(click())
onView(withId(R.id.button_calc)).perform(click())
onView(withId(R.id.field)).check(matches(withText("${333 / 100.0}")))
}
}

This file was deleted.

6 changes: 3 additions & 3 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ plugins {
allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}

dependencies {
implementation("com.android.tools.build:gradle:4.0.0")
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.72")
implementation("com.android.tools.build:gradle:8.2.2")
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.22")
}
24 changes: 13 additions & 11 deletions buildSrc/src/main/java/Dependencies.kt
Original file line number Diff line number Diff line change
@@ -1,38 +1,40 @@
import org.gradle.kotlin.dsl.DependencyHandlerScope

fun DependencyHandlerScope.kotlin() {
implementation("org.jetbrains.kotlin:kotlin-stdlib:1.3.72")
implementation("org.jetbrains.kotlin:kotlin-stdlib:1.9.22")
}

fun DependencyHandlerScope.fragment() {
val version = "1.2.5"
val version = "1.6.2"
implementation("androidx.fragment:fragment-ktx:$version")
debugImplementation("androidx.fragment:fragment-testing:$version")
androidTestImplementation("androidx.fragment:fragment-testing:1.6.0")
}

fun DependencyHandlerScope.compat() {
implementation("androidx.appcompat:appcompat:1.1.0")
implementation("androidx.appcompat:appcompat:1.6.1")
}

fun DependencyHandlerScope.layout() {
implementation("androidx.constraintlayout:constraintlayout:1.1.3")
implementation("com.google.android.material:material:1.1.0")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
implementation("com.google.android.material:material:1.11.0")
}

fun DependencyHandlerScope.viewmodel() {
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0")
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.7.0")
}

fun DependencyHandlerScope.test() {
// These dependencies are consumed in both unit tests and instrumented tests.
debugImplementation("androidx.test.espresso:espresso-core:3.2.0")
debugImplementation("androidx.test:runner:1.2.0")
debugImplementation("androidx.test:rules:1.2.0")
debugImplementation("androidx.test.ext:junit-ktx:1.1.1")
debugImplementation("androidx.test.espresso:espresso-core:3.5.1")
debugImplementation("androidx.test:runner:1.5.2")
debugImplementation("androidx.test:rules:1.5.0")
debugImplementation("androidx.test.ext:junit-ktx:1.1.5")
// Regarding robolectric, only test target is sufficient.
testImplementation("org.robolectric:robolectric:4.3.1")
testImplementation("org.robolectric:robolectric:4.11.1")
}

private const val implementation = "implementation"
private const val debugImplementation = "debugImplementation"
private const val testImplementation = "testImplementation"
private const val androidTestImplementation = "androidTestImplementation"
3 changes: 3 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@
org.gradle.parallel=true
org.gradle.caching=true
android.useAndroidX=true
android.defaults.buildfeatures.buildconfig=true
android.nonTransitiveRClass=false
android.nonFinalResIds=false
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-all.zip

0 comments on commit 92e398a

Please sign in to comment.