espace-formation-initiation-android / CardView / Application / tests / src / com / example / android / cardview / SampleTests.java
Historique | Voir | Annoter | Télécharger (2,406 ko)
1 | 1 | segarra | /*
|
---|---|---|---|
2 | * Copyright 2014 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 | package com.example.android.cardview; |
||
17 | |||
18 | import android.test.ActivityInstrumentationTestCase2; |
||
19 | |||
20 | /**
|
||
21 | * Unit tests for CardView samples.
|
||
22 | */
|
||
23 | public class SampleTests extends ActivityInstrumentationTestCase2<CardViewActivity> { |
||
24 | |||
25 | private CardViewActivity mActivity;
|
||
26 | private CardViewFragment mFragment;
|
||
27 | |||
28 | public SampleTests() {
|
||
29 | super(CardViewActivity.class);
|
||
30 | } |
||
31 | |||
32 | @Override
|
||
33 | protected void setUp() throws Exception { |
||
34 | super.setUp();
|
||
35 | mActivity = getActivity(); |
||
36 | mFragment = (CardViewFragment) mActivity.getFragmentManager().findFragmentById(R.id |
||
37 | .container); |
||
38 | } |
||
39 | |||
40 | public void testPreconditions() { |
||
41 | assertNotNull(String.format("%s is null", CardViewActivity.class.getSimpleName()), |
||
42 | mActivity); |
||
43 | assertNotNull(String.format("%s is null", CardViewFragment.class.getSimpleName()), |
||
44 | mFragment); |
||
45 | assertNotNull("SeekBar for Radius is null", mFragment.mRadiusSeekBar);
|
||
46 | assertNotNull("SeekBar for Elevation is null", mFragment.mElevationSeekBar);
|
||
47 | } |
||
48 | |||
49 | public void testRadiusSeekbarChangesRadiusOfCardView() { |
||
50 | getInstrumentation().runOnMainSync(new Runnable() { |
||
51 | @Override
|
||
52 | public void run() { |
||
53 | float radius = 50.0f; |
||
54 | mFragment.mRadiusSeekBar.setProgress((int) radius);
|
||
55 | assertEquals(radius, mFragment.mCardView.getRadius()); |
||
56 | } |
||
57 | }); |
||
58 | } |
||
59 | |||
60 | public void testElevationSeekbarChangesElevationOfCardView() { |
||
61 | getInstrumentation().runOnMainSync(new Runnable() { |
||
62 | @Override
|
||
63 | public void run() { |
||
64 | float elevation = 40.0f; |
||
65 | mFragment.mElevationSeekBar.setProgress((int) elevation);
|
||
66 | assertEquals(elevation, mFragment.mCardView.getElevation()); |
||
67 | } |
||
68 | }); |
||
69 | } |
||
70 | } |