### Question:
AbstractLocatorHandler implements LocatorHandler<T> { @Override public void setHooks(HookChainBuilder hookChainBuilder, List<HookDefinition<?>> hookDefinitions) { if (isEmpty(hookDefinitions)) { this.hookChainBuilder = null; this.hookDefinitions = null; hooks = null; } else { this.hookChainBuilder = hookChainBuilder; this.hookDefinitions = hookDefinitions; hooks = hookChainBuilder .build(this::getElement, () -> locator, () -> proxy.toString(), hookDefinitions); } } AbstractLocatorHandler(ElementLocator locator); @Override boolean addListener(ProxyElementListener listener); @Override boolean removeListener(ProxyElementListener listener); @Override T getLocatorResult(); @Override void setHooks(HookChainBuilder hookChainBuilder, List<HookDefinition<?>> hookDefinitions); @Override ElementLocator getLocator(); @Override ElementLocator getHookLocator(); @Override boolean loaded(); @Override boolean present(); @Override void reset(); void setProxy(T proxy); abstract T getLocatorResultImpl(); String proxyToString(String elementToString);  }### Answer:
@Test public void shouldSetHooksWhenHookDefinitionsAreNotEmpty() { HookChainBuilder hookChainBuilder = mock(HookChainBuilder.class); HookDefinition<?> hookDefinition1 = mock(HookDefinition.class); HookDefinition<?> hookDefinition2 = mock(HookDefinition.class); List<HookDefinition<?>> hookDefinitions = ImmutableList.of(hookDefinition1, hookDefinition2); locatorHandler.setHooks(hookChainBuilder, hookDefinitions); assertThat(locatorHandler.hookChainBuilder).isSameAs(hookChainBuilder); assertThat(locatorHandler.hookDefinitions).isSameAs(hookDefinitions); verify(locatorHandler.hookChainBuilder).build(any(), any(), any(), eq(hookDefinitions)); assertThat(locatorHandler.hooks).isNotNull(); }
@Test public void shouldSetHooksToNullWhenHookDefinitionsAreEmpty() { HookChainBuilder hookChainBuilder = mock(HookChainBuilder.class); locatorHandler.setHooks(hookChainBuilder, emptyList()); assertThat(locatorHandler.hookChainBuilder).isNull(); assertThat(locatorHandler.hookDefinitions).isNull(); assertThat(locatorHandler.hooks).isNull(); }
@Test public void shouldSetHooksToNullWhenHookDefinitionsIsNull() { HookChainBuilder hookChainBuilder = mock(HookChainBuilder.class); locatorHandler.setHooks(hookChainBuilder, null); assertThat(locatorHandler.hookChainBuilder).isNull(); assertThat(locatorHandler.hookDefinitions).isNull(); assertThat(locatorHandler.hooks).isNull(); }