Created
January 24, 2017 22:31
-
-
Save ecgreb/dc174cea50e3b7142671da29058ea247 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MapViewTest { | |
// ... | |
@Test public void shouldInflateLayoutWithOverlayModeSdk() throws Exception { | |
Context context = mock(Context.class); | |
TypedArray typedArray = mock(TypedArray.class); | |
TestLayoutInflater layoutInflater = new TestLayoutInflater(context); | |
initMockAttributes(context, typedArray, layoutInflater, OVERLAY_MODE_SDK); | |
MapView mapView = new MapView(context, mock(AttributeSet.class)); | |
assertThat(layoutInflater.getResId()).isEqualTo(R.layout.mz_view_map); | |
assertThat(layoutInflater.getRoot()).isEqualTo(mapView); | |
} | |
@Test public void shouldInflateLayoutWithOverlayModeClassic() throws Exception { | |
Context context = mock(Context.class); | |
TypedArray typedArray = mock(TypedArray.class); | |
TestLayoutInflater layoutInflater = new TestLayoutInflater(context); | |
initMockAttributes(context, typedArray, layoutInflater, OVERLAY_MODE_CLASSIC); | |
MapView mapView = new MapView(context, mock(AttributeSet.class)); | |
assertThat(layoutInflater.getResId()).isEqualTo(R.layout.mz_view_map_classic); | |
assertThat(layoutInflater.getRoot()).isEqualTo(mapView); | |
} | |
private void initMockAttributes(Context context, TypedArray typedArray, | |
TestLayoutInflater layoutInflater, int overlayMode) { | |
when(context.obtainStyledAttributes(any(AttributeSet.class), eq(R.styleable.MapView))) | |
.thenReturn(typedArray); | |
when(context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)) | |
.thenReturn(layoutInflater); | |
when(typedArray.getInteger(R.styleable.MapView_overlayMode, OVERLAY_MODE_SDK)) | |
.thenReturn(overlayMode); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment