@Test public void shouldReturnTrueWhenCheckIfCustomTranslationIsUniqueIfEntityIsntSaved() { given(customTranslation.getId()).willReturn(null); given(customTranslation.getStringField(PLUGIN_IDENTIFIER)).willReturn(null); given(customTranslation.getStringField(KEY)).willReturn(null); given(customTranslation.getStringField(LOCALE)).willReturn(null); given(customTranslationDD.find()).willReturn(searchCriteriaBuilder); given(searchCriteriaBuilder.add(Mockito.any(SearchCriterion.class))).willReturn(searchCriteriaBuilder); given(searchCriteriaBuilder.list()).willReturn(searchResult); given(searchResult.getEntities()).willReturn(customTranslations); given(customTranslations.isEmpty()).willReturn(true); boolean result = customTranslationModelHooks.checkIfCustomTranslationIsUnique(customTranslationDD, customTranslation); Assert.assertTrue(result); verify(customTranslation, never()).addError(Mockito.any(FieldDefinition.class), Mockito.anyString()); }
public boolean checkIfCustomTranslationIsUnique(final DataDefinition customTranslationDD, final Entity customTranslation) { String pluginIdentifier = customTranslation.getStringField(PLUGIN_IDENTIFIER); String locale = customTranslation.getStringField(LOCALE); String key = customTranslation.getStringField(KEY); SearchCriteriaBuilder searchCriteriaBuilder = customTranslationDD.find() .add(SearchRestrictions.eq(PLUGIN_IDENTIFIER, pluginIdentifier)).add(SearchRestrictions.eq(LOCALE, locale)) .add(SearchRestrictions.eq(KEY, key)); if (customTranslation.getId() != null) { searchCriteriaBuilder.add(SearchRestrictions.ne("id", customTranslation.getId())); } SearchResult searchResult = searchCriteriaBuilder.list(); if (!searchResult.getEntities().isEmpty()) { customTranslation.addError(customTranslationDD.getField(KEY), "customTranslation.customTranslation.error.customTranslationIsntUnique"); return false; } return true; }
CustomTranslationModelHooks { public boolean checkIfCustomTranslationIsUnique(final DataDefinition customTranslationDD, final Entity customTranslation) { String pluginIdentifier = customTranslation.getStringField(PLUGIN_IDENTIFIER); String locale = customTranslation.getStringField(LOCALE); String key = customTranslation.getStringField(KEY); SearchCriteriaBuilder searchCriteriaBuilder = customTranslationDD.find() .add(SearchRestrictions.eq(PLUGIN_IDENTIFIER, pluginIdentifier)).add(SearchRestrictions.eq(LOCALE, locale)) .add(SearchRestrictions.eq(KEY, key)); if (customTranslation.getId() != null) { searchCriteriaBuilder.add(SearchRestrictions.ne("id", customTranslation.getId())); } SearchResult searchResult = searchCriteriaBuilder.list(); if (!searchResult.getEntities().isEmpty()) { customTranslation.addError(customTranslationDD.getField(KEY), "customTranslation.customTranslation.error.customTranslationIsntUnique"); return false; } return true; } }
CustomTranslationModelHooks { public boolean checkIfCustomTranslationIsUnique(final DataDefinition customTranslationDD, final Entity customTranslation) { String pluginIdentifier = customTranslation.getStringField(PLUGIN_IDENTIFIER); String locale = customTranslation.getStringField(LOCALE); String key = customTranslation.getStringField(KEY); SearchCriteriaBuilder searchCriteriaBuilder = customTranslationDD.find() .add(SearchRestrictions.eq(PLUGIN_IDENTIFIER, pluginIdentifier)).add(SearchRestrictions.eq(LOCALE, locale)) .add(SearchRestrictions.eq(KEY, key)); if (customTranslation.getId() != null) { searchCriteriaBuilder.add(SearchRestrictions.ne("id", customTranslation.getId())); } SearchResult searchResult = searchCriteriaBuilder.list(); if (!searchResult.getEntities().isEmpty()) { customTranslation.addError(customTranslationDD.getField(KEY), "customTranslation.customTranslation.error.customTranslationIsntUnique"); return false; } return true; }  }
CustomTranslationModelHooks { public boolean checkIfCustomTranslationIsUnique(final DataDefinition customTranslationDD, final Entity customTranslation) { String pluginIdentifier = customTranslation.getStringField(PLUGIN_IDENTIFIER); String locale = customTranslation.getStringField(LOCALE); String key = customTranslation.getStringField(KEY); SearchCriteriaBuilder searchCriteriaBuilder = customTranslationDD.find() .add(SearchRestrictions.eq(PLUGIN_IDENTIFIER, pluginIdentifier)).add(SearchRestrictions.eq(LOCALE, locale)) .add(SearchRestrictions.eq(KEY, key)); if (customTranslation.getId() != null) { searchCriteriaBuilder.add(SearchRestrictions.ne("id", customTranslation.getId())); } SearchResult searchResult = searchCriteriaBuilder.list(); if (!searchResult.getEntities().isEmpty()) { customTranslation.addError(customTranslationDD.getField(KEY), "customTranslation.customTranslation.error.customTranslationIsntUnique"); return false; } return true; }  boolean checkIfCustomTranslationIsUnique(final DataDefinition customTranslationDD, final Entity customTranslation); void changeActiveState(final DataDefinition customTranslationDD, final Entity customTranslation); void updateCache(final DataDefinition customTranslationDD, final Entity customTranslation); }
CustomTranslationModelHooks { public boolean checkIfCustomTranslationIsUnique(final DataDefinition customTranslationDD, final Entity customTranslation) { String pluginIdentifier = customTranslation.getStringField(PLUGIN_IDENTIFIER); String locale = customTranslation.getStringField(LOCALE); String key = customTranslation.getStringField(KEY); SearchCriteriaBuilder searchCriteriaBuilder = customTranslationDD.find() .add(SearchRestrictions.eq(PLUGIN_IDENTIFIER, pluginIdentifier)).add(SearchRestrictions.eq(LOCALE, locale)) .add(SearchRestrictions.eq(KEY, key)); if (customTranslation.getId() != null) { searchCriteriaBuilder.add(SearchRestrictions.ne("id", customTranslation.getId())); } SearchResult searchResult = searchCriteriaBuilder.list(); if (!searchResult.getEntities().isEmpty()) { customTranslation.addError(customTranslationDD.getField(KEY), "customTranslation.customTranslation.error.customTranslationIsntUnique"); return false; } return true; }  boolean checkIfCustomTranslationIsUnique(final DataDefinition customTranslationDD, final Entity customTranslation); void changeActiveState(final DataDefinition customTranslationDD, final Entity customTranslation); void updateCache(final DataDefinition customTranslationDD, final Entity customTranslation);  }