Skip to content

Instantly share code, notes, and snippets.

@lfryc
Forked from jhuska/Foo.java
Created February 5, 2014 10:19
Show Gist options
  • Save lfryc/8820686 to your computer and use it in GitHub Desktop.
Save lfryc/8820686 to your computer and use it in GitHub Desktop.
@Override
public boolean canEnhance(InstanceOrCallableInstance instance, Class<?> droneType, Class<? extends Annotation> qualifier) {
if (RemoteWebDriver.class == droneType || ReusableRemoteWebDriver.class == droneType) {
return true;
}
Class<?> realInstanceClass = instance.asInstance(droneType).getClass();
if (RemoteWebDriver.class == realInstanceClass || ReusableRemoteWebDriver.class == realInstanceClass)
|| DroneAugmented.class.isAssignableFrom(realInstanceClass)) {
return true;
}
return false;
}
@Test
public void testCanEnhance() {
RemoteWebDriver driver = mock(RemoteWebDriver.class);
ReusableRemoteWebDriver reusableDriver = mock(ReusableRemoteWebDriver.class);
InstanceOrCallableInstance instance = mock(InstanceOrCallableInstance.class);
doReturn(driver).when(instance).asInstance(RemoteWebDriver.class);
doReturn(driver).when(instance).asInstance(WebDriver.class);
doReturn(driver).when(instance).asInstance(driver.getClass());
doReturn(reusableDriver).when(instance).asInstance(ReusableRemoteWebDriver.class);
System.out.println(driver.getClass());
assertTrue(enhancer.canEnhance(instance, RemoteWebDriver.class, Default.class));
assertTrue(enhancer.canEnhance(instance, ReusableRemoteWebDriver.class, Default.class));
assertTrue(enhancer.canEnhance(instance, WebDriver.class, Default.class));
assertTrue(enhancer.canEnhance(instance, driver.getClass(), Default.class))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment