Skip to content

Commit

Permalink
build: provide integration test projects
Browse files Browse the repository at this point in the history
  • Loading branch information
tynn committed Jan 10, 2024
1 parent aab8655 commit 770ad81
Show file tree
Hide file tree
Showing 32 changed files with 591 additions and 11 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
*.iml
.gradle
.idea
local.properties
Expand Down
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@
[![API][api-shield]][api]
###### A context aware parcelable string abstraction for _Android_

interface AString extends Parcelable {
interface AString : Parcelable {
fun invoke(context: Context): CharSequence?
}

The library is implemented with _Kotlin_ for _Java_, thus
the _Kotlin Standard Library_ is not required to use _AString_.

The main use-case is to provide a generic string data type for
inter-layer communication and state management. Therefore every
implementation should provide meaningful `equals` and `hashCode`
Expand Down
27 changes: 27 additions & 0 deletions astring/catalog/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
plugins {
id 'version-catalog'
}

catalog.versionCatalog {
it.version 'astring', version
}

final module = project
rootProject.allprojects {
if (project != module) pluginManager.withPlugin('maven-publish') {
module.catalog.versionCatalog {
final name = project.name
final alias = name == 'astring' ? name : "astring-$name"
it.library(alias, group, name).versionRef 'astring'
}
}
}

tasks.register('updateCatalog', Copy) {
into projectDir
include 'libs.versions.toml'
from tasks.named('generateCatalogAsToml')
rename 'libs.versions.toml', 'versions.toml'
filter { it.startsWith('#') ? null : it }
outputs.upToDateWhen { false }
}
15 changes: 15 additions & 0 deletions astring/catalog/versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[metadata]
format.version = "1.1"

[versions]
astring = "unspecified"

[libraries]
astring = {group = "xyz.tynn.astring", name = "astring", version.ref = "astring" }
astring-appcompat = {group = "xyz.tynn.astring", name = "appcompat", version.ref = "astring" }
astring-binding = {group = "xyz.tynn.astring", name = "binding", version.ref = "astring" }
astring-bom = {group = "xyz.tynn.astring", name = "bom", version.ref = "astring" }
astring-compose = {group = "xyz.tynn.astring", name = "compose", version.ref = "astring" }
astring-core = {group = "xyz.tynn.astring", name = "core", version.ref = "astring" }
astring-material = {group = "xyz.tynn.astring", name = "material", version.ref = "astring" }

1 change: 1 addition & 0 deletions compose/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
alias libs.plugins.android
id 'integration-test'
id 'nexus-publish'
}

Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions gradle/convention/src/integration-test.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
['check', 'connectedCheck'].each {
tasks.named(it) { task ->
final path = ":${project.name}:${task.name}"
dependsOn gradle.includedBuild('integration').task(path)
}
}
File renamed without changes.
14 changes: 12 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,39 @@ kotlin = "1.9.22"

[plugins]
android = { id = "com.android.library", version.ref = "android" }
android-app = { id = "com.android.application", version.ref = "android" }
conventions = "xyz.tynn.convention.project:0.0.5"
kotlin = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
kotlin-kapt = { id = "org.jetbrains.kotlin.kapt", version.ref = "kotlin" }
paparazzi = "app.cash.paparazzi:1.3.1"
publish = "io.github.gradle-nexus.publish-plugin:1.3.0"

[libraries]
androidx-activity-compose = "androidx.activity:activity-compose:1.8.2"
androidx-appcompat = "androidx.appcompat:appcompat:1.6.1"
androidx-compose-bom = "androidx.compose:compose-bom:2023.10.01"
androidx-compose-material.module = "androidx.compose.material:material"
androidx-compose-ui.module = "androidx.compose.ui:ui"
androidx-compose-ui-preview.module = "androidx.compose.ui:ui-tooling-preview"
androidx-compose-ui-test.module = "androidx.compose.ui:ui-test-junit4"
androidx-compose-ui-tooling.module = "androidx.compose.ui:ui-tooling"
androidx-core = "androidx.core:core:1.12.0"
androidx-core-ktx = "androidx.core:core-ktx:1.12.0"
androidx-databinding-common = { module = "androidx.databinding:databinding-common", version.ref = "android" }
androidx-fragment = "androidx.fragment:fragment:1.6.2"
androidx-test-core = "androidx.test:core:1.5.0"
androidx-test-espresso = "androidx.test.espresso:espresso-core:3.5.1"
androidx-test-junit = "androidx.test.ext:junit:1.1.5"
androidx-test-runner = "androidx.test:runner:1.5.2"
google-material = "com.google.android.material:material:1.11.0"
junit = "junit:junit:4.13.2"
kotlin-stdlib.module = "org.jetbrains.kotlin:kotlin-stdlib"
kotlin-bom = { module = "org.jetbrains.kotlin:kotlin-bom", version.ref = "kotlin" }
kotlin-test.module = "org.jetbrains.kotlin:kotlin-test-junit"
mockk = "io.mockk:mockk:1.13.9"
robolectric = "org.robolectric:robolectric:4.11.1"
slf4j = "org.slf4j:slf4j-nop:2.0.10"
slf4j = "org.slf4j:slf4j-nop:2.0.11"

[bundles]
compose = ["androidx-activity-compose", "androidx-compose-ui-preview", "androidx-compose-material"]
testing = ["kotlin-test", "junit", "mockk", "slf4j"]
testing-android = ["androidx-test-runner", "androidx-test-espresso", "androidx-test-junit", "junit"]
16 changes: 16 additions & 0 deletions integration/binding/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
plugins {
alias libs.plugins.android.app
}

android {
buildFeatures {
dataBinding true
}
}

dependencies {
implementation buildLibs.astring.core
implementation buildLibs.astring.binding

androidTestImplementation libs.bundles.testing.android
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright 2024 Christian Schmitz
// SPDX-License-Identifier: Apache-2.0

package xyz.tynn.astring.integration.binding;

import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.closeSoftKeyboard;
import static androidx.test.espresso.action.ViewActions.replaceText;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withText;

import androidx.test.ext.junit.rules.ActivityScenarioRule;
import androidx.test.filters.SmallTest;

import org.junit.Rule;
import org.junit.Test;

@SmallTest
public class BindingActivityTest {

@Rule
public final ActivityScenarioRule<BindingActivity> activityRule =
new ActivityScenarioRule<>(BindingActivity.class);

@Test
public void bindingActivityTest() {
onView(withId(R.id.astring_binding_converter))
.perform(replaceText("AString"),
closeSoftKeyboard());

onView(withId(R.id.astring_binding_string))
.check(matches(withText("AString")));

onView(withId(R.id.astring_binding_adapter))
.check(matches(withText("AString")));

onView(withId(R.id.astring_binding_converter))
.perform(replaceText(""));

onView(withId(R.id.astring_binding_string))
.check(matches(withText("")));

onView(withId(R.id.astring_binding_adapter))
.check(matches(withText("")));
}
}
18 changes: 18 additions & 0 deletions integration/binding/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<application
android:label="AString Binding"
tools:ignore="MissingApplicationIcon">

<activity
android:name=".BindingActivity"
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
@@ -0,0 +1,43 @@
// Copyright 2024 Christian Schmitz
// SPDX-License-Identifier: Apache-2.0

package xyz.tynn.astring.integration.binding;

import static android.util.Log.d;
import static xyz.tynn.astring.AStringKt.invokeWithContext;

import android.app.Activity;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.Observable;
import androidx.databinding.Observable.OnPropertyChangedCallback;
import androidx.databinding.ObservableField;

import java.util.Objects;

import xyz.tynn.astring.AString;
import xyz.tynn.astring.integration.binding.databinding.ActivityBindingBinding;

public class BindingActivity extends Activity {

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActivityBindingBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_binding);
ObservableField<AString> field = new ObservableField<>(AString.Null);
field.addOnPropertyChangedCallback(new OnPropertyChangedCallback() {
@Override
public void onPropertyChanged(Observable sender, int propertyId) {
log(field.get());
}
});
binding.setData(new BindingData(field));
}

private void log(AString aString) {
CharSequence string = invokeWithContext(this, aString);
d("BindingActivity", Objects.toString(string));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2024 Christian Schmitz
// SPDX-License-Identifier: Apache-2.0

package xyz.tynn.astring.integration.binding;

import androidx.databinding.ObservableField;

import xyz.tynn.astring.AString;

public class BindingData {

private final ObservableField<AString> aString;

BindingData(ObservableField<AString> aString) {
this.aString = aString;
}

public ObservableField<AString> getAString() {
return aString;
}
}
39 changes: 39 additions & 0 deletions integration/binding/src/main/res/layout/activity_binding.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<layout xmlns:android="http://schemas.android.com/apk/res/android">

<data>

<import type="xyz.tynn.astring.binding.AStringBinding" />

<variable
name="data"
type="xyz.tynn.astring.integration.binding.BindingData" />
</data>

<LinearLayout xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".BindingActivity">

<TextView
android:id="@+id/astring_binding_string"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@{data.aString.invoke(context)}" />

<TextView
android:id="@+id/astring_binding_adapter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@{data.aString}" />

<EditText
android:id="@+id/astring_binding_converter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:importantForAutofill="no"
android:inputType="text"
android:text="@={AStringBinding.load(context, data.aString)}"
tools:ignore="LabelFor" />
</LinearLayout>
</layout>
18 changes: 18 additions & 0 deletions integration/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
plugins {
alias libs.plugins.android.app apply false
alias libs.plugins.kotlin apply false
alias libs.plugins.paparazzi apply false
alias libs.plugins.conventions
}

allprojects {
group = 'xyz.tynn.astring.integration'
}

subprojects {
pluginManager.withPlugin(libs.plugins.android.app.get().pluginId) {
java.toolchain.languageVersion.set JavaLanguageVersion.of(17)
dependencies { api platform(libs.kotlin.bom) }
android.defaultConfig.minSdk 21
}
}
39 changes: 39 additions & 0 deletions integration/compose/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
plugins {
alias libs.plugins.android.app
alias libs.plugins.kotlin
alias libs.plugins.paparazzi
}

android {
buildFeatures {
compose true
}

composeOptions {
kotlinCompilerExtensionVersion = libs.versions.compose.compiler.get()
}

kotlinOptions {
freeCompilerArgs += [
'-P', 'plugin:androidx.compose.compiler.plugins.kotlin:suppressKotlinVersionCompatibilityCheck=' +
libs.versions.kotlin.get()
]
}
}

tasks.named('check') {
dependsOn tasks.named('verifyPaparazzi')
}

dependencies {
implementation buildLibs.astring.core
implementation buildLibs.astring.compose
implementation libs.androidx.appcompat

implementation libs.bundles.compose
debugImplementation libs.androidx.compose.ui.tooling

androidTestImplementation platform(libs.androidx.compose.bom)
androidTestImplementation libs.androidx.compose.ui.test
androidTestImplementation libs.bundles.testing.android
}
Loading

0 comments on commit 770ad81

Please sign in to comment.