aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2020-10-02 17:53:34 +0300
committerGravatar Vitaly Takmazov2020-10-02 17:53:34 +0300
commita62c1fda358f54bd3e7de9aea94ce63e89e06142 (patch)
treed6f4734e5150f849ae782ea35812bed139f5d029 /src
parent4eab4c56d571cbd318391c26ccb5b02aa68029e1 (diff)
Apply fixes from some IDEA code inspections
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/juick/CommandsManager.java16
-rw-r--r--src/main/java/com/juick/service/SubscriptionServiceImpl.java8
-rw-r--r--src/main/java/com/juick/www/api/ApiSocialLogin.java9
-rw-r--r--src/main/java/com/juick/www/api/Service.java2
-rw-r--r--src/main/java/com/juick/www/controllers/SocialLogin.java9
-rw-r--r--src/test/java/com/juick/FormatterTest.java4
-rw-r--r--src/test/java/com/juick/config/TestActivityConfiguration.java2
-rw-r--r--src/test/java/com/juick/server/tests/ServerTests.java8
8 files changed, 26 insertions, 32 deletions
diff --git a/src/main/java/com/juick/CommandsManager.java b/src/main/java/com/juick/CommandsManager.java
index f7c37b8b..66a45f9d 100644
--- a/src/main/java/com/juick/CommandsManager.java
+++ b/src/main/java/com/juick/CommandsManager.java
@@ -106,7 +106,7 @@ public class CommandsManager {
}
}
CommandResult commandResult = (CommandResult) getClass().getMethod(cmd.get().getName(), User.class, URI.class, String[].class)
- .invoke(this, user, attachment, groups.toArray(new String[groups.size()]));
+ .invoke(this, user, attachment, groups.toArray(new String[0]));
if (StringUtils.isNotEmpty(commandResult.getText())) {
return commandResult;
}
@@ -196,26 +196,26 @@ public class CommandsManager {
List<User> blusers = userService.getUserBLUsers(user_from.getUid());
List<String> bltags = tagService.getUserBLTags(user_from.getUid());
- String txt = StringUtils.EMPTY;
+ StringBuilder txt = new StringBuilder(StringUtils.EMPTY);
if (bltags.size() > 0) {
for (String bltag : bltags) {
- txt += "*" + bltag + "\n";
+ txt.append("*").append(bltag).append("\n");
}
if (blusers.size() > 0) {
- txt += "\n";
+ txt.append("\n");
}
}
if (blusers.size() > 0) {
for (User bluser : blusers) {
- txt += "@" + bluser.getName() + "\n";
+ txt.append("@").append(bluser.getName()).append("\n");
}
}
- if (txt.isEmpty()) {
- txt = "You don't have any users or tags in your blacklist.";
+ if (txt.length() == 0) {
+ txt = new StringBuilder("You don't have any users or tags in your blacklist.");
}
- return CommandResult.fromString(txt);
+ return CommandResult.fromString(txt.toString());
}
@UserCommand(pattern = "^#\\+$", help = "#+ - Show last Juick messages")
diff --git a/src/main/java/com/juick/service/SubscriptionServiceImpl.java b/src/main/java/com/juick/service/SubscriptionServiceImpl.java
index 977fbec0..83cf682f 100644
--- a/src/main/java/com/juick/service/SubscriptionServiceImpl.java
+++ b/src/main/java/com/juick/service/SubscriptionServiceImpl.java
@@ -63,11 +63,9 @@ public class SubscriptionServiceImpl extends BaseJdbcService implements Subscrip
List<Integer> tags = tagService.getMessageTagsIDs(mid);
List<String> tagsStr = tagService.getMessageTags(mid).stream().map(t -> t.getTag().getName()).collect(Collectors.toList());
- Set<Integer> set = new HashSet<>();
- set.addAll(
- users.stream()
- .map(User::getUid).filter(u -> Collections.disjoint(tagService.getUserBLTags(u), tagsStr))
- .collect(Collectors.toList()));
+ Set<Integer> set = new HashSet<>(users.stream()
+ .map(User::getUid).filter(u -> Collections.disjoint(tagService.getUserBLTags(u), tagsStr))
+ .collect(Collectors.toList()));
if (!tags.isEmpty()) {
diff --git a/src/main/java/com/juick/www/api/ApiSocialLogin.java b/src/main/java/com/juick/www/api/ApiSocialLogin.java
index 101f6b1f..8b331781 100644
--- a/src/main/java/com/juick/www/api/ApiSocialLogin.java
+++ b/src/main/java/com/juick/www/api/ApiSocialLogin.java
@@ -34,13 +34,11 @@ import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.juick.model.AuthResponse;
import com.juick.model.ext.facebook.User;
-import com.juick.util.HttpBadRequestException;
+import com.juick.model.ext.vk.UsersResponse;
import com.juick.service.CrosspostService;
import com.juick.service.EmailService;
import com.juick.service.UserService;
-import com.juick.model.ext.vk.UsersResponse;
-import com.nimbusds.jose.JOSEException;
-import com.nimbusds.jose.proc.BadJOSEException;
+import com.juick.util.HttpBadRequestException;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
@@ -60,7 +58,6 @@ import javax.annotation.PostConstruct;
import javax.inject.Inject;
import java.io.IOException;
import java.security.GeneralSecurityException;
-import java.text.ParseException;
import java.util.Collections;
import java.util.Map;
import java.util.UUID;
@@ -291,7 +288,7 @@ public class ApiSocialLogin {
throw new HttpBadRequestException();
}
@PostMapping("/api/_applelogin")
- public String doVerifyAppleResponse(@RequestParam Map<String, String> body) throws InterruptedException, ExecutionException, IOException, ParseException, JOSEException, BadJOSEException {
+ public String doVerifyAppleResponse(@RequestParam Map<String, String> body) throws InterruptedException, ExecutionException, IOException {
OAuth2AccessToken token = appleSignInService.getAccessToken(body.get("code"));
var jsonNode = jsonMapper.readTree(token.getRawResponse());
var idToken = jsonNode.get("id_token").textValue();
diff --git a/src/main/java/com/juick/www/api/Service.java b/src/main/java/com/juick/www/api/Service.java
index 850acb9d..dc001428 100644
--- a/src/main/java/com/juick/www/api/Service.java
+++ b/src/main/java/com/juick/www/api/Service.java
@@ -203,7 +203,7 @@ public class Service {
.forEach(session -> serverManager.getSessions().remove(session));
}
@GetMapping("/api/events")
- public SseEmitter handle(@Visitor User visitor) throws IOException {
+ public SseEmitter handle(@Visitor User visitor) {
logger.info("{} connected", visitor.getName());
if (!visitor.isAnonymous()) {
userService.updateLastSeen(visitor);
diff --git a/src/main/java/com/juick/www/controllers/SocialLogin.java b/src/main/java/com/juick/www/controllers/SocialLogin.java
index ffd785b7..1f99efc1 100644
--- a/src/main/java/com/juick/www/controllers/SocialLogin.java
+++ b/src/main/java/com/juick/www/controllers/SocialLogin.java
@@ -24,15 +24,13 @@ import com.github.scribejava.core.oauth.OAuth10aService;
import com.github.scribejava.core.oauth.OAuth20Service;
import com.juick.model.ext.facebook.User;
import com.juick.model.ext.vk.UsersResponse;
-import com.juick.util.HttpBadRequestException;
import com.juick.service.CrosspostService;
import com.juick.service.EmailService;
import com.juick.service.TelegramService;
import com.juick.service.UserService;
import com.juick.service.security.annotation.Visitor;
+import com.juick.util.HttpBadRequestException;
import com.juick.util.WebUtils;
-import com.nimbusds.jose.JOSEException;
-import com.nimbusds.jose.proc.BadJOSEException;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.codec.digest.HmacAlgorithms;
import org.apache.commons.codec.digest.HmacUtils;
@@ -55,7 +53,6 @@ import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
-import java.text.ParseException;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@@ -341,7 +338,9 @@ public class SocialLogin {
throw new HttpBadRequestException();
}
@PostMapping("/_apple")
- public String doVerifyAppleResponse(HttpServletRequest request, HttpServletResponse response, @RequestParam Map<String, String> body) throws InterruptedException, ExecutionException, IOException, ParseException, JOSEException, BadJOSEException {
+ public String doVerifyAppleResponse(HttpServletRequest request, HttpServletResponse response,
+ @RequestParam Map<String, String> body)
+ throws InterruptedException, ExecutionException, IOException {
OAuth2AccessToken token = appleSignInService.getAccessToken(body.get("code"));
var jsonNode = jsonMapper.readTree(token.getRawResponse());
var idToken = jsonNode.get("id_token").textValue();
diff --git a/src/test/java/com/juick/FormatterTest.java b/src/test/java/com/juick/FormatterTest.java
index 1f805bb0..519d70a8 100644
--- a/src/test/java/com/juick/FormatterTest.java
+++ b/src/test/java/com/juick/FormatterTest.java
@@ -36,7 +36,7 @@ import static org.hamcrest.Matchers.*;
public class FormatterTest {
@Test
- public void forAnyDateFormatterShouldReturnNotEmptyString() throws Exception {
+ public void forAnyDateFormatterShouldReturnNotEmptyString() {
Instant ts = Instant.now();
assertThat(DateFormattersHolder.getMessageFormatterInstance().format(ts), not(emptyOrNullString()));
@@ -49,7 +49,7 @@ public class FormatterTest {
}
@Test
- public void forConcreteDateShouldReturnCorrectString() throws Exception {
+ public void forConcreteDateShouldReturnCorrectString() {
Calendar calendar = GregorianCalendar.getInstance();
calendar.set(2012, 0, 1, 0, 0, 0);
diff --git a/src/test/java/com/juick/config/TestActivityConfiguration.java b/src/test/java/com/juick/config/TestActivityConfiguration.java
index 94b96bdf..854bad06 100644
--- a/src/test/java/com/juick/config/TestActivityConfiguration.java
+++ b/src/test/java/com/juick/config/TestActivityConfiguration.java
@@ -30,7 +30,7 @@ public class TestActivityConfiguration {
@Value("classpath:test.p12")
Resource keystoreFile;
@Bean
- public KeystoreManager testKeystoreManager() throws IOException {
+ public KeystoreManager testKeystoreManager() {
return new KeystoreManager(keystoreFile, "secret");
}
}
diff --git a/src/test/java/com/juick/server/tests/ServerTests.java b/src/test/java/com/juick/server/tests/ServerTests.java
index 0bc23bf7..00259f8f 100644
--- a/src/test/java/com/juick/server/tests/ServerTests.java
+++ b/src/test/java/com/juick/server/tests/ServerTests.java
@@ -631,7 +631,7 @@ public class ServerTests {
.andExpect(status().isOk())
.andReturn();
List<TagStats> tagsFromApi = jsonMapper.readValue(result.getResponse().getContentAsString(),
- new TypeReference<List<TagStats>>() {
+ new TypeReference<>() {
});
TagStats yoStats = tagsFromApi.stream().filter(t -> t.getTag().getName().equals("yo")).findFirst().get();
assertThat(yoStats.getUsageCount(), is(2));
@@ -640,7 +640,7 @@ public class ServerTests {
.andExpect(status().isOk())
.andReturn();
List<TagStats> ugnichTagsFromApi = jsonMapper.readValue(result2.getResponse().getContentAsString(),
- new TypeReference<List<TagStats>>() {
+ new TypeReference<>() {
});
TagStats yoUgnichStats = ugnichTagsFromApi.stream().filter(t -> t.getTag().getName().equals("yo")).findFirst().get();
assertThat(yoUgnichStats.getUsageCount(), is(1));
@@ -690,7 +690,7 @@ public class ServerTests {
.andExpect(status().isOk())
.andReturn();
List<User> users = jsonMapper.readValue(result.getResponse().getContentAsString(),
- new TypeReference<List<User>>() {
+ new TypeReference<>() {
});
assertThat(users.size(), is(1));
assertThat(users.get(0).getTokens().size(), is(1));
@@ -1471,7 +1471,7 @@ public class ServerTests {
}
@Test
- public void bannedUserShouldBeShadowedFromRecommendationsList() throws IOException {
+ public void bannedUserShouldBeShadowedFromRecommendationsList() {
jdbcTemplate.execute("DELETE FROM bl_users");
User ermine = userService.createUser("ermine", "secret").orElseThrow(IllegalStateException::new);
User monstreek = userService.createUser("monstreek", "secret").orElseThrow(IllegalStateException::new);