ClosedCaptionManagerFactory { public CaptionManager createCaptionManager(Context context) { if (androidVersion.isMarshmallowOrHigher()) { return ClosedCaptionManagerMarshmallow.newInstance(context); } else if (androidVersion.isKitKatOrHigher()) { return ClosedCaptionManagerKitKat.newInstance(context); } else { return new DummyClosedCaptionManager(); } } ClosedCaptionManagerFactory(AndroidVersion androidVersion); static ClosedCaptionManagerFactory newInstance(); CaptionManager createCaptionManager(Context context);  }
@Test public void givenAndroidVersionMarshmallowOrHigher_whenCreatingANewCaptionManager_thenMarshmallowClosedCaptionManagerReturned() { when(mockAndroidVersion.isMarshmallowOrHigher()).thenReturn(true); CaptionManager captionManager = closedCaptionManagerFactory.createCaptionManager(mockContext); assertThat(captionManager).isInstanceOf(ClosedCaptionManagerMarshmallow.class); }
@Test public void givenAndroidVersionKitKatOrHigher_whenCreatingANewCaptionManager_thenKitKatClosedCaptionManagerReturned() { when(mockAndroidVersion.isKitKatOrHigher()).thenReturn(true); CaptionManager captionManager = closedCaptionManagerFactory.createCaptionManager(mockContext); assertThat(captionManager).isInstanceOf(ClosedCaptionManagerKitKat.class); }
@Test public void givenAndroidVersionLowerThanKitKat_whenCreatingANewCaptionManager_thenDummyClosedCaptionManagerReturned() { when(mockAndroidVersion.isKitKatOrHigher()).thenReturn(false); CaptionManager captionManager = closedCaptionManagerFactory.createCaptionManager(mockContext); assertThat(captionManager).isInstanceOf(DummyClosedCaptionManager.class); }