@Test @Config(maxSdk = JELLY_BEAN) public void notSupportedInJellyBean() throws Exception { try { ShadowDisplayManager.removeDisplay(0); fail("Expected Exception thrown"); } catch (UnsupportedOperationException e) { assertThat(e).hasMessageThat().contains("displays not supported in Jelly Bean"); } }
@Test @Config(minSdk = JELLY_BEAN_MR1) public void forNonexistentDisplay_removeDisplay_shouldThrow() throws Exception { try { ShadowDisplayManager.removeDisplay(3); fail("Expected Exception thrown"); } catch (IllegalStateException e) { assertThat(e).hasMessageThat().contains("no display 3"); } }
@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); }