From 720a6c7e876101769850c90059709cb9ae6fb7b2 Mon Sep 17 00:00:00 2001 From: SrdjanStevanetic Date: Wed, 29 Nov 2023 17:16:51 +0100 Subject: [PATCH] improved code smells --- .../ApacheTikaLangDetectService.java | 21 ++----------------- .../tests/web/LangDetectionRestIT.java | 3 ++- 2 files changed, 4 insertions(+), 20 deletions(-) diff --git a/translation-service-apache-tika/src/main/java/eu/europeana/translation/service/apachetika/ApacheTikaLangDetectService.java b/translation-service-apache-tika/src/main/java/eu/europeana/translation/service/apachetika/ApacheTikaLangDetectService.java index 9742f378..3b6fb1ce 100644 --- a/translation-service-apache-tika/src/main/java/eu/europeana/translation/service/apachetika/ApacheTikaLangDetectService.java +++ b/translation-service-apache-tika/src/main/java/eu/europeana/translation/service/apachetika/ApacheTikaLangDetectService.java @@ -39,24 +39,8 @@ public List detectLang(List texts, String langHint) throws Langu if (texts.isEmpty()) { return Collections.emptyList(); } - - /* - * this code can be used for testing the lang hint, but the setPriors map cannot be sent empty or null, - * and once it is set, it stays for the next call as well, so to empty it, the detector would probably - * need to be recreated - */ -// try { -// Map languageProbabilities = new HashMap(); -// if(! StringUtils.isBlank(langHint)) { -// languageProbabilities.put(langHint, (float) 1.0); -// } -// this.detector.setPriors(languageProbabilities); -// } catch (IOException e) { -// throw new LanguageDetectionException( -// "Invalid setting of the language hint for the Apache-Tika service!", -1, e); -// } - List detectedLangs = new ArrayList(); + List detectedLangs = new ArrayList<>(); List tikaLanguages=null; for(String text : texts) { //returns all tika languages sorted by score @@ -92,8 +76,7 @@ private String chooseDetectedLang(List tikaLanguages, String lan detectedLang=langHint; break; } - } - else { + } else { break; } } diff --git a/translation-tests/src/integration-test/java/eu/europeana/api/translation/tests/web/LangDetectionRestIT.java b/translation-tests/src/integration-test/java/eu/europeana/api/translation/tests/web/LangDetectionRestIT.java index 0cfbcd15..850fb7d2 100644 --- a/translation-tests/src/integration-test/java/eu/europeana/api/translation/tests/web/LangDetectionRestIT.java +++ b/translation-tests/src/integration-test/java/eu/europeana/api/translation/tests/web/LangDetectionRestIT.java @@ -1,5 +1,6 @@ package eu.europeana.api.translation.tests.web; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; @@ -87,7 +88,7 @@ void langDetectionApacheTika() throws Exception { JSONArray langs = json.getJSONArray(TranslationAppConstants.LANGS); assertTrue(langs.length()==3 && "hr".equals(langs.getString(0)) && "de".equals(langs.getString(1)) && "en".equals(langs.getString(2))); String serviceFieldValue = json.getString(TranslationAppConstants.SERVICE); - assertTrue("APACHE-TIKA".equals(serviceFieldValue)); + assertEquals("APACHE-TIKA", serviceFieldValue); } @Test