1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.example.android.cardview 18 19 import android.support.test.InstrumentationRegistry 20 import android.support.test.rule.ActivityTestRule 21 import android.support.test.runner.AndroidJUnit4 22 import org.junit.Assert.assertEquals 23 import org.junit.Assert.assertNotNull 24 import org.junit.Before 25 import org.junit.Rule 26 import org.junit.Test 27 import org.junit.runner.RunWith 28 29 /** 30 * Tests for CardView sample. 31 */ 32 @RunWith(AndroidJUnit4::class) 33 class SampleTests { 34 35 private lateinit var fragment: CardViewFragment 36 37 @Rule @JvmField 38 val activityTestRule = ActivityTestRule(CardViewActivity::class.java) 39 setUpnull40 @Before fun setUp() { 41 activityTestRule.activity.fragmentManager.beginTransaction() 42 fragment = activityTestRule.activity.fragmentManager 43 .findFragmentById(R.id.container) as CardViewFragment 44 } 45 testPreconditionsnull46 @Test fun testPreconditions() { 47 assertNotNull(activityTestRule.activity) 48 assertNotNull(fragment) 49 assertNotNull(fragment.radiusSeekBar) 50 assertNotNull(fragment.elevationSeekBar) 51 } 52 testRadiusSeekbarChangesRadiusOfCardViewnull53 @Test fun testRadiusSeekbarChangesRadiusOfCardView() { 54 InstrumentationRegistry.getInstrumentation().runOnMainSync { 55 val radius = 50.0f 56 fragment.radiusSeekBar.progress = radius.toInt() 57 assertEquals(radius, fragment.cardView.radius) 58 } 59 } 60 testElevationSeekbarChangesElevationOfCardViewnull61 @Test fun testElevationSeekbarChangesElevationOfCardView() { 62 InstrumentationRegistry.getInstrumentation().runOnMainSync { 63 val elevation = 40.0f 64 fragment.elevationSeekBar.progress = elevation.toInt() 65 assertEquals(elevation, fragment.cardView.elevation) 66 } 67 } 68 69 }