Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Commit

Permalink
Merge pull request #157 from g-ortuno/code-cleanup
Browse files Browse the repository at this point in the history
Code cleanup
  • Loading branch information
schilit committed Jan 23, 2015
2 parents 75309e1 + d0c2f98 commit d50466d
Show file tree
Hide file tree
Showing 25 changed files with 221 additions and 198 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@

import java.util.ArrayList;

public class BasicUriBeaconTests {
public static final String TEST_NAME = "Basic Tests";
public static ArrayList<TestHelper> initializeTests(Context context, TestCallback testCallback, boolean optional) {
class CoreUriBeaconTests {

public static final String TEST_NAME = "Core UriBeacon Tests";

public static ArrayList<TestHelper> initializeTests(Context context, TestCallback testCallback,
boolean optional) {
ArrayList<Builder> basicTestsBuilder = new ArrayList<>();
basicTestsBuilder.add(
new Builder()
Expand Down Expand Up @@ -80,9 +83,10 @@ public static ArrayList<TestHelper> initializeTests(Context context, TestCallbac
return setUpTests(basicTestsBuilder, context, testCallback);
}

private static ArrayList<TestHelper> setUpTests(ArrayList<Builder> basicTestsBuilder, Context context, TestCallback testCallback) {
private static ArrayList<TestHelper> setUpTests(ArrayList<Builder> basicTestsBuilder,
Context context, TestCallback testCallback) {
ArrayList<TestHelper> basicTests = new ArrayList<>();
for(Builder builder : basicTestsBuilder) {
for (Builder builder : basicTestsBuilder) {
basicTests.add(builder
.setUp(context, ProtocolV2.CONFIG_SERVICE_UUID, testCallback)
.build());
Expand Down Expand Up @@ -127,7 +131,8 @@ private static void addLockUnlockTests(ArrayList<Builder> basicTestsBuilder) {
new Builder()
.name("Unlocking...")
.write(ProtocolV2.UNLOCK, TestData.BASIC_LOCK_KEY, BluetoothGatt.GATT_SUCCESS)
.assertEquals(ProtocolV2.LOCK_STATE, TestData.UNLOCKED_STATE, BluetoothGatt.GATT_SUCCESS)
.assertEquals(ProtocolV2.LOCK_STATE, TestData.UNLOCKED_STATE,
BluetoothGatt.GATT_SUCCESS)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@ public class MainActivity extends Activity {

public static final String TEST_TYPE = "MainActivity.TestType";
public static final String LOCK_IMPLEMENTED = "MainActivity.LockImplemented";
private RecyclerView mRecyclerView;
private RecyclerView.Adapter mAdapter;
private RecyclerView.LayoutManager mLayoutManager;
private boolean lockImplemented = false;

private StartTestType mStartTestType = new StartTestType() {
private final StartTestType mStartTestType = new StartTestType() {
@Override
public void startTestType(String type) {
Intent intent = new Intent(MainActivity.this, TestActivity.class);
Expand All @@ -33,19 +30,20 @@ public void startTestType(String type) {
startActivity(intent);
}
};

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mRecyclerView = (RecyclerView) findViewById(R.id.recyclerView_types);
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerView_types);

mRecyclerView.setHasFixedSize(true);
recyclerView.setHasFixedSize(true);

mLayoutManager = new LinearLayoutManager(this);
mRecyclerView.setLayoutManager(mLayoutManager);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);

mAdapter = new TestTypesAdapter(getTestsInfo(), mStartTestType);
mRecyclerView.setAdapter(mAdapter);
RecyclerView.Adapter mAdapter = new TestTypesAdapter(getTestsInfo(), mStartTestType);
recyclerView.setAdapter(mAdapter);

}

Expand All @@ -70,14 +68,16 @@ public void onClick(View v) {

private TestInfo[] getTestsInfo() {
return new TestInfo[]{
new TestInfo(BasicUriBeaconTests.TEST_NAME, BasicUriBeaconTests.class.getName()),
new TestInfo(CoreUriBeaconTests.TEST_NAME, CoreUriBeaconTests.class.getName()),
new TestInfo(SpecUriBeaconTests.TEST_NAME, SpecUriBeaconTests.class.getName())
};
}

public class TestInfo {
public String testName;
public String className;

public final String testName;
public final String className;

public TestInfo(String testName, String className) {
this.testName = testName;
this.className = className;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@

import java.util.ArrayList;

public class SpecUriBeaconTests {
public static final String TEST_NAME = "Spec Tests";
public static ArrayList<TestHelper> initializeTests(Context context, TestCallback testCallback, boolean optional) {
class SpecUriBeaconTests {

public static final String TEST_NAME = "Spec UriBeacon Tests";

public static ArrayList<TestHelper> initializeTests(Context context, TestCallback testCallback,
boolean optional) {
ArrayList<Builder> specUriBeaconTestsBuilder = new ArrayList<>();
specUriBeaconTestsBuilder.add(
new Builder()
.name("Connecting...")
.connect()
.name("Connecting...")
.connect()
);
specUriBeaconTestsBuilder.add(
new Builder()
Expand Down Expand Up @@ -105,7 +108,8 @@ public static ArrayList<TestHelper> initializeTests(Context context, TestCallbac
new Builder()
.name("Locking beacon...")
.write(ProtocolV2.LOCK, TestData.BASIC_LOCK_KEY, BluetoothGatt.GATT_SUCCESS)
.assertEquals(ProtocolV2.LOCK_STATE, TestData.LOCKED_STATE, BluetoothGatt.GATT_SUCCESS)
.assertEquals(ProtocolV2.LOCK_STATE, TestData.LOCKED_STATE,
BluetoothGatt.GATT_SUCCESS)
);
specUriBeaconTestsBuilder.add(
new Builder()
Expand All @@ -129,7 +133,8 @@ public static ArrayList<TestHelper> initializeTests(Context context, TestCallbac
new Builder()
.name("Unlocking beacon...")
.write(ProtocolV2.UNLOCK, TestData.BASIC_LOCK_KEY, BluetoothGatt.GATT_SUCCESS)
.assertEquals(ProtocolV2.LOCK_STATE, TestData.UNLOCKED_STATE, BluetoothGatt.GATT_SUCCESS)
.assertEquals(ProtocolV2.LOCK_STATE, TestData.UNLOCKED_STATE,
BluetoothGatt.GATT_SUCCESS)
);
specUriBeaconTestsBuilder.add(
new Builder()
Expand All @@ -145,126 +150,147 @@ public static ArrayList<TestHelper> initializeTests(Context context, TestCallbac
specUriBeaconTestsBuilder.add(
new Builder()
.name("Try Unlock with Long Key")
.write(ProtocolV2.UNLOCK, TestData.LONG_LOCK_KEY, BluetoothGatt.GATT_INVALID_ATTRIBUTE_LENGTH)
.write(ProtocolV2.UNLOCK, TestData.LONG_LOCK_KEY,
BluetoothGatt.GATT_INVALID_ATTRIBUTE_LENGTH)
);
specUriBeaconTestsBuilder.add(
new Builder()
.name("Locking beacon...")
.write(ProtocolV2.LOCK, TestData.BASIC_LOCK_KEY, BluetoothGatt.GATT_SUCCESS)
.assertEquals(ProtocolV2.LOCK_STATE, TestData.LOCKED_STATE, BluetoothGatt.GATT_SUCCESS)
.assertEquals(ProtocolV2.LOCK_STATE, TestData.LOCKED_STATE,
BluetoothGatt.GATT_SUCCESS)
);
specUriBeaconTestsBuilder.add(
new Builder()
.name("Try to Unlock with Short Key")
.write(ProtocolV2.UNLOCK, TestData.SHORT_LOCK_KEY, BluetoothGatt.GATT_INVALID_ATTRIBUTE_LENGTH)
.write(ProtocolV2.UNLOCK, TestData.SHORT_LOCK_KEY,
BluetoothGatt.GATT_INVALID_ATTRIBUTE_LENGTH)
);
specUriBeaconTestsBuilder.add(
new Builder()
.name("Try Unlock with Long Key")
.write(ProtocolV2.UNLOCK, TestData.LONG_LOCK_KEY, BluetoothGatt.GATT_INVALID_ATTRIBUTE_LENGTH)
.write(ProtocolV2.UNLOCK, TestData.LONG_LOCK_KEY,
BluetoothGatt.GATT_INVALID_ATTRIBUTE_LENGTH)
);
specUriBeaconTestsBuilder.add(
new Builder()
.name("Unlocking...")
.write(ProtocolV2.UNLOCK, TestData.BASIC_LOCK_KEY, BluetoothGatt.GATT_SUCCESS)
.assertEquals(ProtocolV2.LOCK_STATE, TestData.UNLOCKED_STATE, BluetoothGatt.GATT_SUCCESS)
.assertEquals(ProtocolV2.LOCK_STATE, TestData.UNLOCKED_STATE,
BluetoothGatt.GATT_SUCCESS)
);
specUriBeaconTestsBuilder.add(
new Builder()
.name("Locking...")
.write(ProtocolV2.LOCK, TestData.BASIC_LOCK_KEY, BluetoothGatt.GATT_SUCCESS)
.assertEquals(ProtocolV2.LOCK_STATE, TestData.LOCKED_STATE, BluetoothGatt.GATT_SUCCESS)
.assertEquals(ProtocolV2.LOCK_STATE, TestData.LOCKED_STATE,
BluetoothGatt.GATT_SUCCESS)
);
specUriBeaconTestsBuilder.add(
new Builder()
.name("Locked: Try Long Data")
.write(ProtocolV2.DATA, TestData.LONG_URI, ConfigUriBeacon.INSUFFICIENT_AUTHORIZATION)
.name("Locked: Try Long Data")
.write(ProtocolV2.DATA, TestData.LONG_URI, ConfigUriBeacon.INSUFFICIENT_AUTHORIZATION)
);
specUriBeaconTestsBuilder.add(
new Builder()
.name("Locked: Try Short Flags")
.write(ProtocolV2.FLAGS, TestData.SHORT_FLAGS, ConfigUriBeacon.INSUFFICIENT_AUTHORIZATION)
.name("Locked: Try Short Flags")
.write(ProtocolV2.FLAGS, TestData.SHORT_FLAGS,
ConfigUriBeacon.INSUFFICIENT_AUTHORIZATION)
);
specUriBeaconTestsBuilder.add(
new Builder()
.name("Locked: Try Valid Flags")
.write(ProtocolV2.FLAGS, TestData.BASIC_GENERAL_DATA, ConfigUriBeacon.INSUFFICIENT_AUTHORIZATION)
.name("Locked: Try Valid Flags")
.write(ProtocolV2.FLAGS, TestData.BASIC_GENERAL_DATA,
ConfigUriBeacon.INSUFFICIENT_AUTHORIZATION)
);
specUriBeaconTestsBuilder.add(
new Builder()
.name("Locked: Try Long Flags")
.write(ProtocolV2.FLAGS, TestData.LONG_FLAGS, ConfigUriBeacon.INSUFFICIENT_AUTHORIZATION)
.name("Locked: Try Long Flags")
.write(ProtocolV2.FLAGS, TestData.LONG_FLAGS,
ConfigUriBeacon.INSUFFICIENT_AUTHORIZATION)
);
specUriBeaconTestsBuilder.add(
new Builder()
.name("Locked: Try Short Advertised Tx Power Levels")
.write(ProtocolV2.POWER_LEVELS, TestData.SHORT_TX_POWER_LEVELS, ConfigUriBeacon.INSUFFICIENT_AUTHORIZATION)
.name("Locked: Try Short Advertised Tx Power Levels")
.write(ProtocolV2.POWER_LEVELS, TestData.SHORT_TX_POWER_LEVELS,
ConfigUriBeacon.INSUFFICIENT_AUTHORIZATION)
);
specUriBeaconTestsBuilder.add(
new Builder()
.name("Locked: Try Valid Advertised Tx Power Levels")
.write(ProtocolV2.POWER_LEVELS, TestData.BASIC_TX_POWER_LEVELS, ConfigUriBeacon.INSUFFICIENT_AUTHORIZATION)
.name("Locked: Try Valid Advertised Tx Power Levels")
.write(ProtocolV2.POWER_LEVELS, TestData.BASIC_TX_POWER_LEVELS,
ConfigUriBeacon.INSUFFICIENT_AUTHORIZATION)
);
specUriBeaconTestsBuilder.add(
new Builder()
.name("Locked: Try Long Advertised Tx Power Levels")
.write(ProtocolV2.POWER_LEVELS, TestData.LONG_TX_POWER_LEVELS, ConfigUriBeacon.INSUFFICIENT_AUTHORIZATION)
.name("Locked: Try Long Advertised Tx Power Levels")
.write(ProtocolV2.POWER_LEVELS, TestData.LONG_TX_POWER_LEVELS,
ConfigUriBeacon.INSUFFICIENT_AUTHORIZATION)
);
specUriBeaconTestsBuilder.add(
new Builder()
.name("Locked: Try Short Power Mode")
.write(ProtocolV2.POWER_MODE, TestData.SHORT_POWER_MODE, ConfigUriBeacon.INSUFFICIENT_AUTHORIZATION)
.name("Locked: Try Short Power Mode")
.write(ProtocolV2.POWER_MODE, TestData.SHORT_POWER_MODE,
ConfigUriBeacon.INSUFFICIENT_AUTHORIZATION)
);
specUriBeaconTestsBuilder.add(
new Builder()
.name("Locked: Try Valid Power Mode")
.write(ProtocolV2.POWER_MODE, TestData.BASIC_GENERAL_DATA, ConfigUriBeacon.INSUFFICIENT_AUTHORIZATION)
.name("Locked: Try Valid Power Mode")
.write(ProtocolV2.POWER_MODE, TestData.BASIC_GENERAL_DATA,
ConfigUriBeacon.INSUFFICIENT_AUTHORIZATION)
);
specUriBeaconTestsBuilder.add(
new Builder()
.name("Locked: Try Long Power Mode")
.write(ProtocolV2.POWER_MODE, TestData.BASIC_GENERAL_DATA, ConfigUriBeacon.INSUFFICIENT_AUTHORIZATION)
.name("Locked: Try Long Power Mode")
.write(ProtocolV2.POWER_MODE, TestData.BASIC_GENERAL_DATA,
ConfigUriBeacon.INSUFFICIENT_AUTHORIZATION)
);
specUriBeaconTestsBuilder.add(
new Builder()
.name("Locked: Try Short Period")
.write(ProtocolV2.PERIOD, TestData.SHORT_PERIOD, ConfigUriBeacon.INSUFFICIENT_AUTHORIZATION)
.name("Locked: Try Short Period")
.write(ProtocolV2.PERIOD, TestData.SHORT_PERIOD,
ConfigUriBeacon.INSUFFICIENT_AUTHORIZATION)
);
specUriBeaconTestsBuilder.add(
new Builder()
.name("Locked: Try Valid Period")
.write(ProtocolV2.PERIOD, TestData.BASIC_PERIOD, ConfigUriBeacon.INSUFFICIENT_AUTHORIZATION)
.name("Locked: Try Valid Period")
.write(ProtocolV2.PERIOD, TestData.BASIC_PERIOD,
ConfigUriBeacon.INSUFFICIENT_AUTHORIZATION)
);
specUriBeaconTestsBuilder.add(
new Builder()
.name("Locked: Try Long Period")
.write(ProtocolV2.PERIOD, TestData.LONG_PERIOD, ConfigUriBeacon.INSUFFICIENT_AUTHORIZATION)
.name("Locked: Try Long Period")
.write(ProtocolV2.PERIOD, TestData.LONG_PERIOD,
ConfigUriBeacon.INSUFFICIENT_AUTHORIZATION)
);
specUriBeaconTestsBuilder.add(
new Builder()
.name("Locked: Try Short Reset")
.write(ProtocolV2.RESET, TestData.SHORT_RESET, ConfigUriBeacon.INSUFFICIENT_AUTHORIZATION)
.name("Locked: Try Short Reset")
.write(ProtocolV2.RESET, TestData.SHORT_RESET,
ConfigUriBeacon.INSUFFICIENT_AUTHORIZATION)
);
specUriBeaconTestsBuilder.add(
new Builder()
.name("Locked: Try Valid Reset")
.write(ProtocolV2.RESET, TestData.BASIC_GENERAL_DATA, ConfigUriBeacon.INSUFFICIENT_AUTHORIZATION)
.name("Locked: Try Valid Reset")
.write(ProtocolV2.RESET, TestData.BASIC_GENERAL_DATA,
ConfigUriBeacon.INSUFFICIENT_AUTHORIZATION)
);
specUriBeaconTestsBuilder.add(
new Builder()
.name("Locked: Try Long Reset")
.write(ProtocolV2.RESET, TestData.LONG_RESET, ConfigUriBeacon.INSUFFICIENT_AUTHORIZATION)
.name("Locked: Try Long Reset")
.write(ProtocolV2.RESET, TestData.LONG_RESET,
ConfigUriBeacon.INSUFFICIENT_AUTHORIZATION)
);
specUriBeaconTestsBuilder.add(
new Builder()
.name("Unlocking...")
.write(ProtocolV2.UNLOCK, TestData.BASIC_LOCK_KEY, BluetoothGatt.GATT_SUCCESS)
.name("Unlocking...")
.write(ProtocolV2.UNLOCK, TestData.BASIC_LOCK_KEY, BluetoothGatt.GATT_SUCCESS)
);
}
specUriBeaconTestsBuilder.add(
new Builder()
.name("Disconnecting...")
.disconnect()
.name("Disconnecting...")
.disconnect()
);
ArrayList<TestHelper> specUriBeaconTests = new ArrayList<>();
for (Builder builder : specUriBeaconTestsBuilder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import java.util.UUID;

public class TestAction {
class TestAction {

public final static int CONNECT = 0;
public final static int WRITE = 1;
Expand All @@ -31,7 +31,7 @@ public class TestAction {
public final static int LAST = 8;


public int actionType;
public final int actionType;
public UUID characteristicUuid;
public int expectedReturnCode;
public byte[] transmittedValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ public class TestActivity extends Activity {

private static final String TAG = TestActivity.class.getCanonicalName();
private TestRunner mTestRunner;
private ArrayList<TestHelper> mUriBeaconTests;
private DataCallback mDataCallback = new DataCallback() {
private final DataCallback mDataCallback = new DataCallback() {
ProgressDialog progress;

@Override
Expand Down Expand Up @@ -91,21 +90,18 @@ public void run() {
});
}
};
// Recycle view variables
private RecyclerView mRecyclerView;
private RecyclerView.Adapter mAdapter;
private RecyclerView.LayoutManager mLayoutManager;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
boolean optionalImplemented = getIntent().getBooleanExtra(MainActivity.LOCK_IMPLEMENTED, false);
String testType = getIntent().getStringExtra(MainActivity.TEST_TYPE);
mTestRunner = new TestRunner(this, mDataCallback, testType, optionalImplemented);
mUriBeaconTests = mTestRunner.getUriBeaconTests();
mRecyclerView = (RecyclerView) findViewById(R.id.recyclerView_tests);
mLayoutManager = new LinearLayoutManager(this);
mTestRunner = new TestRunner(this, mDataCallback, testType, optionalImplemented);
ArrayList<TestHelper> mUriBeaconTests = mTestRunner.getUriBeaconTests();
RecyclerView mRecyclerView = (RecyclerView) findViewById(R.id.recyclerView_tests);
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(this);
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setLayoutManager(mLayoutManager);
mAdapter = new TestsAdapter(mUriBeaconTests);
Expand Down
Loading

0 comments on commit d50466d

Please sign in to comment.