mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 12:19:54 +01:00
Lint cleanups.
This commit is contained in:
@@ -25,7 +25,6 @@ public class AndroidUtils {
|
||||
|
||||
private static final String STORED_REPORTS = "dev-reports";
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static Collection<String> getSupportedArchitectures() {
|
||||
List<String> abis = new ArrayList<>();
|
||||
if (SDK_INT >= 21) {
|
||||
|
||||
@@ -5,14 +5,20 @@ import org.briarproject.bramble.api.FormatException;
|
||||
import org.briarproject.bramble.test.BrambleTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static java.util.Collections.emptyList;
|
||||
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.assertEquals;
|
||||
|
||||
public class BdfListTest extends BrambleTestCase {
|
||||
|
||||
private final Random random = new Random();
|
||||
|
||||
@Test
|
||||
public void testConstructors() {
|
||||
assertEquals(emptyList(), new BdfList());
|
||||
@@ -63,22 +69,21 @@ public class BdfListTest extends BrambleTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
public void testIndexOutOfBoundsReturnsDefaultValue() throws Exception {
|
||||
public void testIndexOutOfBoundsReturnsDefaultValue() {
|
||||
BdfList list = BdfList.of(1, 2, 3);
|
||||
boolean defaultBoolean = true;
|
||||
boolean defaultBoolean = random.nextBoolean();
|
||||
assertEquals(defaultBoolean, list.getBoolean(-1, defaultBoolean));
|
||||
assertEquals(defaultBoolean, list.getBoolean(3, defaultBoolean));
|
||||
Long defaultLong = 123L;
|
||||
Long defaultLong = random.nextLong();
|
||||
assertEquals(defaultLong, list.getLong(-1, 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(3, defaultDouble));
|
||||
String defaultString = "123";
|
||||
String defaultString = getRandomString(123);
|
||||
assertEquals(defaultString, list.getString(-1, 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(3, defaultBytes));
|
||||
BdfList defaultList = BdfList.of(1, 2, 3);
|
||||
@@ -94,18 +99,17 @@ public class BdfListTest extends BrambleTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
public void testWrongTypeReturnsDefaultValue() throws Exception {
|
||||
public void testWrongTypeReturnsDefaultValue() {
|
||||
BdfList list = BdfList.of(1, 2, 3, true);
|
||||
boolean defaultBoolean = true;
|
||||
boolean defaultBoolean = random.nextBoolean();
|
||||
assertEquals(defaultBoolean, list.getBoolean(0, defaultBoolean));
|
||||
Long defaultLong = 123L;
|
||||
Long defaultLong = random.nextLong();
|
||||
assertEquals(defaultLong, list.getLong(3, defaultLong));
|
||||
Double defaultDouble = 1.23;
|
||||
Double defaultDouble = random.nextDouble();
|
||||
assertEquals(defaultDouble, list.getDouble(0, defaultDouble));
|
||||
String defaultString = "123";
|
||||
String defaultString = getRandomString(123);
|
||||
assertEquals(defaultString, list.getString(0, defaultString));
|
||||
byte[] defaultBytes = new byte[] {1, 2, 3};
|
||||
byte[] defaultBytes = getRandomBytes(123);
|
||||
assertArrayEquals(defaultBytes, list.getRaw(0, defaultBytes));
|
||||
BdfList defaultList = BdfList.of(1, 2, 3);
|
||||
assertEquals(defaultList, list.getList(0, defaultList));
|
||||
|
||||
@@ -49,7 +49,9 @@ public class TestUtils {
|
||||
|
||||
public static void deleteTestDirectory(File 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) {
|
||||
|
||||
@@ -282,6 +282,8 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
InputStream in = null;
|
||||
OutputStream out = null;
|
||||
try {
|
||||
// The done file may already exist from a previous installation
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
doneFile.delete();
|
||||
// Unzip the Tor binary to the filesystem
|
||||
in = getTorInputStream();
|
||||
@@ -303,7 +305,8 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
in = getConfigInputStream();
|
||||
out = new FileOutputStream(configFile);
|
||||
copyAndClose(in, out);
|
||||
doneFile.createNewFile();
|
||||
if (!doneFile.createNewFile())
|
||||
LOG.warning("Failed to create done file");
|
||||
} catch (IOException e) {
|
||||
IoUtils.tryToClose(in, LOG, WARNING);
|
||||
IoUtils.tryToClose(out, LOG, WARNING);
|
||||
|
||||
@@ -318,6 +318,8 @@ public class AccountManagerImplTest extends BrambleMockTestCase {
|
||||
}
|
||||
|
||||
private void storeDatabaseKey(File f, String hex) throws IOException {
|
||||
// Create parent directory if it doesn't already exist
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
f.getParentFile().mkdirs();
|
||||
FileOutputStream out = new FileOutputStream(f);
|
||||
out.write(hex.getBytes("UTF-8"));
|
||||
|
||||
@@ -1393,7 +1393,6 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testMessageDependencies() throws Exception {
|
||||
int shutdownHandle = 12345;
|
||||
MessageId messageId2 = new MessageId(getRandomId());
|
||||
|
||||
@@ -85,7 +85,6 @@ public class Localizer {
|
||||
context.createConfigurationContext(conf);
|
||||
} else
|
||||
conf.locale = locale;
|
||||
//noinspection deprecation
|
||||
res.updateConfiguration(conf, res.getDisplayMetrics());
|
||||
return context;
|
||||
}
|
||||
|
||||
@@ -431,17 +431,11 @@ public class CameraView extends SurfaceView implements SurfaceHolder.Callback,
|
||||
|
||||
@Override
|
||||
public void surfaceCreated(SurfaceHolder holder) {
|
||||
post(() -> {
|
||||
try {
|
||||
surfaceCreatedUi(holder);
|
||||
} catch (CameraException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
}
|
||||
});
|
||||
post(() -> surfaceCreatedUi(holder));
|
||||
}
|
||||
|
||||
@UiThread
|
||||
private void surfaceCreatedUi(SurfaceHolder holder) throws CameraException {
|
||||
private void surfaceCreatedUi(SurfaceHolder holder) {
|
||||
LOG.info("Surface created");
|
||||
if (surface != null && surface != holder.getSurface()) {
|
||||
LOG.info("Releasing old surface");
|
||||
|
||||
@@ -81,7 +81,6 @@ public abstract class ThreadListControllerImpl<G extends NamedGroup, I extends T
|
||||
}
|
||||
|
||||
@CallSuper
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void onActivityCreate(Activity activity) {
|
||||
listener = (L) activity;
|
||||
|
||||
@@ -1166,10 +1166,9 @@ public class IntroductionIntegrationTest
|
||||
@ParametersNotNullByDefault
|
||||
private abstract class IntroductionListener implements EventListener {
|
||||
|
||||
protected volatile boolean aborted = false;
|
||||
protected volatile Event latestEvent;
|
||||
volatile boolean aborted = false;
|
||||
volatile Event latestEvent;
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
IntroductionResponse getResponse() {
|
||||
assertTrue(
|
||||
latestEvent instanceof IntroductionResponseReceivedEvent);
|
||||
|
||||
@@ -326,6 +326,7 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||
private void expectParseMessageMetadata() throws Exception {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(messageParser).parseMetadata(meta);
|
||||
@@ -351,6 +352,7 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
expectStoreSession(session, storageMessage.getId());
|
||||
}
|
||||
|
||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||
@Nullable
|
||||
private Session expectHandleFirstMessage(Role role,
|
||||
MessageMetadata messageMetadata, MessageType type)
|
||||
@@ -363,23 +365,20 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
}});
|
||||
if (type == ABORT || type == LEAVE) return null;
|
||||
|
||||
AbstractProtocolEngine engine;
|
||||
Session session;
|
||||
if (type == INVITE) {
|
||||
assertEquals(Role.INVITEE, role);
|
||||
engine = inviteeEngine;
|
||||
session = inviteeSession;
|
||||
expectIndividualMessage(type, inviteeEngine, inviteeSession);
|
||||
return inviteeSession;
|
||||
} else if (type == JOIN) {
|
||||
assertEquals(Role.PEER, role);
|
||||
engine = peerEngine;
|
||||
session = peerSession;
|
||||
expectIndividualMessage(type, peerEngine, peerSession);
|
||||
return peerSession;
|
||||
} else {
|
||||
throw new AssertionError();
|
||||
}
|
||||
expectIndividualMessage(type, engine, session);
|
||||
return session;
|
||||
}
|
||||
|
||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||
@Nullable
|
||||
private Session expectHandleMessage(Role role,
|
||||
MessageMetadata messageMetadata, BdfDictionary state,
|
||||
@@ -809,6 +808,7 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
.isInvitationAllowed(contact, privateGroup.getId()));
|
||||
}
|
||||
|
||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||
private void expectIsInvitationAllowed(CreatorState state)
|
||||
throws Exception {
|
||||
expectGetSession(oneResult, sessionId, contactGroup.getId());
|
||||
|
||||
Reference in New Issue
Block a user