| 1 | package com.jsql.util; | |
| 2 | ||
| 3 | import com.jsql.model.exception.JSqlRuntimeException; | |
| 4 | import org.apache.commons.lang3.StringUtils; | |
| 5 | import org.apache.logging.log4j.LogManager; | |
| 6 | import org.apache.logging.log4j.Logger; | |
| 7 | ||
| 8 | import java.io.IOException; | |
| 9 | import java.io.InputStream; | |
| 10 | import java.io.StringReader; | |
| 11 | import java.math.BigDecimal; | |
| 12 | import java.math.RoundingMode; | |
| 13 | import java.net.URISyntaxException; | |
| 14 | import java.nio.charset.StandardCharsets; | |
| 15 | import java.nio.file.Files; | |
| 16 | import java.nio.file.Paths; | |
| 17 | import java.util.Arrays; | |
| 18 | import java.util.Locale; | |
| 19 | import java.util.Properties; | |
| 20 | import java.util.concurrent.atomic.AtomicInteger; | |
| 21 | import java.util.regex.Matcher; | |
| 22 | import java.util.regex.Pattern; | |
| 23 | ||
| 24 | public class PropertiesUtil { | |
| 25 | | |
| 26 | private static final Logger LOGGER = LogManager.getRootLogger(); | |
| 27 | ||
| 28 | private final Properties properties = new Properties(); | |
| 29 | ||
| 30 | public PropertiesUtil() { | |
| 31 | var filename = "config.properties"; | |
| 32 | try (InputStream input = PropertiesUtil.class.getClassLoader().getResourceAsStream(filename)) { | |
| 33 |
1
1. <init> : negated conditional → SURVIVED |
if (input == null) { |
| 34 | LOGGER.log(LogLevelUtil.CONSOLE_ERROR, "Properties file {} not found", filename); | |
| 35 | return; | |
| 36 | } | |
| 37 |
1
1. <init> : removed call to java/util/Properties::load → SURVIVED |
this.properties.load(input); // load a properties file from class path, inside static method |
| 38 | } catch (IOException e) { | |
| 39 | LOGGER.log(LogLevelUtil.CONSOLE_JAVA, e, e); | |
| 40 | } | |
| 41 | } | |
| 42 | ||
| 43 | public void displayI18nStatus(Locale newLocale) { | |
| 44 |
1
1. displayI18nStatus : negated conditional → NO_COVERAGE |
if (!Arrays.asList(StringUtils.EMPTY, "en").contains(newLocale.getLanguage())) { |
| 45 | AtomicInteger countGui = new AtomicInteger(); | |
| 46 | var bundleRoot = PropertiesUtil.getProperties("i18n/jsql.properties"); | |
| 47 | var bundleUser = PropertiesUtil.getProperties("i18n/jsql_" + newLocale.getLanguage() + ".properties"); | |
| 48 | bundleRoot.entrySet().stream().filter( | |
| 49 |
3
1. lambda$displayI18nStatus$0 : negated conditional → NO_COVERAGE 2. lambda$displayI18nStatus$0 : replaced boolean return with true for com/jsql/util/PropertiesUtil::lambda$displayI18nStatus$0 → NO_COVERAGE 3. lambda$displayI18nStatus$0 : negated conditional → NO_COVERAGE |
key -> bundleUser.isEmpty() || !bundleUser.containsKey(key.getKey()) |
| 50 |
1
1. displayI18nStatus : removed call to java/util/stream/Stream::forEach → NO_COVERAGE |
).forEach( |
| 51 | key -> countGui.getAndIncrement() | |
| 52 | ); | |
| 53 |
2
1. displayI18nStatus : changed conditional boundary → NO_COVERAGE 2. displayI18nStatus : negated conditional → NO_COVERAGE |
if (countGui.get() > 0) { |
| 54 | LOGGER.log( | |
| 55 | LogLevelUtil.CONSOLE_SUCCESS, | |
| 56 | "Switched to {} with {}% translated, contribute and translate any of {} items in menu Community", | |
| 57 |
1
1. lambda$displayI18nStatus$2 : replaced return value with null for com/jsql/util/PropertiesUtil::lambda$displayI18nStatus$2 → NO_COVERAGE |
() -> newLocale.getDisplayLanguage(newLocale), |
| 58 |
1
1. lambda$displayI18nStatus$3 : replaced return value with null for com/jsql/util/PropertiesUtil::lambda$displayI18nStatus$3 → NO_COVERAGE |
() -> BigDecimal.valueOf( |
| 59 |
3
1. lambda$displayI18nStatus$3 : Replaced double multiplication with division → NO_COVERAGE 2. lambda$displayI18nStatus$3 : Replaced double subtraction with addition → NO_COVERAGE 3. lambda$displayI18nStatus$3 : Replaced double division with multiplication → NO_COVERAGE |
100.0 - countGui.get() * 100.0 / bundleRoot.size() |
| 60 | ).setScale(1, RoundingMode.HALF_UP).doubleValue(), | |
| 61 | countGui::get | |
| 62 | ); | |
| 63 | } | |
| 64 | } | |
| 65 | } | |
| 66 | ||
| 67 | private static Properties getProperties(String name) { | |
| 68 | var properties = new Properties(); | |
| 69 | try { | |
| 70 | var uri = ClassLoader.getSystemResource(name).toURI(); | |
| 71 | var path = Paths.get(uri); | |
| 72 | byte[] root = Files.readAllBytes(path); | |
| 73 | var rootI18n = new String(root, StandardCharsets.UTF_8); | |
| 74 | String rootI18nFixed = Pattern.compile("\\\\[\n\r]+") | |
| 75 | .matcher(Matcher.quoteReplacement(rootI18n)) | |
| 76 | .replaceAll("a"); | |
| 77 |
1
1. getProperties : removed call to java/util/Properties::load → NO_COVERAGE |
properties.load(new StringReader(rootI18nFixed)); |
| 78 | } catch (IOException | URISyntaxException e) { | |
| 79 | throw new JSqlRuntimeException(e); | |
| 80 | } | |
| 81 |
1
1. getProperties : replaced return value with null for com/jsql/util/PropertiesUtil::getProperties → NO_COVERAGE |
return properties; |
| 82 | } | |
| 83 | ||
| 84 | public String getVersionJsql() { | |
| 85 |
1
1. getVersionJsql : replaced return value with "" for com/jsql/util/PropertiesUtil::getVersionJsql → NO_COVERAGE |
return this.properties.getProperty("jsql.version"); |
| 86 | } | |
| 87 | ||
| 88 | public String getProperty(String property) { | |
| 89 |
1
1. getProperty : replaced return value with "" for com/jsql/util/PropertiesUtil::getProperty → NO_COVERAGE |
return this.properties.getProperty(property); |
| 90 | } | |
| 91 | } | |
Mutations | ||
| 33 |
1.1 |
|
| 37 |
1.1 |
|
| 44 |
1.1 |
|
| 49 |
1.1 2.2 3.3 |
|
| 50 |
1.1 |
|
| 53 |
1.1 2.2 |
|
| 57 |
1.1 |
|
| 58 |
1.1 |
|
| 59 |
1.1 2.2 3.3 |
|
| 77 |
1.1 |
|
| 81 |
1.1 |
|
| 85 |
1.1 |
|
| 89 |
1.1 |