### Question:
DataDefinitionImpl implements InternalDataDefinition { @Override public boolean callSaveHook(final Entity entity) { return entity.isValid() && callHooks(entity, getSaveHooks()); } DataDefinitionImpl(final String pluginIdentifier, final String name, final DataAccessService dataAccessService); @Override Entity get(final Long id); @Override List<Entity> copy(final Long... id); @Override EntityOpResult delete(final Long... id); @Override Entity save(final Entity entity); @Override Entity validate(final Entity entity); @Override Entity fastSave(final Entity entity); @Override SearchQueryBuilder find(final String queryString); @Override SearchCriteriaBuilder find(); @Override long count(); @Override long count(final SearchCriterion criterion); @Override SearchCriteriaBuilder findWithAlias(final String alias); @Override SearchResult find(final SearchCriteria searchCriteria); @Override void move(final Long id, final int offset); @Override void moveTo(final Long id, final int position); @Override List<Entity> activate(final Long... ids); @Override List<Entity> deactivate(final Long... ids); @Override String getName(); @Override String getPluginIdentifier(); @Override String getFullyQualifiedClassName(); void setFullyQualifiedClassName(final String fullyQualifiedClassName); @Override Map<String, FieldDefinition> getFields(); void withField(final FieldDefinition field); @Override FieldDefinition getField(final String fieldName); @Override EntityHookDefinition getHook(final String type, final String className, final String methodName); List<EntityHookDefinition> getValidators(); List<EntityHookDefinition> getViewHooks(); List<EntityHookDefinition> getCopyHooks(); List<EntityHookDefinition> getCreateHooks(); List<EntityHookDefinition> getSaveHooks(); List<EntityHookDefinition> getUpdateHooks(); List<EntityHookDefinition> getDeleteHooks(); void addValidatorHook(final EntityHookDefinition validator); void addViewHook(final EntityHookDefinition viewHook); void addCreateHook(final EntityHookDefinition createHook); void addUpdateHook(final EntityHookDefinition updateHook); void addSaveHook(final EntityHookDefinition saveHook); void addCopyHook(final EntityHookDefinition copyHook); void addDeleteHook(final EntityHookDefinition deleteHook); void addHook(final HooksTag tag, final EntityHookDefinition hook); void setIdentifierExpression(final String identifierExpression); @Override String getIdentifierExpression(); @Override boolean callViewHook(final Entity entity); @Override boolean callCreateHook(final Entity entity); @Override boolean callUpdateHook(final Entity entity); @Override boolean callSaveHook(final Entity entity); @Override boolean callCopyHook(final Entity entity); @Override boolean callValidators(final Entity entity); @Override boolean callDeleteHook(final Entity entity); @Override Class<?> getClassForEntity(); @Override Object getInstanceForEntity(); @Override boolean isPrioritizable(); void addPriorityField(final FieldDefinition priorityField); @Override FieldDefinition getPriorityField(); @Override boolean isDeletable(); void setDeletable(final boolean deletable); @Override boolean isUpdatable(); @Override boolean isAuditable(); @Override boolean isInstertable(); void setInsertable(final boolean creatable); void setUpdatable(final boolean updatable); void setAuditable(final boolean auditable); @Override boolean isVersionable(); void setVersionable(boolean versionable); @Override Entity create(); @Override Entity create(final Long id); @Override String toString(); @Override int hashCode(); @Override boolean equals(final Object obj); @Override boolean isEnabled(); @Override void enable(); @Override void disable(); @Override boolean isActivable(); void setActivable(final boolean activable); @Override MasterModel getMasterModel(); @Override void setMasterModel(MasterModel masterModel); @Override Entity getMasterModelEntity(Long id); @Override Entity tryGetMasterModelEntity(Long id);  }### Answer:
@Test public final void shouldCallSaveHook() throws Exception { given(entity.isValid()).willReturn(true); boolean result = dataDefinitionImpl.callSaveHook(entity); assertTrue(result); verify(saveHook).call(entity); }
@Test public final void shouldNotCallSaveHookIfEntityIsInvalid() throws Exception { given(entity.isValid()).willReturn(false); boolean result = dataDefinitionImpl.callSaveHook(entity); assertFalse(result); verify(saveHook, never()).call(entity); }