Skip to content

Commit

Permalink
Some small improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
floscher committed Sep 30, 2019
1 parent fb41781 commit dfb6bd7
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,13 @@ public static WikidataActionApiQuery<WbgetentitiesResult> wbgetentities(final St
if (siteId == null || titles == null || titles.size() <= 0) {
throw new IllegalArgumentException("The site ID and titles must be present!");
}
if (!RegexUtil.isValidSiteId(siteId)) {
final String lowercaseSiteId = siteId.toLowerCase();
if (!RegexUtil.isValidSiteId(lowercaseSiteId)) {
throw new IllegalArgumentException("The site ID is not given in the expected format!");
}
return new WikidataActionApiQuery<>(
FORMAT_PARAMS + "&action=wbgetentities&props=sitelinks&sites=" + siteId + // defines the language of the titles
"&sitefilter=" + siteId + // defines for which languages sitelinks should be returned
FORMAT_PARAMS + "&action=wbgetentities&props=sitelinks&sites=" + lowercaseSiteId + // defines the language of the titles
"&sitefilter=" + lowercaseSiteId + // defines for which languages sitelinks should be returned
"&titles=" + Utils.encodeUrl(String.join("|", titles)),
WbgetentitiesResult.SCHEMA
);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/wikipedia/data/WikipediaEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public int compareTo(WikipediaEntry o) {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!(o instanceof WikipediaEntry)) return false;
final WikipediaEntry that = (WikipediaEntry) o;
return Objects.equals(lang, that.lang) &&
Objects.equals(article, that.article);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
* Toggle dialog that displays infos about the currently selected Wikidata item.
*/
public class WikidataInfoToggleDialog extends ToggleDialog {
private static final Logger L = Logger.getLogger(WikidataInfoToggleDialog.class.getName());
private static final String EMPTY_STRING = "";

private final WikipediaToggleDialog wikiDialog;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/wikipedia/tools/RegexUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class RegexUtil {
private static final Pattern PROPERTY_ID_PATTERN = Pattern.compile("^P[1-9][0-9]*$");
private static final Pattern Q_ID_PATTERN = Pattern.compile("^Q[1-9][0-9]*$");
private static final Pattern MULTI_Q_ID_PATTERN = Pattern.compile("^Q[1-9][0-9]*(;Q[1-9][0-9]*)*$");
private static final Pattern SITE_ID_PATTERN = Pattern.compile("^[a-z][a-z][a-z]?wiki$");
private static final Pattern SITE_ID_PATTERN = Pattern.compile("^[a-z0-9_]+wiki$");
public static final Pattern WIKIPEDIA_TAG_VALUE_PATTERN = Pattern.compile("([a-z][a-z][a-z]?):(.+)");

public static final Pattern INTEGER_PATTERN = Pattern.compile("^[0-9]+$");
Expand Down
4 changes: 2 additions & 2 deletions test/unit/org/wikipedia/api/wdq/WdqApiQueryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public void testIllegalArguments() {
});
}

private void stubWithFileContent(final String filename) throws IOException, URISyntaxException {
private static void stubWithFileContent(final String filename) throws IOException, URISyntaxException {
stubFor(post(URL_PATH)
.withHeader("Content-Type", equalTo("application/x-www-form-urlencoded"))
.willReturn(
Expand All @@ -141,7 +141,7 @@ private void stubWithFileContent(final String filename) throws IOException, URIS
);
}

private void verifyOneRequestTo(final String urlPattern) {
private static void verifyOneRequestTo(final String urlPattern) {
verify(1, postRequestedFor(urlEqualTo(URL_PATH)).withRequestBody(new EqualToPattern(urlPattern)));
}

Expand Down
5 changes: 5 additions & 0 deletions test/unit/org/wikipedia/testutils/JunitJupiterCompatUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
import static org.junit.Assert.assertTrue;

public class JunitJupiterCompatUtil {

private JunitJupiterCompatUtil() {
// Private constructor to avoid instantiation
}

public static <T extends Throwable> void assertThrows(Class<T> expectedType, Runnable runnable) {
boolean success = false;
Throwable throwable = null;
Expand Down

0 comments on commit dfb6bd7

Please sign in to comment.