Skip to content

Instantly share code, notes, and snippets.

@ecgreb
Created January 24, 2017 22:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ecgreb/dc174cea50e3b7142671da29058ea247 to your computer and use it in GitHub Desktop.
Save ecgreb/dc174cea50e3b7142671da29058ea247 to your computer and use it in GitHub Desktop.
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