@Test @Config(minSdk = JELLY_BEAN_MR1) public void addDisplay_shouldNotifyListeners() throws Exception { List<String> events = new ArrayList<>(); instance.registerDisplayListener(new MyDisplayListener(events), null); int displayId = ShadowDisplayManager.addDisplay("w100dp-h200dp"); assertThat(events).containsExactly("Added " + displayId); }
@Test @Config(minSdk = JELLY_BEAN_MR1) public void changeDisplay_shouldAllowPartialChanges() throws Exception { List<String> events = new ArrayList<>(); instance.registerDisplayListener(new MyDisplayListener(events), null); int displayId = ShadowDisplayManager.addDisplay("w100dp-h200dp"); ShadowDisplayManager.changeDisplay(displayId, "+h201dp-land"); Display display = getGlobal().getRealDisplay(displayId); assertThat(display.getWidth()).isEqualTo(201); assertThat(display.getHeight()).isEqualTo(100); assertThat(display.getOrientation()).isEqualTo(Surface.ROTATION_90); assertThat(events).containsExactly( "Added " + displayId, "Changed " + displayId); }
@Test @Config(minSdk = JELLY_BEAN_MR1) public void addDisplay() throws Exception { int displayId = ShadowDisplayManager.addDisplay("w100dp-h200dp"); assertThat(displayId).isGreaterThan(0); DisplayInfo di = getGlobal().getDisplayInfo(displayId); assertThat(di.appWidth).isEqualTo(100); assertThat(di.appHeight).isEqualTo(200); Display display = instance.getDisplay(displayId); assertThat(display.getDisplayId()).isEqualTo(displayId); }
@Test @Config(minSdk = JELLY_BEAN_MR1) public void changeAndRemoveDisplay_shouldNotifyListeners() throws Exception { List<String> events = new ArrayList<>(); instance.registerDisplayListener(new MyDisplayListener(events), null); int displayId = ShadowDisplayManager.addDisplay("w100dp-h200dp"); ShadowDisplayManager.changeDisplay(displayId, "w300dp-h400dp"); Display display = getGlobal().getRealDisplay(displayId); assertThat(display.getWidth()).isEqualTo(300); assertThat(display.getHeight()).isEqualTo(400); assertThat(display.getOrientation()).isEqualTo(Surface.ROTATION_0); ShadowDisplayManager.removeDisplay(displayId); assertThat(events).containsExactly( "Added " + displayId, "Changed " + displayId, "Removed " + displayId); }