Skip to content
This repository has been archived by the owner on May 23, 2019. It is now read-only.

Commit

Permalink
Fix checksyle issues
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrovgs committed Dec 13, 2015
1 parent 94102c0 commit ef1c265
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@
import com.github.pedrovgs.androidwifiadb.view.View;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

public class AndroidWiFiADB {

private static final Set<Device> DEVICES = new HashSet<Device>();
private final ADB adb;
private final View view;
private static final Set<Device> devices = new LinkedHashSet<Device>();

public AndroidWiFiADB(ADB adb, View view) {
this.adb = adb;
Expand All @@ -41,15 +41,15 @@ public void connectDevices() {
view.showADBNotInstalledNotification();
return;
}
devices.clear();
devices.addAll(adb.getDevicesConnectedByUSB());
if (devices.isEmpty()) {
DEVICES.clear();
DEVICES.addAll(adb.getDevicesConnectedByUSB());
if (DEVICES.isEmpty()) {
view.showNoConnectedDevicesNotification();
return;
}

devices.addAll(adb.connectDevices(devices));
showConnectionResultNotification(devices);
DEVICES.addAll(adb.connectDevices(DEVICES));
showConnectionResultNotification(DEVICES);
}

public boolean refreshDevicesList() {
Expand All @@ -61,7 +61,7 @@ public boolean refreshDevicesList() {
for (Device connectedDevice : connected) {
if (!checkDeviceExistance(connectedDevice)) {
connectedDevice.setIp(adb.getDeviceIp(connectedDevice));
devices.add(connectedDevice);
DEVICES.add(connectedDevice);
} else {
updateDeviceConnectionState(connectedDevice);
}
Expand All @@ -71,17 +71,17 @@ public boolean refreshDevicesList() {

private void removeNotConnectedDevices() {
List<Device> connectedDevices = new LinkedList<Device>();
for (Device device : devices){
if (device.isConnected()){
connectedDevices.add(device);
}
for (Device device : DEVICES) {
if (device.isConnected()) {
connectedDevices.add(device);
}
}
devices.clear();
devices.addAll(connectedDevices);
DEVICES.clear();
DEVICES.addAll(connectedDevices);
}

public Collection<Device> getDevices() {
return devices;
return DEVICES;
}

public void connectDevice(Device device) {
Expand Down Expand Up @@ -115,12 +115,12 @@ public void disconnectDevice(Device device) {
}

private void updateDeviceConnectionState(final Device updatedDevice) {
devices.add(updatedDevice);
DEVICES.add(updatedDevice);
}

private boolean checkDeviceExistance(Device connectedDevice) {
boolean deviceExists = false;
for (Device device : devices) {
for (Device device : DEVICES) {
if (connectedDevice.getId().equals(device.getId())) {
deviceExists = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,11 @@

import com.github.pedrovgs.androidwifiadb.Device;
import com.intellij.ui.table.JBTable;

import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Container;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
Expand Down Expand Up @@ -133,8 +130,9 @@ private void configureTableAppearance() {
tableDevices.getColumnModel().getColumn(2).setMinWidth(215);
tableDevices.getColumnModel().getColumn(2).setMaxWidth(215);
tableDevices.getColumnModel().getColumn(2).setCellRenderer(new ConnectDisconnectRenderer());
tableDevices.getColumnModel().getColumn(2).setCellEditor(
new ConnectDisconnectEditor(new JCheckBox(), this));
tableDevices.getColumnModel()
.getColumn(2)
.setCellEditor(new ConnectDisconnectEditor(new JCheckBox(), this));
}

private void updateDevicesTable() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import com.github.pedrovgs.androidwifiadb.adb.ADB;
import com.github.pedrovgs.androidwifiadb.view.View;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
Expand All @@ -30,7 +29,6 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.anyObject;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -86,16 +84,14 @@ public class AndroidWiFiADBTest extends UnitTest {
}
}

@Test
public void shouldNotRefreshDevicesListIfAdbIsNotIstalled() throws Exception {
@Test public void shouldNotRefreshDevicesListIfAdbIsNotIstalled() throws Exception {
AndroidWiFiADB androidWiFiAdb = givenAnAndroidWiFiADB();
givenADBIsNotInstalled();

assertFalse(androidWiFiAdb.refreshDevicesList());
}

@Test
public void shouldRefreshDevicesListAddNewDevice() throws Exception {
@Test public void shouldRefreshDevicesListAddNewDevice() throws Exception {
AndroidWiFiADB androidWiFiAdb = givenAnAndroidWiFiADB();
List<Device> devices = givenThereAreSomeDevicesConnectedByUSB();
givenDevicesAreConnectedSuccessfully(devices);
Expand All @@ -106,8 +102,7 @@ public void shouldRefreshDevicesListAddNewDevice() throws Exception {
assertEquals(devices.size(), androidWiFiAdb.getDevices().size());
}

@Test
public void shouldRefreshDevicesListUpdateExistingDevices() throws Exception {
@Test public void shouldRefreshDevicesListUpdateExistingDevices() throws Exception {
AndroidWiFiADB androidWiFiAdb = givenAnAndroidWiFiADB();
List<Device> devices = givenThereAreSomeDevicesConnectedByUSB();
givenDevicesAreConnectedSuccessfully(devices);
Expand All @@ -118,8 +113,7 @@ public void shouldRefreshDevicesListUpdateExistingDevices() throws Exception {
assertEquals(devices.size(), androidWiFiAdb.getDevices().size());
}

@Test
public void shouldDisconnectDevice() throws Exception {
@Test public void shouldDisconnectDevice() throws Exception {
AndroidWiFiADB androidWiFiAdb = givenAnAndroidWiFiADB();
givenADBIsInstalled();
Device device = givenAnyConnectedDevice();
Expand All @@ -130,8 +124,7 @@ public void shouldDisconnectDevice() throws Exception {
assertFalse(device.isConnected());
}

@Test
public void shouldConnectDevice() throws Exception {
@Test public void shouldConnectDevice() throws Exception {
AndroidWiFiADB androidWiFiAdb = givenAnAndroidWiFiADB();
givenADBIsInstalled();
Device device = givenAnyDisonnectedDevice();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ public void shouldReturnEditableCellForActionColumn() throws Exception {

androidDevicesTableModel.add(givenAnyDevice());

assertFalse(androidDevicesTableModel.isCellEditable(0, COLUMN_STATE) || androidDevicesTableModel.isCellEditable(0, COLUMN_DEVICE));
assertFalse(androidDevicesTableModel.isCellEditable(0, COLUMN_STATE)
|| androidDevicesTableModel.isCellEditable(0, COLUMN_DEVICE));
assertTrue(androidDevicesTableModel.isCellEditable(0, COLUMN_ACTION));
}

Expand Down

0 comments on commit ef1c265

Please sign in to comment.