Skip to content

Commit

Permalink
Convert toolbar-title to Kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
chiuki committed Jan 19, 2019
1 parent 5f0cd74 commit 8b6fc6e
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 75 deletions.
11 changes: 6 additions & 5 deletions toolbar-title/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 27
buildToolsVersion '27.0.1'
compileSdkVersion 28
buildToolsVersion '28.0.3'

defaultConfig {
applicationId 'com.sqisland.android.espresso.toolbar_title'
minSdkVersion 15
targetSdkVersion 27
targetSdkVersion 28
versionCode 1
versionName '1.0.0'

Expand All @@ -20,8 +21,8 @@ android {
}

dependencies {
implementation 'com.android.support:appcompat-v7:27.0.1'

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0'
androidTestImplementation ('com.android.support.test.espresso:espresso-core:3.0.1') {
exclude module: 'support-annotations'
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.sqisland.espresso.toolbar_title

import android.support.test.InstrumentationRegistry
import android.support.test.espresso.Espresso.onView
import android.support.test.espresso.ViewInteraction
import android.support.test.espresso.assertion.ViewAssertions.matches
import android.support.test.espresso.matcher.BoundedMatcher
import android.support.test.espresso.matcher.ViewMatchers.isAssignableFrom
import android.support.test.rule.ActivityTestRule
import android.support.test.runner.AndroidJUnit4
import android.support.v7.widget.Toolbar
import org.hamcrest.Description
import org.hamcrest.Matcher
import org.hamcrest.core.Is.`is`
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class MainActivityTest {
@get:Rule
val activityRule = ActivityTestRule(MainActivity::class.java)

@Test
fun toolbarTitle() {
val title = InstrumentationRegistry.getTargetContext().getString(R.string.my_title)
matchToolbarTitle(title)
}

private fun matchToolbarTitle(title: CharSequence): ViewInteraction {
return onView(isAssignableFrom(Toolbar::class.java))
.check(matches(withToolbarTitle(`is`(title))))
}

private fun withToolbarTitle(textMatcher: Matcher<CharSequence>): Matcher<Any> {
return object : BoundedMatcher<Any, Toolbar>(Toolbar::class.java) {
public override fun matchesSafely(toolbar: Toolbar): Boolean {
return textMatcher.matches(toolbar.title)
}

override fun describeTo(description: Description) {
description.appendText("with toolbar title: ")
textMatcher.describeTo(description)
}
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.sqisland.espresso.toolbar_title

import android.os.Bundle
import android.support.v7.app.AppCompatActivity

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setTitle(R.string.my_title)
}
}
16 changes: 7 additions & 9 deletions toolbar-title/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.3.11'
repositories {
maven {
url 'https://maven.google.com'
name 'Google'
}
mavenCentral()
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.android.tools.build:gradle:3.3.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -18,11 +18,9 @@ buildscript {

allprojects {
repositories {
maven {
url 'https://maven.google.com'
name 'Google'
}
mavenCentral()
jcenter()
google()
}
}

Expand Down
2 changes: 1 addition & 1 deletion toolbar-title/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-4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-all.zip

0 comments on commit 8b6fc6e

Please sign in to comment.