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 android.widget.cts;
18 
19 import static org.junit.Assert.assertEquals;
20 
21 import android.support.test.annotation.UiThreadTest;
22 import android.support.test.filters.MediumTest;
23 import android.support.test.rule.ActivityTestRule;
24 import android.support.test.runner.AndroidJUnit4;
25 import android.widget.Toolbar;
26 
27 import org.junit.Before;
28 import org.junit.Rule;
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 
32 @MediumTest
33 @RunWith(AndroidJUnit4.class)
34 public class ToolbarWithMarginsTest {
35     private ToolbarWithMarginsCtsActivity mActivity;
36     private Toolbar mMainToolbar;
37 
38     @Rule
39     public ActivityTestRule<ToolbarWithMarginsCtsActivity> mActivityRule =
40             new ActivityTestRule<>(ToolbarWithMarginsCtsActivity.class);
41 
42     @Before
setup()43     public void setup() {
44         mActivity = mActivityRule.getActivity();
45         mMainToolbar = mActivity.getMainToolbar();
46     }
47 
48     @UiThreadTest
49     @Test
testGetTitleMargins()50     public void testGetTitleMargins() {
51         assertEquals(5, mMainToolbar.getTitleMarginStart());
52         assertEquals(10, mMainToolbar.getTitleMarginTop());
53         assertEquals(15, mMainToolbar.getTitleMarginEnd());
54         assertEquals(20, mMainToolbar.getTitleMarginBottom());
55     }
56 
57     @UiThreadTest
58     @Test
testSetTitleMargins()59     public void testSetTitleMargins() {
60         Toolbar toolbar = (Toolbar) mActivity.findViewById(R.id.toolbar2);
61 
62         toolbar.setTitleMargin(5, 10, 15, 20);
63         assertEquals(5, toolbar.getTitleMarginStart());
64         assertEquals(10, toolbar.getTitleMarginTop());
65         assertEquals(15, toolbar.getTitleMarginEnd());
66         assertEquals(20, toolbar.getTitleMarginBottom());
67 
68         toolbar.setTitleMarginStart(25);
69         toolbar.setTitleMarginTop(30);
70         toolbar.setTitleMarginEnd(35);
71         toolbar.setTitleMarginBottom(40);
72         assertEquals(25, toolbar.getTitleMarginStart());
73         assertEquals(30, toolbar.getTitleMarginTop());
74         assertEquals(35, toolbar.getTitleMarginEnd());
75         assertEquals(40, toolbar.getTitleMarginBottom());
76     }
77 }
78