Lint cleanups.

This commit is contained in:
akwizgran
2018-11-26 11:40:39 +00:00
parent 98633f5e7c
commit 56ac755e96
11 changed files with 39 additions and 39 deletions

View File

@@ -25,7 +25,6 @@ public class AndroidUtils {
private static final String STORED_REPORTS = "dev-reports"; private static final String STORED_REPORTS = "dev-reports";
@SuppressWarnings("deprecation")
public static Collection<String> getSupportedArchitectures() { public static Collection<String> getSupportedArchitectures() {
List<String> abis = new ArrayList<>(); List<String> abis = new ArrayList<>();
if (SDK_INT >= 21) { if (SDK_INT >= 21) {

View File

@@ -5,14 +5,20 @@ import org.briarproject.bramble.api.FormatException;
import org.briarproject.bramble.test.BrambleTestCase; import org.briarproject.bramble.test.BrambleTestCase;
import org.junit.Test; import org.junit.Test;
import java.util.Random;
import static java.util.Arrays.asList; import static java.util.Arrays.asList;
import static java.util.Collections.emptyList; import static java.util.Collections.emptyList;
import static org.briarproject.bramble.api.data.BdfDictionary.NULL_VALUE; import static org.briarproject.bramble.api.data.BdfDictionary.NULL_VALUE;
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
import static org.briarproject.bramble.util.StringUtils.getRandomString;
import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
public class BdfListTest extends BrambleTestCase { public class BdfListTest extends BrambleTestCase {
private final Random random = new Random();
@Test @Test
public void testConstructors() { public void testConstructors() {
assertEquals(emptyList(), new BdfList()); assertEquals(emptyList(), new BdfList());
@@ -63,22 +69,21 @@ public class BdfListTest extends BrambleTestCase {
} }
@Test @Test
@SuppressWarnings("ConstantConditions") public void testIndexOutOfBoundsReturnsDefaultValue() {
public void testIndexOutOfBoundsReturnsDefaultValue() throws Exception {
BdfList list = BdfList.of(1, 2, 3); BdfList list = BdfList.of(1, 2, 3);
boolean defaultBoolean = true; boolean defaultBoolean = random.nextBoolean();
assertEquals(defaultBoolean, list.getBoolean(-1, defaultBoolean)); assertEquals(defaultBoolean, list.getBoolean(-1, defaultBoolean));
assertEquals(defaultBoolean, list.getBoolean(3, defaultBoolean)); assertEquals(defaultBoolean, list.getBoolean(3, defaultBoolean));
Long defaultLong = 123L; Long defaultLong = random.nextLong();
assertEquals(defaultLong, list.getLong(-1, defaultLong)); assertEquals(defaultLong, list.getLong(-1, defaultLong));
assertEquals(defaultLong, list.getLong(3, defaultLong)); assertEquals(defaultLong, list.getLong(3, defaultLong));
Double defaultDouble = 1.23; Double defaultDouble = random.nextDouble();
assertEquals(defaultDouble, list.getDouble(-1, defaultDouble)); assertEquals(defaultDouble, list.getDouble(-1, defaultDouble));
assertEquals(defaultDouble, list.getDouble(3, defaultDouble)); assertEquals(defaultDouble, list.getDouble(3, defaultDouble));
String defaultString = "123"; String defaultString = getRandomString(123);
assertEquals(defaultString, list.getString(-1, defaultString)); assertEquals(defaultString, list.getString(-1, defaultString));
assertEquals(defaultString, list.getString(3, defaultString)); assertEquals(defaultString, list.getString(3, defaultString));
byte[] defaultBytes = new byte[] {1, 2, 3}; byte[] defaultBytes = getRandomBytes(123);
assertArrayEquals(defaultBytes, list.getRaw(-1, defaultBytes)); assertArrayEquals(defaultBytes, list.getRaw(-1, defaultBytes));
assertArrayEquals(defaultBytes, list.getRaw(3, defaultBytes)); assertArrayEquals(defaultBytes, list.getRaw(3, defaultBytes));
BdfList defaultList = BdfList.of(1, 2, 3); BdfList defaultList = BdfList.of(1, 2, 3);
@@ -94,18 +99,17 @@ public class BdfListTest extends BrambleTestCase {
} }
@Test @Test
@SuppressWarnings("ConstantConditions") public void testWrongTypeReturnsDefaultValue() {
public void testWrongTypeReturnsDefaultValue() throws Exception {
BdfList list = BdfList.of(1, 2, 3, true); BdfList list = BdfList.of(1, 2, 3, true);
boolean defaultBoolean = true; boolean defaultBoolean = random.nextBoolean();
assertEquals(defaultBoolean, list.getBoolean(0, defaultBoolean)); assertEquals(defaultBoolean, list.getBoolean(0, defaultBoolean));
Long defaultLong = 123L; Long defaultLong = random.nextLong();
assertEquals(defaultLong, list.getLong(3, defaultLong)); assertEquals(defaultLong, list.getLong(3, defaultLong));
Double defaultDouble = 1.23; Double defaultDouble = random.nextDouble();
assertEquals(defaultDouble, list.getDouble(0, defaultDouble)); assertEquals(defaultDouble, list.getDouble(0, defaultDouble));
String defaultString = "123"; String defaultString = getRandomString(123);
assertEquals(defaultString, list.getString(0, defaultString)); assertEquals(defaultString, list.getString(0, defaultString));
byte[] defaultBytes = new byte[] {1, 2, 3}; byte[] defaultBytes = getRandomBytes(123);
assertArrayEquals(defaultBytes, list.getRaw(0, defaultBytes)); assertArrayEquals(defaultBytes, list.getRaw(0, defaultBytes));
BdfList defaultList = BdfList.of(1, 2, 3); BdfList defaultList = BdfList.of(1, 2, 3);
assertEquals(defaultList, list.getList(0, defaultList)); assertEquals(defaultList, list.getList(0, defaultList));

View File

@@ -49,7 +49,9 @@ public class TestUtils {
public static void deleteTestDirectory(File testDir) { public static void deleteTestDirectory(File testDir) {
deleteFileOrDir(testDir); deleteFileOrDir(testDir);
testDir.getParentFile().delete(); // Delete if empty // Delete parent directory only if it's empty
//noinspection ResultOfMethodCallIgnored
testDir.getParentFile().delete();
} }
public static byte[] getRandomBytes(int length) { public static byte[] getRandomBytes(int length) {

View File

@@ -282,6 +282,8 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
InputStream in = null; InputStream in = null;
OutputStream out = null; OutputStream out = null;
try { try {
// The done file may already exist from a previous installation
//noinspection ResultOfMethodCallIgnored
doneFile.delete(); doneFile.delete();
// Unzip the Tor binary to the filesystem // Unzip the Tor binary to the filesystem
in = getTorInputStream(); in = getTorInputStream();
@@ -303,7 +305,8 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
in = getConfigInputStream(); in = getConfigInputStream();
out = new FileOutputStream(configFile); out = new FileOutputStream(configFile);
copyAndClose(in, out); copyAndClose(in, out);
doneFile.createNewFile(); if (!doneFile.createNewFile())
LOG.warning("Failed to create done file");
} catch (IOException e) { } catch (IOException e) {
IoUtils.tryToClose(in, LOG, WARNING); IoUtils.tryToClose(in, LOG, WARNING);
IoUtils.tryToClose(out, LOG, WARNING); IoUtils.tryToClose(out, LOG, WARNING);

View File

@@ -318,6 +318,8 @@ public class AccountManagerImplTest extends BrambleMockTestCase {
} }
private void storeDatabaseKey(File f, String hex) throws IOException { private void storeDatabaseKey(File f, String hex) throws IOException {
// Create parent directory if it doesn't already exist
//noinspection ResultOfMethodCallIgnored
f.getParentFile().mkdirs(); f.getParentFile().mkdirs();
FileOutputStream out = new FileOutputStream(f); FileOutputStream out = new FileOutputStream(f);
out.write(hex.getBytes("UTF-8")); out.write(hex.getBytes("UTF-8"));

View File

@@ -1393,7 +1393,6 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
} }
@Test @Test
@SuppressWarnings("unchecked")
public void testMessageDependencies() throws Exception { public void testMessageDependencies() throws Exception {
int shutdownHandle = 12345; int shutdownHandle = 12345;
MessageId messageId2 = new MessageId(getRandomId()); MessageId messageId2 = new MessageId(getRandomId());

View File

@@ -85,7 +85,6 @@ public class Localizer {
context.createConfigurationContext(conf); context.createConfigurationContext(conf);
} else } else
conf.locale = locale; conf.locale = locale;
//noinspection deprecation
res.updateConfiguration(conf, res.getDisplayMetrics()); res.updateConfiguration(conf, res.getDisplayMetrics());
return context; return context;
} }

View File

@@ -431,17 +431,11 @@ public class CameraView extends SurfaceView implements SurfaceHolder.Callback,
@Override @Override
public void surfaceCreated(SurfaceHolder holder) { public void surfaceCreated(SurfaceHolder holder) {
post(() -> { post(() -> surfaceCreatedUi(holder));
try {
surfaceCreatedUi(holder);
} catch (CameraException e) {
logException(LOG, WARNING, e);
}
});
} }
@UiThread @UiThread
private void surfaceCreatedUi(SurfaceHolder holder) throws CameraException { private void surfaceCreatedUi(SurfaceHolder holder) {
LOG.info("Surface created"); LOG.info("Surface created");
if (surface != null && surface != holder.getSurface()) { if (surface != null && surface != holder.getSurface()) {
LOG.info("Releasing old surface"); LOG.info("Releasing old surface");

View File

@@ -81,7 +81,6 @@ public abstract class ThreadListControllerImpl<G extends NamedGroup, I extends T
} }
@CallSuper @CallSuper
@SuppressWarnings("unchecked")
@Override @Override
public void onActivityCreate(Activity activity) { public void onActivityCreate(Activity activity) {
listener = (L) activity; listener = (L) activity;

View File

@@ -1166,10 +1166,9 @@ public class IntroductionIntegrationTest
@ParametersNotNullByDefault @ParametersNotNullByDefault
private abstract class IntroductionListener implements EventListener { private abstract class IntroductionListener implements EventListener {
protected volatile boolean aborted = false; volatile boolean aborted = false;
protected volatile Event latestEvent; volatile Event latestEvent;
@SuppressWarnings("WeakerAccess")
IntroductionResponse getResponse() { IntroductionResponse getResponse() {
assertTrue( assertTrue(
latestEvent instanceof IntroductionResponseReceivedEvent); latestEvent instanceof IntroductionResponseReceivedEvent);

View File

@@ -326,6 +326,7 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
} }
} }
@SuppressWarnings("ResultOfMethodCallIgnored")
private void expectParseMessageMetadata() throws Exception { private void expectParseMessageMetadata() throws Exception {
context.checking(new Expectations() {{ context.checking(new Expectations() {{
oneOf(messageParser).parseMetadata(meta); oneOf(messageParser).parseMetadata(meta);
@@ -351,6 +352,7 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
expectStoreSession(session, storageMessage.getId()); expectStoreSession(session, storageMessage.getId());
} }
@SuppressWarnings("ResultOfMethodCallIgnored")
@Nullable @Nullable
private Session expectHandleFirstMessage(Role role, private Session expectHandleFirstMessage(Role role,
MessageMetadata messageMetadata, MessageType type) MessageMetadata messageMetadata, MessageType type)
@@ -363,23 +365,20 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
}}); }});
if (type == ABORT || type == LEAVE) return null; if (type == ABORT || type == LEAVE) return null;
AbstractProtocolEngine engine;
Session session;
if (type == INVITE) { if (type == INVITE) {
assertEquals(Role.INVITEE, role); assertEquals(Role.INVITEE, role);
engine = inviteeEngine; expectIndividualMessage(type, inviteeEngine, inviteeSession);
session = inviteeSession; return inviteeSession;
} else if (type == JOIN) { } else if (type == JOIN) {
assertEquals(Role.PEER, role); assertEquals(Role.PEER, role);
engine = peerEngine; expectIndividualMessage(type, peerEngine, peerSession);
session = peerSession; return peerSession;
} else { } else {
throw new AssertionError(); throw new AssertionError();
} }
expectIndividualMessage(type, engine, session);
return session;
} }
@SuppressWarnings("ResultOfMethodCallIgnored")
@Nullable @Nullable
private Session expectHandleMessage(Role role, private Session expectHandleMessage(Role role,
MessageMetadata messageMetadata, BdfDictionary state, MessageMetadata messageMetadata, BdfDictionary state,
@@ -809,6 +808,7 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
.isInvitationAllowed(contact, privateGroup.getId())); .isInvitationAllowed(contact, privateGroup.getId()));
} }
@SuppressWarnings("ResultOfMethodCallIgnored")
private void expectIsInvitationAllowed(CreatorState state) private void expectIsInvitationAllowed(CreatorState state)
throws Exception { throws Exception {
expectGetSession(oneResult, sessionId, contactGroup.getId()); expectGetSession(oneResult, sessionId, contactGroup.getId());