Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error prone warnings #4290

Merged
merged 1 commit into from
Aug 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -1172,7 +1172,7 @@ void parsePreambleAndEntryWithoutNewLine() throws IOException {
@Test
void parseFileHeaderAndPreambleWithoutNewLine() throws IOException {
ParserResult result = parser
.parse(new StringReader("% Encoding: US-ASCII@preamble{some text and \\latex}"));
.parse(new StringReader("\\% Encoding: US-ASCII@preamble{some text and \\latex}"));

assertFalse(result.hasWarnings());
assertEquals(Optional.of("some text and \\latex"), result.getDatabase().getPreamble());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,21 @@
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.ResourceBundle;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

class LocalizationConsistencyTest {
Expand Down Expand Up @@ -140,6 +145,31 @@ void localizationParameterMustIncludeAString() throws IOException {
}
}

private static Language[] installedLanguages() {
return Language.values();
}

@ParameterizedTest
@MethodSource("installedLanguages")
void resourceBundleExists(Language language) {
Path messagesPropertyFile = Paths.get("src/main/resources").resolve(Localization.RESOURCE_PREFIX + "_" + language.getId() + ".properties");
assertTrue(Files.exists(messagesPropertyFile));
}

@ParameterizedTest
@MethodSource("installedLanguages")
void languageCanBeLoaded(Language language) {
Locale oldLocale = Locale.getDefault();
try {
Locale locale = Language.convertToSupportedLocale(language).get();
Locale.setDefault(locale);
ResourceBundle messages = ResourceBundle.getBundle(Localization.RESOURCE_PREFIX, locale, new EncodingControl(StandardCharsets.UTF_8));
assertNotNull(messages);
} finally {
Locale.setDefault(oldLocale);
}
}

private static class DuplicationDetectionProperties extends Properties {

private static final long serialVersionUID = 1L;
Expand Down
13 changes: 7 additions & 6 deletions src/test/java/org/jabref/logic/l10n/LocalizationParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ private static List<LocalizationEntry> getLanguageKeysInJavaFile(Path path, Loca
for (String key : keys) {
result.add(new LocalizationEntry(path, key, type));
}
} catch (IOException ignore) {
ignore.printStackTrace();
} catch (IOException exception) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why throwing a Runtime Exception?`

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we don't really care about the exception (it should never occur) but the tests should fail nonetheless if an exception occurs. Moreover, these methods here used while working with (file) streams, which does not has a nice mechanism to handle exceptions.

throw new RuntimeException(exception);
}

return result;
Expand All @@ -174,8 +174,8 @@ private static List<LocalizationEntry> getLocalizationParametersInJavaFile(Path
for (String key : keys) {
result.add(new LocalizationEntry(path, key, type));
}
} catch (IOException ignore) {
ignore.printStackTrace();
} catch (IOException exception) {
throw new RuntimeException(exception);
}

return result;
Expand Down Expand Up @@ -209,15 +209,16 @@ public boolean containsKey(String key) {

PlatformImpl.startup(() -> {
});

try {
FXMLLoader loader = new FXMLLoader(path.toUri().toURL(), registerUsageResourceBundle);
// We don't want to initialize controller
loader.setControllerFactory(controllerType -> null);
// Don't check if root is null (needed for custom controls, where the root value is normally set in the FXMLLoader)
loader.impl_setStaticLoad(true);
loader.load();
} catch (IOException ignore) {
ignore.printStackTrace();
} catch (IOException exception) {
throw new RuntimeException(exception);
}

return result.stream()
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion src/test/java/org/jabref/model/strings/StringUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ void testShaveString() {

@Test
void testJoin() {
String[] s = "ab/cd/ed".split("/");
String[] s = {"ab", "cd", "ed"};
assertEquals("ab\\cd\\ed", StringUtil.join(s, "\\", 0, s.length));

assertEquals("cd\\ed", StringUtil.join(s, "\\", 1, s.length));
Expand Down