### Question:
DeviceManagerImpl implements DeviceManager { @VisibleForTesting String getScreenSize() { WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); if (windowManager != null) { Display display = windowManager.getDefaultDisplay(); final DisplayMetrics out = new DisplayMetrics(); display.getMetrics(out); return String.format(Locale.US, "%dx%d", out.widthPixels, out.heightPixels); } return "unknown"; } @VisibleForTesting  DeviceManagerImpl(Context context); @WorkerThread @Nullable @Override String getAdvertisingId(); @Override Map<String, String> getSignals(); @Override String getTimeStamp(); @Override boolean isOldInstallation(); @Override String getUserAgent();  }### Answer:
@Test public void getScreenSize_hasWindowManager_returnValidSize() { WindowManager windowManager = mock(WindowManager.class); Display display = mock(Display.class); when(context.getSystemService(Context.WINDOW_SERVICE)).thenReturn(windowManager); when(windowManager.getDefaultDisplay()).thenReturn(display); doAnswer(new Answer<DisplayMetrics>() { @Override public DisplayMetrics answer(InvocationOnMock invocation) throws Throwable { DisplayMetrics displayMetrics = invocation.getArgument(0); displayMetrics.widthPixels = 1080; displayMetrics.heightPixels = 500; return displayMetrics; } }).when(display).getMetrics(any(DisplayMetrics.class)); String screenSize = deviceManager.getScreenSize(); assertEquals("1080x500", screenSize); }
@Test public void getScreenSize_doesNotHaveWindowManager_returnUnknown() { when(context.getSystemService(Context.WINDOW_SERVICE)).thenReturn(null); String screenSize = deviceManager.getScreenSize(); assertEquals("unknown", screenSize); }