Skip to content

Commit

Permalink
Merge pull request #98 from RUGSoftEng/release-0.5
Browse files Browse the repository at this point in the history
Release 0.5
  • Loading branch information
Luc van den Brand authored May 16, 2017
2 parents fb9387a + 90f9308 commit 0c2dca5
Show file tree
Hide file tree
Showing 85 changed files with 1,499 additions and 1,424 deletions.
Binary file added .gradle/3.3/taskArtifacts/fileSnapshots.bin
Binary file not shown.
Binary file added .gradle/3.3/taskArtifacts/taskArtifacts.bin
Binary file not shown.
Binary file added .gradle/3.3/taskArtifacts/taskArtifacts.lock
Binary file not shown.
47 changes: 45 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
sudo: false

language: android
jdk: oraclejdk8
android:
components:
# Auxiliary tools which have to be installed
- tools
- tools # see https://github.com/travis-ci/travis-ci/issues/6040#issuecomment-219367943
- platform-tools

# The BuildTools version used
- build-tools-19.1.0
- build-tools-25.0.3

# The SDK version used to compile the project
- android-25
- android-22

# Additional components
Expand All @@ -17,5 +26,39 @@ android:
- sys-img-armeabi-v7a-android-22
- sys-img-armeabi-v7a-android-17

before_install:
# copy the licenses to the correct file on the Travis system
- pip install --user codecov #Install codecov
- cp -r licenses/ /usr/local/android-sdk/licenses/
- cd Hestia

install:
- bash gradlew tasks --all --stacktrace --info

before_script:
- android update sdk --no-ui --filter build-tools-25.0.3,android-25,extra-android-m2repository
# Start emulator
- echo no | android create avd --force -n test -t android-22 --abi armeabi-v7a
- emulator -avd test -no-audio -no-window &
- android-wait-for-emulator
- adb shell input keyevent 82 &

script:
- bash Hestia/gradlew tasks --all
- bash gradlew app:connectedCheck
- bash gradlew app:createDebugCoverageReport

after_failure:
# Prints any linting errors after failing
- cat $TRAVIS_BUILD_DIR/app/build/outputs/lint-results-debug.xml

after_success:
- codecov
- sh set_tags.sh

before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/
cache:
directories:
- $HOME/.gradle/caches/
- $HOME/.gradle/wrapper/
14 changes: 13 additions & 1 deletion Hestia/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "com.rugged.application.hestia"
minSdkVersion 15
Expand All @@ -17,14 +17,26 @@ android {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug{
testCoverageEnabled = true
}
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile ('com.android.support.test.espresso:espresso-intents:2.2.2', {
exclude group: 'com.android.support',module: 'support-annotations'
})
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
androidTestCompile ('com.android.support.test:runner:0.5', {
exclude group: 'com.android.support',module: 'support-annotations'
})
androidTestCompile ('com.android.support.test:rules:0.5', {
exclude group: 'com.android.support',module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
testCompile 'junit:junit:4.12'
compile 'com.android.support:recyclerview-v7:25.3.1'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,19 @@
package com.rugged.application.hestia;

import android.content.Context;
import android.provider.Settings;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import android.util.Log;

import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.ArrayList;

import hestia.backend.Activator;
import hestia.backend.ActivatorState;
import hestia.backend.BackendInteractor;
import hestia.backend.Device;

import static org.junit.Assert.*;

@RunWith(AndroidJUnit4.class)
public class ActivatorAndActivatorStateTest {
private static final int DEFAULT_ID = 0;
private static final String DEFAULT_ID = "0";
private static final String DEFAULT_NAME = "TEST_ACTIVATOR";
private static ActivatorState<Float> floatActivatorState;
private static ActivatorState<Boolean> boolActivatorState;
Expand All @@ -34,10 +24,10 @@ public class ActivatorAndActivatorStateTest {
@Before
public void setUp(){
floatActivatorState = new ActivatorState<Float>(Float.valueOf("122"),"UNSIGNED_BYTE");
testFloatActivator = new Activator(1,floatActivatorState,"TEST_SLIDER_255");
testFloatActivator = new Activator("1",0,floatActivatorState,"TEST_SLIDER_255");

boolActivatorState = new ActivatorState<Boolean>(true,"TOGGLE");
testBoolActivator = new Activator(1,boolActivatorState,"TEST_SWITCH");
testBoolActivator = new Activator("1",0,boolActivatorState,"TEST_SWITCH");
}

@Test
Expand All @@ -49,6 +39,22 @@ public void activatorStateTest(){
boolean returnedBoolState = (boolean) boolActivatorState.getRawState();
assertEquals(true,returnedBoolState);
assertEquals("TOGGLE",boolActivatorState.getType());

// Testing rawState getters and setters
boolean newBoolState = false;
boolActivatorState.setRawState(newBoolState);
assertEquals(newBoolState,boolActivatorState.getRawState());

float newFloatState = (float) 0.34578;
floatActivatorState.setRawState(newFloatState);
double allowedDelta = 0.00000005;
assertEquals(newFloatState,floatActivatorState.getRawState(),allowedDelta);

// Testing type setter
String typeString = "HESTIA_SWITCH";
boolActivatorState.setType(typeString);
assertEquals(typeString,boolActivatorState.getType());

}

@Test
Expand All @@ -57,4 +63,35 @@ public void activatorConstructorTest(){
assertEquals(boolActivatorState,testBoolActivator.getState());
}

@Test
public void activatorGettersAndSettersTest(){
// Testing getId, setId
assertEquals("1",testBoolActivator.getId());
testBoolActivator.setId("0");
assertEquals(DEFAULT_ID,testBoolActivator.getId());
assertNotEquals(DEFAULT_ID,testFloatActivator.getId());

// Testing setState
assertNotEquals(boolActivatorState,testFloatActivator.getState());
testFloatActivator.setState(boolActivatorState);
assertEquals(boolActivatorState,testFloatActivator.getState());

// Testing getName, setName
assertEquals("TEST_SWITCH",testBoolActivator.getName());
testBoolActivator.setName(DEFAULT_NAME);
assertEquals(DEFAULT_NAME,testBoolActivator.getName());
}

@Test
public void activatorEqualsAndHashTest(){
// Testing hashCodes
assertNotEquals(testBoolActivator.hashCode(),testFloatActivator.hashCode());
assertEquals(testBoolActivator.hashCode(),testBoolActivator.hashCode());

// Testing equals method
assertTrue(testBoolActivator.equals(testBoolActivator));
assertFalse(testBoolActivator.equals(testFloatActivator));
}


}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.rugged.application.hestia;

import android.content.Context;
import android.provider.Settings;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import android.util.Log;
Expand All @@ -11,38 +10,40 @@
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.ArrayList;

import hestia.UI.DeviceListFragment;
import hestia.backend.Activator;
import hestia.backend.ActivatorState;
import hestia.backend.BackendInteractor;
import hestia.backend.Device;

import hestia.backend.DevicesChangeListener;
import static org.junit.Assert.*;

@RunWith(AndroidJUnit4.class)
public class BackendInteractorTest {
private static final int TEST_DEVICE_ID = 0;
private static final int TEST_ACTIVATOR_ID = 0;
private static final String TEST_DEVICE_ID = "1";

private static final String TEST_ACTIVATOR_ID = "0";
private String TAG = "ClientInteractionTest";
private static BackendInteractor backendInteractor;

@BeforeClass
public static void runBeforeTests(){
backendInteractor = BackendInteractor.getInstance();
ActivatorState<Boolean> testState = new ActivatorState<Boolean>(false,"TOGGLE");
Activator testButton = new Activator(0,testState,"testButton");
Activator testButton = new Activator("0",0,testState,"testButton");
ArrayList<Activator> arr = new ArrayList<>();
arr.add(testButton);
Device testDevice = new Device(0,"testDevice", "testing",arr);
Device testDevice = new Device("0","testDevice", "testing",arr);
backendInteractor.addDevice(testDevice);

}

@Before
public void addTestDevice(){
ActivatorState<Boolean> testState = new ActivatorState<Boolean>(false,"TOGGLE");
Activator testButton = new Activator(TEST_ACTIVATOR_ID,testState,"testButton");

Activator testButton = new Activator(TEST_ACTIVATOR_ID,0,testState,"testButton");
ArrayList<Activator> arr = new ArrayList<>();
arr.add(testButton);
Device testDevice = new Device(TEST_DEVICE_ID,"testDevice", "testing",arr);
Expand All @@ -51,18 +52,17 @@ public void addTestDevice(){

@After
public void removeTestDevice(){
backendInteractor.deleteTestDevice(TEST_DEVICE_ID);
backendInteractor.deleteTestDevice(Integer.parseInt(TEST_DEVICE_ID));
}


@Test
public void testPackageName(){
public void packageNameTest(){
Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("com.rugged.application.hestia", appContext.getPackageName());
}

@Test
public void testGetDevices(){
public void getDevicesTest(){
StringBuilder sb = new StringBuilder();
for(Device d : backendInteractor.getDevices()){
sb.append(d.toString());
Expand All @@ -73,26 +73,78 @@ public void testGetDevices(){
/*
* Test of the singleton reference, two different references should refer to the same object.
*/

@Test
public void testSingleton(){
public void singletonTest(){
BackendInteractor copyOfInteractor = BackendInteractor.getInstance();
assertEquals(backendInteractor,copyOfInteractor);
}


@Test
public void ipTest(){
String testIp = "192.168.0.1";
backendInteractor.setIp(testIp);
assertEquals(testIp,backendInteractor.getIp());
}

@Test
public void testSetActivatorState(){
public void setActivatorStateTest(){
ArrayList<Device> testDeviceList = backendInteractor.getDevices();
Device testDevice = testDeviceList.get(TEST_DEVICE_ID);
ActivatorState state = testDevice.getActivator(TEST_ACTIVATOR_ID).getState();
Device testDevice = testDeviceList.get(Integer.parseInt(TEST_DEVICE_ID));
ActivatorState state = testDevice.getActivators().get(Integer.parseInt(TEST_ACTIVATOR_ID)).getState();
boolean testState = (boolean)state.getRawState();
assertEquals(testState,false);
ActivatorState newState = new ActivatorState(true,"TOGGLE");
backendInteractor.setActivatorState(TEST_DEVICE_ID,TEST_ACTIVATOR_ID,newState);
testDeviceList = backendInteractor.getDevices();
testDevice = testDeviceList.get(TEST_DEVICE_ID);
assertEquals(testDevice.getActivator(TEST_ACTIVATOR_ID).getState().getRawState(),true);
state.setRawState(true);

backendInteractor.setActivatorState(testDevice,testDevice.getActivators().get(Integer.parseInt(TEST_ACTIVATOR_ID)),state);

Activator activator = backendInteractor.getDevices().get(Integer.parseInt(TEST_DEVICE_ID)).getActivators().get(Integer.parseInt(TEST_ACTIVATOR_ID));
assertEquals(true,activator.getState().getRawState());
}

@Test
public void deleteDeviceTest(){
Device temp = backendInteractor.getDevices().get(Integer.parseInt(TEST_DEVICE_ID));

// Removing a device
backendInteractor.deleteDevice(temp);
backendInteractor.clearDevices();

// The list should be empty, updating should leave it empty
backendInteractor.updateDevices();
assertTrue(backendInteractor.getDevices().isEmpty());

// Now adding a device, trying the same device twice
backendInteractor.addDevice(temp);
backendInteractor.addDevice(temp);
assertEquals(2,backendInteractor.getDevices().size());

}

@Test
public void setDevicesTest(){
Device temp = backendInteractor.getDevices().get(Integer.parseInt(TEST_DEVICE_ID));
ArrayList<Device> newDevices = new ArrayList<>();
// Adding the same device three times
newDevices.add(temp);
newDevices.add(temp);
newDevices.add(temp);

backendInteractor.setDevices(newDevices);
assertEquals(3,backendInteractor.getDevices().size());
}

@Test
public void listenerTest(){
DevicesChangeListener l = new DeviceListFragment();

// Testing adding a listener
backendInteractor.addDevicesChangeListener(l);
assertEquals(l,backendInteractor.getListeners().get(0));

// Testing removing a listener
backendInteractor.removeDevicesChangeListener(l);
assertEquals(0,backendInteractor.getListeners().size());
}
}
Loading

0 comments on commit 0c2dca5

Please sign in to comment.