Fix some statically detected code issues

This includes: unnecessary semicolons, suppress warnings, switch statements, final/private qualifiers, Optional wrapping, conditionals, both inline and non-inline variables, ternaries, Collection putAll() calls, StringBuilders, and throws declarations.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=244182539
This commit is contained in:
mcilwain 2019-04-18 07:34:10 -07:00 committed by jianglai
parent 9f360587ff
commit 24bb78bd16
54 changed files with 107 additions and 158 deletions

View file

@ -425,7 +425,6 @@ public class CloudDnsWriterTest {
}
@Test
@SuppressWarnings("unchecked")
public void retryMutateZoneOnError() {
CloudDnsWriter spyWriter = spy(writer);
// First call - throw. Second call - do nothing.

View file

@ -16,6 +16,7 @@ package google.registry.documentation;
import static com.google.common.truth.Truth.assert_;
import static google.registry.util.BuildPathUtils.getProjectRoot;
import static java.nio.charset.StandardCharsets.UTF_8;
import com.google.common.base.Joiner;
import java.io.IOException;
@ -47,7 +48,7 @@ public class FlowDocumentationTest {
Path goldenMarkdownPath =
GOLDEN_MARKDOWN_FILEPATH;
String goldenMarkdown = new String(Files.readAllBytes(goldenMarkdownPath), "UTF-8");
String goldenMarkdown = new String(Files.readAllBytes(goldenMarkdownPath), UTF_8);
// Don't use Truth's isEqualTo() because the output is huge and unreadable for large files.
DocumentationGenerator generator = new DocumentationGenerator();

View file

@ -86,7 +86,7 @@ public class ExportDomainListsActionTest extends MapreduceTestCase<ExportDomainL
eq(EXPORT_MIME_TYPE),
eq(folderId),
bytesExportedToDrive.capture());
assertThat(new String(bytesExportedToDrive.getValue(), "UTF-8")).isEqualTo(domains);
assertThat(new String(bytesExportedToDrive.getValue(), UTF_8)).isEqualTo(domains);
}
@Test

View file

@ -60,7 +60,6 @@ import google.registry.xml.ValidationMode;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import javax.annotation.Nullable;
import org.joda.time.DateTime;
import org.junit.Before;
@ -183,14 +182,11 @@ public abstract class FlowTestCase<F extends Flow> extends ShardableTestCase {
ImmutableMap.Builder<GracePeriod, BillingEvent> builder = new ImmutableMap.Builder<>();
for (Map.Entry<GracePeriod, ? extends BillingEvent> entry : gracePeriods.entrySet()) {
builder.put(
((Function<GracePeriod, GracePeriod>)
gracePeriod ->
GracePeriod.create(
gracePeriod.getType(),
gracePeriod.getExpirationTime(),
gracePeriod.getClientId(),
null))
.apply(entry.getKey()),
GracePeriod.create(
entry.getKey().getType(),
entry.getKey().getExpirationTime(),
entry.getKey().getClientId(),
null),
stripBillingEventId(entry.getValue()));
}
return builder.build();

View file

@ -383,7 +383,6 @@ public class BouncyCastleTest {
* Googler who was also uncertain about the precise reason why it's needed.
*/
private void addUserInfoToSignature(PGPPublicKey publicKey, PGPSignatureGenerator signer) {
@SuppressWarnings("unchecked") // Safe by specification.
Iterator<String> uidIter = publicKey.getUserIDs();
if (uidIter.hasNext()) {
PGPSignatureSubpacketGenerator spg = new PGPSignatureSubpacketGenerator();

View file

@ -76,7 +76,6 @@ import google.registry.testing.sftp.SftpServerRule;
import google.registry.util.Retrier;
import google.registry.util.TaskQueueUtils;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@ -353,7 +352,7 @@ public class RdeUploadActionTest {
+ "upload; last upload attempt was at 2010-10-16T22:23:00.000Z (97 minutes ago)");
}
private String slurp(InputStream is) throws FileNotFoundException, IOException {
private String slurp(InputStream is) throws IOException {
return CharStreams.toString(new InputStreamReader(is, UTF_8));
}
}

View file

@ -30,7 +30,6 @@ import google.registry.testing.GpgSystemCommandRule;
import google.registry.testing.ShardableTestCase;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
@ -208,7 +207,7 @@ public class RydeGpgIntegrationTest extends ShardableTestCase {
assertThat(slurp(xmlFile)).isEqualTo(content.get());
}
private String slurp(File file) throws FileNotFoundException, IOException {
private String slurp(File file) throws IOException {
return CharStreams.toString(new InputStreamReader(new FileInputStream(file), UTF_8));
}

View file

@ -45,9 +45,6 @@ import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class PublishInvoicesActionTest {
private Dataflow dataflow;
private Projects projects;
private Jobs jobs;
private Get get;
private BillingEmailUtils emailUtils;
@ -60,9 +57,9 @@ public class PublishInvoicesActionTest {
@Before
public void setUp() throws IOException {
dataflow = mock(Dataflow.class);
projects = mock(Projects.class);
jobs = mock(Jobs.class);
Dataflow dataflow = mock(Dataflow.class);
Projects projects = mock(Projects.class);
Jobs jobs = mock(Jobs.class);
get = mock(Get.class);
when(dataflow.projects()).thenReturn(projects);
when(projects.jobs()).thenReturn(jobs);

View file

@ -82,8 +82,7 @@ public class TestCacheRule extends ExternalResource {
}
public TestCacheRule build() {
TestCacheRule rule = new TestCacheRule(ImmutableList.copyOf(cacheHandlerMap.values()));
return rule;
return new TestCacheRule(ImmutableList.copyOf(cacheHandlerMap.values()));
}
}

View file

@ -168,7 +168,6 @@ public class NordnUploadActionTest {
assertThat(action.loadAllTasks(queue, "tld")).containsExactly(task);
}
@SuppressWarnings("unchecked")
@Test
public void test_loadAllTasks_retryLogic_allFailures() {
Queue queue = mock(Queue.class);

View file

@ -235,7 +235,6 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
verifyZeroInteractions(connection);
}
@SuppressWarnings("unchecked")
@Test
public void testFailure_groupCreationFails() throws Exception {
when(connection.sendPostRequest(

View file

@ -24,7 +24,6 @@ import google.registry.testing.AppEngineRule;
import google.registry.tools.LevelDbFileBuilder.Property;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.junit.Rule;
import org.junit.Test;
@ -41,7 +40,7 @@ public class LevelDbFileBuilderTest {
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
@Test
public void testSingleRecordWrites() throws FileNotFoundException, IOException {
public void testSingleRecordWrites() throws IOException {
File subdir = tempFs.newFolder("folder");
File logFile = new File(subdir, "testfile");
LevelDbFileBuilder builder = new LevelDbFileBuilder(logFile);
@ -64,7 +63,7 @@ public class LevelDbFileBuilderTest {
}
@Test
public void testMultipleRecordWrites() throws FileNotFoundException, IOException {
public void testMultipleRecordWrites() throws IOException {
File subdir = tempFs.newFolder("folder");
File logFile = new File(subdir, "testfile");
LevelDbFileBuilder builder = new LevelDbFileBuilder(logFile);

View file

@ -77,8 +77,7 @@ public class ConsoleUiActionTest {
action.userService = UserServiceFactory.getUserService();
action.xsrfTokenManager = new XsrfTokenManager(new FakeClock(), action.userService);
action.paramClientId = Optional.empty();
AuthResult authResult = AuthResult.create(AuthLevel.USER, UserAuthInfo.create(user, false));
action.authResult = authResult;
action.authResult = AuthResult.create(AuthLevel.USER, UserAuthInfo.create(user, false));
action.environment = RegistryEnvironment.UNITTEST;
action.registrarAccessor =

View file

@ -15,6 +15,7 @@
package google.registry.util;
import static google.registry.testing.JUnitBackports.assertThrows;
import static org.junit.Assert.assertNotEquals;
import com.google.common.collect.ImmutableMap;
import com.google.common.net.InetAddresses;
@ -264,8 +265,8 @@ public class CidrAddressBlockTest extends TestCase {
assertEquals(b0, b1);
assertEquals(b0, new CidrAddressBlock(b0.toString()));
assertEquals(b0.hashCode(), b1.hashCode());
assertFalse(b0.equals(b2));
assertFalse(b0.equals(b3));
assertNotEquals(b0, b2);
assertNotEquals(b0, b3);
}
public void testIterate() {