Skip to content

Commit 0c2dca5

Browse files
author
Luc van den Brand
authored
Merge pull request #98 from RUGSoftEng/release-0.5
Release 0.5
2 parents fb9387a + 90f9308 commit 0c2dca5

85 files changed

Lines changed: 1499 additions & 1424 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
18.1 KB
Binary file not shown.
18.2 KB
Binary file not shown.
17 Bytes
Binary file not shown.

.travis.yml

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
1+
sudo: false
2+
13
language: android
4+
jdk: oraclejdk8
25
android:
36
components:
7+
# Auxiliary tools which have to be installed
8+
- tools
9+
- tools # see https://github.com/travis-ci/travis-ci/issues/6040#issuecomment-219367943
10+
- platform-tools
11+
412
# The BuildTools version used
5-
- build-tools-19.1.0
13+
- build-tools-25.0.3
614

715
# The SDK version used to compile the project
16+
- android-25
817
- android-22
918

1019
# Additional components
@@ -17,5 +26,39 @@ android:
1726
- sys-img-armeabi-v7a-android-22
1827
- sys-img-armeabi-v7a-android-17
1928

29+
before_install:
30+
# copy the licenses to the correct file on the Travis system
31+
- pip install --user codecov #Install codecov
32+
- cp -r licenses/ /usr/local/android-sdk/licenses/
33+
- cd Hestia
34+
35+
install:
36+
- bash gradlew tasks --all --stacktrace --info
37+
38+
before_script:
39+
- android update sdk --no-ui --filter build-tools-25.0.3,android-25,extra-android-m2repository
40+
# Start emulator
41+
- echo no | android create avd --force -n test -t android-22 --abi armeabi-v7a
42+
- emulator -avd test -no-audio -no-window &
43+
- android-wait-for-emulator
44+
- adb shell input keyevent 82 &
45+
2046
script:
21-
- bash Hestia/gradlew tasks --all
47+
- bash gradlew app:connectedCheck
48+
- bash gradlew app:createDebugCoverageReport
49+
50+
after_failure:
51+
# Prints any linting errors after failing
52+
- cat $TRAVIS_BUILD_DIR/app/build/outputs/lint-results-debug.xml
53+
54+
after_success:
55+
- codecov
56+
- sh set_tags.sh
57+
58+
before_cache:
59+
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
60+
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/
61+
cache:
62+
directories:
63+
- $HOME/.gradle/caches/
64+
- $HOME/.gradle/wrapper/

Hestia/app/build.gradle

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apply plugin: 'com.android.application'
22

33
android {
44
compileSdkVersion 25
5-
buildToolsVersion "25.0.2"
5+
buildToolsVersion "25.0.3"
66
defaultConfig {
77
applicationId "com.rugged.application.hestia"
88
minSdkVersion 15
@@ -17,14 +17,26 @@ android {
1717
minifyEnabled false
1818
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
1919
}
20+
debug{
21+
testCoverageEnabled = true
22+
}
2023
}
2124
}
2225

2326
dependencies {
2427
compile fileTree(include: ['*.jar'], dir: 'libs')
28+
androidTestCompile ('com.android.support.test.espresso:espresso-intents:2.2.2', {
29+
exclude group: 'com.android.support',module: 'support-annotations'
30+
})
2531
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
2632
exclude group: 'com.android.support', module: 'support-annotations'
2733
})
34+
androidTestCompile ('com.android.support.test:runner:0.5', {
35+
exclude group: 'com.android.support',module: 'support-annotations'
36+
})
37+
androidTestCompile ('com.android.support.test:rules:0.5', {
38+
exclude group: 'com.android.support',module: 'support-annotations'
39+
})
2840
compile 'com.android.support:appcompat-v7:25.3.1'
2941
testCompile 'junit:junit:4.12'
3042
compile 'com.android.support:recyclerview-v7:25.3.1'
Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,19 @@
11
package com.rugged.application.hestia;
22

3-
import android.content.Context;
4-
import android.provider.Settings;
5-
import android.support.test.InstrumentationRegistry;
63
import android.support.test.runner.AndroidJUnit4;
7-
import android.util.Log;
84

9-
import org.junit.After;
105
import org.junit.Before;
11-
import org.junit.BeforeClass;
126
import org.junit.Test;
137
import org.junit.runner.RunWith;
148

15-
import java.util.ArrayList;
16-
179
import hestia.backend.Activator;
1810
import hestia.backend.ActivatorState;
19-
import hestia.backend.BackendInteractor;
20-
import hestia.backend.Device;
2111

2212
import static org.junit.Assert.*;
2313

2414
@RunWith(AndroidJUnit4.class)
2515
public class ActivatorAndActivatorStateTest {
26-
private static final int DEFAULT_ID = 0;
16+
private static final String DEFAULT_ID = "0";
2717
private static final String DEFAULT_NAME = "TEST_ACTIVATOR";
2818
private static ActivatorState<Float> floatActivatorState;
2919
private static ActivatorState<Boolean> boolActivatorState;
@@ -34,10 +24,10 @@ public class ActivatorAndActivatorStateTest {
3424
@Before
3525
public void setUp(){
3626
floatActivatorState = new ActivatorState<Float>(Float.valueOf("122"),"UNSIGNED_BYTE");
37-
testFloatActivator = new Activator(1,floatActivatorState,"TEST_SLIDER_255");
27+
testFloatActivator = new Activator("1",0,floatActivatorState,"TEST_SLIDER_255");
3828

3929
boolActivatorState = new ActivatorState<Boolean>(true,"TOGGLE");
40-
testBoolActivator = new Activator(1,boolActivatorState,"TEST_SWITCH");
30+
testBoolActivator = new Activator("1",0,boolActivatorState,"TEST_SWITCH");
4131
}
4232

4333
@Test
@@ -49,6 +39,22 @@ public void activatorStateTest(){
4939
boolean returnedBoolState = (boolean) boolActivatorState.getRawState();
5040
assertEquals(true,returnedBoolState);
5141
assertEquals("TOGGLE",boolActivatorState.getType());
42+
43+
// Testing rawState getters and setters
44+
boolean newBoolState = false;
45+
boolActivatorState.setRawState(newBoolState);
46+
assertEquals(newBoolState,boolActivatorState.getRawState());
47+
48+
float newFloatState = (float) 0.34578;
49+
floatActivatorState.setRawState(newFloatState);
50+
double allowedDelta = 0.00000005;
51+
assertEquals(newFloatState,floatActivatorState.getRawState(),allowedDelta);
52+
53+
// Testing type setter
54+
String typeString = "HESTIA_SWITCH";
55+
boolActivatorState.setType(typeString);
56+
assertEquals(typeString,boolActivatorState.getType());
57+
5258
}
5359

5460
@Test
@@ -57,4 +63,35 @@ public void activatorConstructorTest(){
5763
assertEquals(boolActivatorState,testBoolActivator.getState());
5864
}
5965

66+
@Test
67+
public void activatorGettersAndSettersTest(){
68+
// Testing getId, setId
69+
assertEquals("1",testBoolActivator.getId());
70+
testBoolActivator.setId("0");
71+
assertEquals(DEFAULT_ID,testBoolActivator.getId());
72+
assertNotEquals(DEFAULT_ID,testFloatActivator.getId());
73+
74+
// Testing setState
75+
assertNotEquals(boolActivatorState,testFloatActivator.getState());
76+
testFloatActivator.setState(boolActivatorState);
77+
assertEquals(boolActivatorState,testFloatActivator.getState());
78+
79+
// Testing getName, setName
80+
assertEquals("TEST_SWITCH",testBoolActivator.getName());
81+
testBoolActivator.setName(DEFAULT_NAME);
82+
assertEquals(DEFAULT_NAME,testBoolActivator.getName());
83+
}
84+
85+
@Test
86+
public void activatorEqualsAndHashTest(){
87+
// Testing hashCodes
88+
assertNotEquals(testBoolActivator.hashCode(),testFloatActivator.hashCode());
89+
assertEquals(testBoolActivator.hashCode(),testBoolActivator.hashCode());
90+
91+
// Testing equals method
92+
assertTrue(testBoolActivator.equals(testBoolActivator));
93+
assertFalse(testBoolActivator.equals(testFloatActivator));
94+
}
95+
96+
6097
}
Lines changed: 74 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.rugged.application.hestia;
22

33
import android.content.Context;
4-
import android.provider.Settings;
54
import android.support.test.InstrumentationRegistry;
65
import android.support.test.runner.AndroidJUnit4;
76
import android.util.Log;
@@ -11,38 +10,40 @@
1110
import org.junit.BeforeClass;
1211
import org.junit.Test;
1312
import org.junit.runner.RunWith;
14-
1513
import java.util.ArrayList;
16-
14+
import hestia.UI.DeviceListFragment;
1715
import hestia.backend.Activator;
1816
import hestia.backend.ActivatorState;
1917
import hestia.backend.BackendInteractor;
2018
import hestia.backend.Device;
21-
19+
import hestia.backend.DevicesChangeListener;
2220
import static org.junit.Assert.*;
2321

2422
@RunWith(AndroidJUnit4.class)
2523
public class BackendInteractorTest {
26-
private static final int TEST_DEVICE_ID = 0;
27-
private static final int TEST_ACTIVATOR_ID = 0;
24+
private static final String TEST_DEVICE_ID = "1";
25+
26+
private static final String TEST_ACTIVATOR_ID = "0";
2827
private String TAG = "ClientInteractionTest";
2928
private static BackendInteractor backendInteractor;
3029

3130
@BeforeClass
3231
public static void runBeforeTests(){
3332
backendInteractor = BackendInteractor.getInstance();
3433
ActivatorState<Boolean> testState = new ActivatorState<Boolean>(false,"TOGGLE");
35-
Activator testButton = new Activator(0,testState,"testButton");
34+
Activator testButton = new Activator("0",0,testState,"testButton");
3635
ArrayList<Activator> arr = new ArrayList<>();
3736
arr.add(testButton);
38-
Device testDevice = new Device(0,"testDevice", "testing",arr);
37+
Device testDevice = new Device("0","testDevice", "testing",arr);
3938
backendInteractor.addDevice(testDevice);
39+
4040
}
4141

4242
@Before
4343
public void addTestDevice(){
4444
ActivatorState<Boolean> testState = new ActivatorState<Boolean>(false,"TOGGLE");
45-
Activator testButton = new Activator(TEST_ACTIVATOR_ID,testState,"testButton");
45+
46+
Activator testButton = new Activator(TEST_ACTIVATOR_ID,0,testState,"testButton");
4647
ArrayList<Activator> arr = new ArrayList<>();
4748
arr.add(testButton);
4849
Device testDevice = new Device(TEST_DEVICE_ID,"testDevice", "testing",arr);
@@ -51,18 +52,17 @@ public void addTestDevice(){
5152

5253
@After
5354
public void removeTestDevice(){
54-
backendInteractor.deleteTestDevice(TEST_DEVICE_ID);
55+
backendInteractor.deleteTestDevice(Integer.parseInt(TEST_DEVICE_ID));
5556
}
5657

57-
5858
@Test
59-
public void testPackageName(){
59+
public void packageNameTest(){
6060
Context appContext = InstrumentationRegistry.getTargetContext();
6161
assertEquals("com.rugged.application.hestia", appContext.getPackageName());
6262
}
6363

6464
@Test
65-
public void testGetDevices(){
65+
public void getDevicesTest(){
6666
StringBuilder sb = new StringBuilder();
6767
for(Device d : backendInteractor.getDevices()){
6868
sb.append(d.toString());
@@ -73,26 +73,78 @@ public void testGetDevices(){
7373
/*
7474
* Test of the singleton reference, two different references should refer to the same object.
7575
*/
76+
7677
@Test
77-
public void testSingleton(){
78+
public void singletonTest(){
7879
BackendInteractor copyOfInteractor = BackendInteractor.getInstance();
7980
assertEquals(backendInteractor,copyOfInteractor);
8081
}
8182

83+
84+
@Test
85+
public void ipTest(){
86+
String testIp = "192.168.0.1";
87+
backendInteractor.setIp(testIp);
88+
assertEquals(testIp,backendInteractor.getIp());
89+
}
90+
8291
@Test
83-
public void testSetActivatorState(){
92+
public void setActivatorStateTest(){
8493
ArrayList<Device> testDeviceList = backendInteractor.getDevices();
85-
Device testDevice = testDeviceList.get(TEST_DEVICE_ID);
86-
ActivatorState state = testDevice.getActivator(TEST_ACTIVATOR_ID).getState();
94+
Device testDevice = testDeviceList.get(Integer.parseInt(TEST_DEVICE_ID));
95+
ActivatorState state = testDevice.getActivators().get(Integer.parseInt(TEST_ACTIVATOR_ID)).getState();
8796
boolean testState = (boolean)state.getRawState();
8897
assertEquals(testState,false);
89-
ActivatorState newState = new ActivatorState(true,"TOGGLE");
90-
backendInteractor.setActivatorState(TEST_DEVICE_ID,TEST_ACTIVATOR_ID,newState);
91-
testDeviceList = backendInteractor.getDevices();
92-
testDevice = testDeviceList.get(TEST_DEVICE_ID);
93-
assertEquals(testDevice.getActivator(TEST_ACTIVATOR_ID).getState().getRawState(),true);
98+
state.setRawState(true);
99+
100+
backendInteractor.setActivatorState(testDevice,testDevice.getActivators().get(Integer.parseInt(TEST_ACTIVATOR_ID)),state);
101+
102+
Activator activator = backendInteractor.getDevices().get(Integer.parseInt(TEST_DEVICE_ID)).getActivators().get(Integer.parseInt(TEST_ACTIVATOR_ID));
103+
assertEquals(true,activator.getState().getRawState());
94104
}
95105

106+
@Test
107+
public void deleteDeviceTest(){
108+
Device temp = backendInteractor.getDevices().get(Integer.parseInt(TEST_DEVICE_ID));
109+
110+
// Removing a device
111+
backendInteractor.deleteDevice(temp);
112+
backendInteractor.clearDevices();
113+
114+
// The list should be empty, updating should leave it empty
115+
backendInteractor.updateDevices();
116+
assertTrue(backendInteractor.getDevices().isEmpty());
96117

118+
// Now adding a device, trying the same device twice
119+
backendInteractor.addDevice(temp);
120+
backendInteractor.addDevice(temp);
121+
assertEquals(2,backendInteractor.getDevices().size());
97122

123+
}
124+
125+
@Test
126+
public void setDevicesTest(){
127+
Device temp = backendInteractor.getDevices().get(Integer.parseInt(TEST_DEVICE_ID));
128+
ArrayList<Device> newDevices = new ArrayList<>();
129+
// Adding the same device three times
130+
newDevices.add(temp);
131+
newDevices.add(temp);
132+
newDevices.add(temp);
133+
134+
backendInteractor.setDevices(newDevices);
135+
assertEquals(3,backendInteractor.getDevices().size());
136+
}
137+
138+
@Test
139+
public void listenerTest(){
140+
DevicesChangeListener l = new DeviceListFragment();
141+
142+
// Testing adding a listener
143+
backendInteractor.addDevicesChangeListener(l);
144+
assertEquals(l,backendInteractor.getListeners().get(0));
145+
146+
// Testing removing a listener
147+
backendInteractor.removeDevicesChangeListener(l);
148+
assertEquals(0,backendInteractor.getListeners().size());
149+
}
98150
}

0 commit comments

Comments
 (0)