1 package com.xtremelabs.robolectric.res;
2 
3 
4 import static com.xtremelabs.robolectric.util.TestUtil.resourceFile;
5 import static org.hamcrest.CoreMatchers.equalTo;
6 import static org.junit.Assert.*;
7 
8 import org.junit.Test;
9 import org.junit.runner.RunWith;
10 
11 import android.view.MenuItem;
12 
13 import com.xtremelabs.robolectric.R;
14 import com.xtremelabs.robolectric.Robolectric;
15 import com.xtremelabs.robolectric.WithTestDefaultsRunner;
16 import com.xtremelabs.robolectric.tester.android.view.TestMenu;
17 
18 @RunWith(WithTestDefaultsRunner.class)
19 public class MenuResourceLoaderTest {
20 
21 	@Test
shouldInflateComplexMenu()22     public void shouldInflateComplexMenu() throws Exception {
23         ResourceLoader resourceLoader = new ResourceLoader(10, R.class, resourceFile("res"), resourceFile("menu"));
24         TestMenu testMenu = new TestMenu();
25     	resourceLoader.inflateMenu(Robolectric.application, R.menu.test_withchilds, testMenu);
26     	assertThat(testMenu.size(), equalTo(4));
27     }
28 
29 	@Test
shouldParseSubItemCorrectly()30     public void shouldParseSubItemCorrectly() throws Exception {
31         ResourceLoader resourceLoader = new ResourceLoader(10, R.class, resourceFile("res"), resourceFile("menu"));
32         TestMenu testMenu = new TestMenu();
33     	resourceLoader.inflateMenu(Robolectric.application, R.menu.test_withchilds, testMenu);
34     	MenuItem mi = testMenu.findItem(R.id.test_submenu_1);
35     	assertTrue(mi.hasSubMenu());
36     	assertThat(mi.getSubMenu().size(), equalTo(2) );
37     	assertThat(mi.getSubMenu().getItem(1).getTitle() + "", equalTo("Test menu item 3") );
38     }
39 }
40