diff --git a/.circleci/config.yml b/.circleci/config.yml
index 99aa7624b..4e09c3922 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -7,7 +7,7 @@ references:
container_config: &container_config
docker:
- - image: circleci/android:api-25-alpha
+ - image: circleci/android:api-26-alpha
working_directory: *workspace_root
environment:
environment:
@@ -33,7 +33,7 @@ jobs:
command: ./gradlew --no-daemon --stacktrace dependencies || true
- run:
name: Initial build
- command: ./gradlew --no-daemon --stacktrace assembleDebug
+ command: ./gradlew --no-daemon --stacktrace assembleDebug -PdisablePreDex
- store_artifacts:
path: ./app/build/outputs/apk/
destination: apks/
@@ -58,6 +58,8 @@ jobs:
- store_artifacts:
path: ./app/build/reports/
destination: lint_reports/app/
+ - store_test_results:
+ path: ./app/build/reports/
test:
<<: *container_config
@@ -69,8 +71,10 @@ jobs:
name: Run Tests
command: ./gradlew --no-daemon --stacktrace test
- run:
- name: Upload code coverage to codecov
- command: ./gradlew --no-daemon --stacktrace jacocoTestReport && bash <(curl -s https://codecov.io/bash)
+ name: Upload unit code coverage to codecov
+ command: |
+ ./gradlew --no-daemon --stacktrace jacocoTestReport
+ bash <(curl -s https://codecov.io/bash) -F unit
- run:
name: Upload code coverage to codacy
command: ./gradlew --no-daemon --stacktrace codacyUpload
@@ -83,6 +87,43 @@ jobs:
- store_test_results:
path: ./app/build/test-results
+ instrumented:
+ <<: *container_config
+ steps:
+ - *attach_workspace
+ - run:
+ name: Setup emulator
+ command: sdkmanager "system-images;android-19;google_apis;armeabi-v7a" && echo "no" | avdmanager create avd -n test -k "system-images;android-19;google_apis;armeabi-v7a"
+ - run:
+ name: Launch emulator
+ command: export LD_LIBRARY_PATH=${ANDROID_HOME}/emulator/lib64:${ANDROID_HOME}/emulator/lib64/qt/lib && emulator64-arm -avd test -noaudio -no-boot-anim -no-window -accel on
+ background: true
+ - run:
+ name: Wait emulator
+ command: |
+ # wait for it to have booted
+ circle-android wait-for-boot
+ # unlock the emulator screen
+ sleep 30
+ adb shell input keyevent 82
+ - run:
+ name: Clean project
+ command: ./gradlew clean --no-daemon --stacktrace --console=plain -PdisablePreDex
+ - run:
+ name: Run instrumented tests
+ command: ./gradlew connectedAndroidTest --no-daemon --stacktrace --console=plain -PdisablePreDex
+ - run:
+ name: Collect logs from emulator
+ command: adb logcat -d > ./app/build/reports/logcat_emulator.txt
+ - run:
+ name: Upload code covarage to codecov
+ command: bash <(curl -s https://codecov.io/bash) -F instrumented
+ - store_artifacts:
+ path: ./app/build/reports
+ destination: reports
+ - store_test_results:
+ path: ./app/build/outputs/androidTest-results/connected/
+
workflows:
version: 2
@@ -95,3 +136,6 @@ workflows:
- test:
requires:
- build
+ - instrumented:
+ requires:
+ - build
diff --git a/.codecov.yml b/.codecov.yml
new file mode 100644
index 000000000..44d53a1f2
--- /dev/null
+++ b/.codecov.yml
@@ -0,0 +1,19 @@
+coverage:
+ range: 60..100
+ status:
+ project:
+ default: off
+ unit:
+ target: 20%
+ flags: unit
+ instrumented:
+ target: 20%
+ flags: instrumented
+
+flags:
+ unit:
+ paths:
+ - app/src/main/io/github/wulkanowy
+ instrumented:
+ paths:
+ - app/src/main/io/github/wulkanowy
diff --git a/app/build.gradle b/app/build.gradle
index bbd40a295..8f0c1429f 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -9,7 +9,7 @@ android {
defaultConfig {
applicationId "io.github.wulkanowy"
testApplicationId "io.github.tests.wulkanowy"
- minSdkVersion 14
+ minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "0.1.0"
@@ -26,6 +26,16 @@ android {
ext.enableCrashlytics = false
}
}
+
+ testOptions {
+ unitTests.all {
+ testLogging {
+ events "passed", "skipped", "failed", "standardOut", "standardError"
+ outputs.upToDateWhen {false}
+ showStandardStreams = true
+ }
+ }
+ }
}
greendao {
@@ -35,9 +45,7 @@ greendao {
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
- androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
- exclude group: 'com.android.support', module: 'support-annotations'
- })
+
compile 'com.android.support:appcompat-v7:26.0.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:design:26.0.1'
@@ -45,7 +53,6 @@ dependencies {
compile 'com.android.support:support-v4:26.0.1'
compile 'com.android.support:recyclerview-v7:26.0.1'
compile 'com.android.support:cardview-v7:26.0.1'
- compile 'com.google.code.gson:gson:2.8.1'
compile 'com.firebase:firebase-jobdispatcher:0.8.1'
compile 'com.thoughtbot:expandablerecyclerview:1.3'
compile 'org.apache.commons:commons-lang3:3.6'
@@ -60,4 +67,12 @@ dependencies {
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:2.10.0'
+
+ androidTestCompile('com.android.support.test.espresso:espresso-core:3.0.1', {
+ exclude group: 'com.android.support', module: 'support-annotations'
+ })
+ androidTestCompile 'com.android.support:support-annotations:26.0.1'
+ androidTestCompile 'com.android.support.test:runner:1.0.1'
+ androidTestCompile 'com.android.support.test:rules:1.0.1'
+ androidTestCompile 'org.hamcrest:hamcrest-library:1.3'
}
diff --git a/app/src/androidTest/java/io/github/wulkanowy/ExampleInstrumentedTest.java b/app/src/androidTest/java/io/github/wulkanowy/ExampleInstrumentedTest.java
deleted file mode 100644
index 6eb4e14fc..000000000
--- a/app/src/androidTest/java/io/github/wulkanowy/ExampleInstrumentedTest.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package io.github.wulkanowy;
-
-import static org.junit.Assert.assertEquals;
-
-import android.content.Context;
-import android.support.test.InstrumentationRegistry;
-import android.support.test.runner.AndroidJUnit4;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-/**
- * Instrumentation test, which will execute on an Android device.
- *
- * @see Testing documentation
- */
-@RunWith(AndroidJUnit4.class)
-public class ExampleInstrumentedTest {
- @Test
- public void useAppContext() throws Exception {
- // Context of the app under test.
- Context appContext = InstrumentationRegistry.getTargetContext();
-
- assertEquals("io.github.wulkanowy", appContext.getPackageName());
- }
-}
diff --git a/app/src/androidTest/java/io/github/wulkanowy/dao/entities/AccountTest.java b/app/src/androidTest/java/io/github/wulkanowy/dao/entities/AccountTest.java
index 4b9ddc5aa..c943a560b 100644
--- a/app/src/androidTest/java/io/github/wulkanowy/dao/entities/AccountTest.java
+++ b/app/src/androidTest/java/io/github/wulkanowy/dao/entities/AccountTest.java
@@ -1,7 +1,10 @@
package io.github.wulkanowy.dao.entities;
+import android.support.test.filters.SmallTest;
+
import org.greenrobot.greendao.test.AbstractDaoTestLongPk;
+@SmallTest
public class AccountTest extends AbstractDaoTestLongPk {
public AccountTest() {
diff --git a/app/src/androidTest/java/io/github/wulkanowy/dao/entities/GradeTest.java b/app/src/androidTest/java/io/github/wulkanowy/dao/entities/GradeTest.java
index 31d30c977..70f12510f 100644
--- a/app/src/androidTest/java/io/github/wulkanowy/dao/entities/GradeTest.java
+++ b/app/src/androidTest/java/io/github/wulkanowy/dao/entities/GradeTest.java
@@ -1,7 +1,10 @@
package io.github.wulkanowy.dao.entities;
+import android.support.test.filters.SmallTest;
+
import org.greenrobot.greendao.test.AbstractDaoTestLongPk;
+@SmallTest
public class GradeTest extends AbstractDaoTestLongPk {
public GradeTest() {
diff --git a/app/src/androidTest/java/io/github/wulkanowy/dao/entities/SubjectTest.java b/app/src/androidTest/java/io/github/wulkanowy/dao/entities/SubjectTest.java
index 9d2464edf..59c9da45f 100644
--- a/app/src/androidTest/java/io/github/wulkanowy/dao/entities/SubjectTest.java
+++ b/app/src/androidTest/java/io/github/wulkanowy/dao/entities/SubjectTest.java
@@ -1,7 +1,10 @@
package io.github.wulkanowy.dao.entities;
+import android.support.test.filters.SmallTest;
+
import org.greenrobot.greendao.test.AbstractDaoTestLongPk;
+@SmallTest
public class SubjectTest extends AbstractDaoTestLongPk {
public SubjectTest() {
diff --git a/app/src/androidTest/java/io/github/wulkanowy/security/SafetyTest.java b/app/src/androidTest/java/io/github/wulkanowy/security/SafetyTest.java
new file mode 100644
index 000000000..63d268a35
--- /dev/null
+++ b/app/src/androidTest/java/io/github/wulkanowy/security/SafetyTest.java
@@ -0,0 +1,25 @@
+package io.github.wulkanowy.security;
+
+import android.content.Context;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.filters.SdkSuppress;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class SafetyTest {
+
+ @Test
+ @SdkSuppress(minSdkVersion = 18)
+ public void encryptDecryptTest() throws Exception {
+ Context targetContext = InstrumentationRegistry.getTargetContext();
+
+ Safety safety = new Safety();
+ Assert.assertEquals("PASS", safety.decrypt("TEST", safety.encrypt("TEST", "PASS", targetContext)));
+ }
+}
diff --git a/app/src/androidTest/java/io/github/wulkanowy/security/ScramblerTest.java b/app/src/androidTest/java/io/github/wulkanowy/security/ScramblerTest.java
new file mode 100644
index 000000000..0b7e5b5c1
--- /dev/null
+++ b/app/src/androidTest/java/io/github/wulkanowy/security/ScramblerTest.java
@@ -0,0 +1,59 @@
+package io.github.wulkanowy.security;
+
+import android.content.Context;
+import android.os.Build;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.filters.SdkSuppress;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@SmallTest
+@SdkSuppress(minSdkVersion = 18)
+@RunWith(AndroidJUnit4.class)
+public class ScramblerTest {
+
+ private Context targetContext;
+
+ private Scrambler scramblerLoad = new Scrambler();
+
+ @Before
+ public void setUp() throws CryptoException {
+ targetContext = InstrumentationRegistry.getTargetContext();
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
+ scramblerLoad.loadKeyStore();
+ }
+ }
+
+ @Test(expected = CryptoException.class)
+ @SdkSuppress(maxSdkVersion = 17)
+ public void testNoSuchAlgorithm() throws CryptoException {
+ scramblerLoad.loadKeyStore();
+ }
+
+ @Test
+ public void decryptEncryptStringTest() throws CryptoException {
+ scramblerLoad.generateNewKey("TEST", targetContext);
+ Assert.assertEquals("pass",
+ scramblerLoad.decryptString("TEST", scramblerLoad.encryptString("TEST", "pass")));
+ }
+
+ @Test(expected = CryptoException.class)
+ public void decryptEmptyTest() throws CryptoException {
+ scramblerLoad.decryptString("", "");
+ }
+
+ @Test(expected = CryptoException.class)
+ public void encryptEmptyTest() throws CryptoException {
+ scramblerLoad.encryptString("", "");
+ }
+
+ @Test(expected = CryptoException.class)
+ public void generateNewKeyEmptyTest() throws CryptoException {
+ scramblerLoad.generateNewKey("", targetContext);
+ }
+}
diff --git a/app/src/androidTest/java/io/github/wulkanowy/services/synchronization/AccountSynchronizationTest.java b/app/src/androidTest/java/io/github/wulkanowy/services/synchronization/AccountSynchronizationTest.java
index 754da85b6..d070aee47 100644
--- a/app/src/androidTest/java/io/github/wulkanowy/services/synchronization/AccountSynchronizationTest.java
+++ b/app/src/androidTest/java/io/github/wulkanowy/services/synchronization/AccountSynchronizationTest.java
@@ -72,11 +72,11 @@ public class AccountSynchronizationTest {
public void loginCurrentUserTest() throws Exception {
AccountDao accountDao = daoSession.getAccountDao();
- Safety safety = new Safety(context);
+ Safety safety = new Safety();
Long userId = accountDao.insert(new Account()
.setEmail("TEST@TEST")
- .setPassword(safety.encrypt("TEST@TEST", "TEST"))
+ .setPassword(safety.encrypt("TEST@TEST", "TEST", context))
.setSymbol(""));
setUserIdSharePreferences(userId);
@@ -117,7 +117,7 @@ public class AccountSynchronizationTest {
Assert.assertNotNull(loginSession.getDaoSession());
Assert.assertEquals(loginSession.getVulcan(), vulcan);
- Safety safety = new Safety(context);
+ Safety safety = new Safety();
Account account = daoSession.getAccountDao().load(userId);
Assert.assertNotNull(account);
diff --git a/app/src/main/java/io/github/wulkanowy/activity/dashboard/DashboardActivity.java b/app/src/main/java/io/github/wulkanowy/activity/dashboard/DashboardActivity.java
index a91af4615..926927c97 100644
--- a/app/src/main/java/io/github/wulkanowy/activity/dashboard/DashboardActivity.java
+++ b/app/src/main/java/io/github/wulkanowy/activity/dashboard/DashboardActivity.java
@@ -72,7 +72,7 @@ public class DashboardActivity extends AppCompatActivity {
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
getSupportFragmentManager().beginTransaction()
- .add(R.id.fragment_container, boardFragment).commit();
+ .replace(R.id.fragment_container, boardFragment).commit();
}
public void onBackPressed() {
diff --git a/app/src/main/java/io/github/wulkanowy/activity/dashboard/grades/GradesDialogFragment.java b/app/src/main/java/io/github/wulkanowy/activity/dashboard/grades/GradesDialogFragment.java
index 95c987546..c50ce156a 100644
--- a/app/src/main/java/io/github/wulkanowy/activity/dashboard/grades/GradesDialogFragment.java
+++ b/app/src/main/java/io/github/wulkanowy/activity/dashboard/grades/GradesDialogFragment.java
@@ -44,17 +44,17 @@ public class GradesDialogFragment extends DialogFragment {
dateText.setText(grade.getDate());
colorText.setText(colorHexToColorName(grade.getColor()));
- if (grade.getDescription().equals("")) {
- if (!grade.getSymbol().equals("")) {
+ if ("".equals(grade.getDescription())) {
+ if (!"".equals(grade.getSymbol())) {
descriptionText.setText(grade.getSymbol());
}
- } else if (!grade.getSymbol().equals("")) {
+ } else if (!"".equals(grade.getSymbol())) {
descriptionText.setText(grade.getSymbol() + " - " + grade.getDescription());
} else {
descriptionText.setText(grade.getDescription());
}
- if (!grade.getTeacher().equals("")) {
+ if (!"".equals(grade.getTeacher())) {
teacherText.setText(grade.getTeacher());
}
@@ -68,7 +68,7 @@ public class GradesDialogFragment extends DialogFragment {
return view;
}
- public int colorHexToColorName(String hexColor) {
+ public static int colorHexToColorName(String hexColor) {
switch (hexColor) {
case "000000": {
return R.string.color_black_text;
diff --git a/app/src/main/java/io/github/wulkanowy/activity/dashboard/grades/GradesFragment.java b/app/src/main/java/io/github/wulkanowy/activity/dashboard/grades/GradesFragment.java
index 618344f48..2286daed1 100644
--- a/app/src/main/java/io/github/wulkanowy/activity/dashboard/grades/GradesFragment.java
+++ b/app/src/main/java/io/github/wulkanowy/activity/dashboard/grades/GradesFragment.java
@@ -35,7 +35,8 @@ public class GradesFragment extends Fragment {
DaoSession daoSession = ((WulkanowyApp) getActivity().getApplication()).getDaoSession();
- if (subjectWithGradesList.equals(new ArrayList<>())) {
+ if (new ArrayList<>().equals(subjectWithGradesList)) {
+ createExpListView();
new GradesTask(daoSession).execute();
} else if (subjectWithGradesList.size() > 0) {
createExpListView();
@@ -45,7 +46,7 @@ public class GradesFragment extends Fragment {
return view;
}
- public void createExpListView() {
+ private void createExpListView() {
RecyclerView recyclerView = view.findViewById(R.id.subject_grade_recycler);
recyclerView.setLayoutManager(new LinearLayoutManager(view.getContext()));
diff --git a/app/src/main/java/io/github/wulkanowy/dao/EntitiesCompare.java b/app/src/main/java/io/github/wulkanowy/dao/EntitiesCompare.java
index b368c6076..c79b11450 100644
--- a/app/src/main/java/io/github/wulkanowy/dao/EntitiesCompare.java
+++ b/app/src/main/java/io/github/wulkanowy/dao/EntitiesCompare.java
@@ -7,7 +7,7 @@ import java.util.List;
import io.github.wulkanowy.dao.entities.Grade;
-public class EntitiesCompare {
+public abstract class EntitiesCompare {
public static List compareGradeList(List newList, List oldList) {
diff --git a/app/src/main/java/io/github/wulkanowy/security/Safety.java b/app/src/main/java/io/github/wulkanowy/security/Safety.java
index 116a8f986..4bc329ba1 100644
--- a/app/src/main/java/io/github/wulkanowy/security/Safety.java
+++ b/app/src/main/java/io/github/wulkanowy/security/Safety.java
@@ -9,16 +9,12 @@ import io.github.wulkanowy.utilities.RootUtilities;
public class Safety extends Scrambler {
- public Safety(Context context) {
- super(context);
- }
-
- public String encrypt(String email, String plainText) throws CryptoException, UnsupportedOperationException {
+ public String encrypt(String email, String plainText, Context context) throws CryptoException, UnsupportedOperationException {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
loadKeyStore();
- generateNewKey(email);
+ generateNewKey(email, context);
return encryptString(email, plainText);
} else {
diff --git a/app/src/main/java/io/github/wulkanowy/security/Scrambler.java b/app/src/main/java/io/github/wulkanowy/security/Scrambler.java
index ae3cd7f5a..bf4b0257c 100644
--- a/app/src/main/java/io/github/wulkanowy/security/Scrambler.java
+++ b/app/src/main/java/io/github/wulkanowy/security/Scrambler.java
@@ -29,19 +29,14 @@ import javax.security.auth.x500.X500Principal;
public class Scrambler {
- public final static String DEBUG_TAG = "WulkanowySecurity";
private static final String ANDROID_KEYSTORE = "AndroidKeyStore";
- protected Context context;
+ public final static String DEBUG_TAG = "WulkanowySecurity";
private KeyStore keyStore;
- protected Scrambler(Context context) {
- this.context = context;
- }
-
- protected void loadKeyStore() throws CryptoException {
+ public void loadKeyStore() throws CryptoException {
try {
keyStore = KeyStore.getInstance(ANDROID_KEYSTORE);
@@ -54,7 +49,7 @@ public class Scrambler {
}
@TargetApi(18)
- protected void generateNewKey(String alias) throws CryptoException {
+ protected void generateNewKey(String alias, Context context) throws CryptoException {
Calendar start = Calendar.getInstance();
Calendar end = Calendar.getInstance();
@@ -62,7 +57,7 @@ public class Scrambler {
AlgorithmParameterSpec spec;
end.add(Calendar.YEAR, 10);
- if (!alias.isEmpty()) {
+ if (!"".equals(alias)) {
try {
if (!keyStore.containsAlias(alias)) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
diff --git a/app/src/main/java/io/github/wulkanowy/services/synchronisation/AccountSynchronisation.java b/app/src/main/java/io/github/wulkanowy/services/synchronisation/AccountSynchronisation.java
index 967c62d49..04cd98024 100644
--- a/app/src/main/java/io/github/wulkanowy/services/synchronisation/AccountSynchronisation.java
+++ b/app/src/main/java/io/github/wulkanowy/services/synchronisation/AccountSynchronisation.java
@@ -33,7 +33,7 @@ public class AccountSynchronisation {
Log.d(VulcanSync.DEBUG_TAG, "Login current user id=" + String.valueOf(userId));
- Safety safety = new Safety(context);
+ Safety safety = new Safety();
Account account = accountDao.load(userId);
vulcan.login(
account.getEmail(),
@@ -60,12 +60,12 @@ public class AccountSynchronisation {
PersonalData personalData = vulcan.getBasicInformation().getPersonalData();
AccountDao accountDao = daoSession.getAccountDao();
- Safety safety = new Safety(context);
+ Safety safety = new Safety();
Account account = new Account()
.setName(personalData.getFirstAndLastName())
.setEmail(email)
- .setPassword(safety.encrypt(email, password))
+ .setPassword(safety.encrypt(email, password, context))
.setSymbol(symbol);
userId = accountDao.insert(account);
diff --git a/app/src/main/java/io/github/wulkanowy/services/synchronisation/VulcanSynchronisation.java b/app/src/main/java/io/github/wulkanowy/services/synchronisation/VulcanSynchronisation.java
new file mode 100644
index 000000000..e69de29bb
diff --git a/app/src/main/java/io/github/wulkanowy/utilities/ConversionVulcanObject.java b/app/src/main/java/io/github/wulkanowy/utilities/ConversionVulcanObject.java
index 707454ba7..72601d051 100644
--- a/app/src/main/java/io/github/wulkanowy/utilities/ConversionVulcanObject.java
+++ b/app/src/main/java/io/github/wulkanowy/utilities/ConversionVulcanObject.java
@@ -1,7 +1,6 @@
package io.github.wulkanowy.utilities;
-import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
@@ -25,7 +24,7 @@ public abstract class ConversionVulcanObject {
return subjectEntityList;
}
- public static List gradesToGradeEntities(List gradeList) throws ParseException {
+ public static List gradesToGradeEntities(List gradeList) {
List gradeEntityList = new ArrayList<>();
diff --git a/app/src/test/java/io/github/wulkanowy/activity/dashboard/grades/GradesDialogFragmentTest.java b/app/src/test/java/io/github/wulkanowy/activity/dashboard/grades/GradesDialogFragmentTest.java
new file mode 100644
index 000000000..55b313b1b
--- /dev/null
+++ b/app/src/test/java/io/github/wulkanowy/activity/dashboard/grades/GradesDialogFragmentTest.java
@@ -0,0 +1,22 @@
+package io.github.wulkanowy.activity.dashboard.grades;
+
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import io.github.wulkanowy.R;
+
+import static io.github.wulkanowy.activity.dashboard.grades.GradesDialogFragment.colorHexToColorName;
+
+public class GradesDialogFragmentTest {
+
+ @Test
+ public void colorHexToColorNameTest() {
+ Assert.assertEquals(R.string.color_black_text, colorHexToColorName("000000"));
+ Assert.assertEquals(R.string.color_red_text, colorHexToColorName("F04C4C"));
+ Assert.assertEquals(R.string.color_blue_text, colorHexToColorName("20A4F7"));
+ Assert.assertEquals(R.string.color_green_text, colorHexToColorName("6ECD07"));
+ Assert.assertEquals(R.string.noColor_text, colorHexToColorName(""));
+
+ }
+}
diff --git a/app/src/test/java/io/github/wulkanowy/activity/dashboard/grades/SubjectWithGradesTest.java b/app/src/test/java/io/github/wulkanowy/activity/dashboard/grades/SubjectWithGradesTest.java
new file mode 100644
index 000000000..6ecc3f428
--- /dev/null
+++ b/app/src/test/java/io/github/wulkanowy/activity/dashboard/grades/SubjectWithGradesTest.java
@@ -0,0 +1,45 @@
+package io.github.wulkanowy.activity.dashboard.grades;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import io.github.wulkanowy.dao.entities.Grade;
+
+public class SubjectWithGradesTest {
+
+ private List gradeListEmpty = new ArrayList<>();
+
+ private List gradeList = new ArrayList<>();
+
+ private Grade grade = new Grade().setDescription("Lorem ipsum");
+
+ @Before
+ public void setUp() {
+ gradeList.add(grade);
+ }
+
+ @Test
+ public void countTest() {
+ SubjectWithGrades subjectWithGrades = new SubjectWithGrades("", gradeList);
+ Assert.assertEquals(1, subjectWithGrades.getItemCount());
+
+ SubjectWithGrades subjectWithGrades1 = new SubjectWithGrades("", gradeListEmpty);
+ Assert.assertEquals(0, subjectWithGrades1.getItemCount());
+ }
+
+ @Test
+ public void titleTest() {
+ SubjectWithGrades subjectWithGrades = new SubjectWithGrades("TEST", gradeListEmpty);
+ Assert.assertEquals("TEST", subjectWithGrades.getTitle());
+ }
+
+ @Test
+ public void itemTest() {
+ SubjectWithGrades subjectWithGrades = new SubjectWithGrades("", gradeList);
+ Assert.assertEquals(gradeList, subjectWithGrades.getItems());
+ }
+}
diff --git a/app/src/test/java/io/github/wulkanowy/utilities/ConnectionUtilitiesTest.java b/app/src/test/java/io/github/wulkanowy/utilities/ConnectionUtilitiesTest.java
new file mode 100644
index 000000000..62cc366d9
--- /dev/null
+++ b/app/src/test/java/io/github/wulkanowy/utilities/ConnectionUtilitiesTest.java
@@ -0,0 +1,42 @@
+package io.github.wulkanowy.utilities;
+
+import android.content.Context;
+import android.net.ConnectivityManager;
+import android.net.NetworkInfo;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class ConnectionUtilitiesTest extends ConnectionUtilities {
+
+ @Test
+ public void isOnlineTrueTest() {
+ NetworkInfo networkInfo = mock(NetworkInfo.class);
+ when(networkInfo.isConnectedOrConnecting()).thenReturn(true);
+
+ ConnectivityManager connectivityManager = mock(ConnectivityManager.class);
+ when(connectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo);
+
+ Context context = mock(Context.class);
+ when(context.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(connectivityManager);
+
+ Assert.assertTrue(ConnectionUtilities.isOnline(context));
+ }
+
+ @Test
+ public void isOnlineFalseTest() {
+ NetworkInfo networkInfo = mock(NetworkInfo.class);
+ when(networkInfo.isConnectedOrConnecting()).thenReturn(false);
+
+ ConnectivityManager connectivityManager = mock(ConnectivityManager.class);
+ when(connectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo);
+
+ Context context = mock(Context.class);
+ when(context.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(connectivityManager);
+
+ Assert.assertFalse(ConnectionUtilities.isOnline(context));
+ }
+}
diff --git a/app/src/test/java/io/github/wulkanowy/utilities/ConversionVulcanObjectTest.java b/app/src/test/java/io/github/wulkanowy/utilities/ConversionVulcanObjectTest.java
new file mode 100644
index 000000000..b74d13d5d
--- /dev/null
+++ b/app/src/test/java/io/github/wulkanowy/utilities/ConversionVulcanObjectTest.java
@@ -0,0 +1,45 @@
+package io.github.wulkanowy.utilities;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import io.github.wulkanowy.api.grades.Grade;
+import io.github.wulkanowy.api.grades.Subject;
+
+public class ConversionVulcanObjectTest extends ConversionVulcanObject {
+
+ @Test
+ public void subjectConversionTest() {
+ List subjectList = new ArrayList<>();
+ subjectList.add(new Subject().setName("Matematyka"));
+ List subjectEntitiesList =
+ ConversionVulcanObject.subjectsToSubjectEntities(subjectList);
+
+ Assert.assertEquals("Matematyka", subjectEntitiesList.get(0).getName());
+ }
+
+ @Test
+ public void subjectConversionEmptyTest() {
+ Assert.assertEquals(new ArrayList<>(),
+ ConversionVulcanObject.subjectsToSubjectEntities(new ArrayList()));
+ }
+
+ @Test
+ public void gradesConversionTest() {
+ List gradeList = new ArrayList<>();
+ gradeList.add(new Grade().setDescription("Lorem ipsum"));
+ List gradeEntitiesList =
+ ConversionVulcanObject.gradesToGradeEntities(gradeList);
+
+ Assert.assertEquals("Lorem ipsum", gradeEntitiesList.get(0).getDescription());
+ }
+
+ @Test
+ public void gradeConversionEmptyTest() {
+ Assert.assertEquals(new ArrayList<>(),
+ ConversionVulcanObject.gradesToGradeEntities(new ArrayList()));
+ }
+}
diff --git a/build.gradle b/build.gradle
index d673f9ab5..ef951a0d4 100644
--- a/build.gradle
+++ b/build.gradle
@@ -18,6 +18,17 @@ buildscript {
}
}
+project.ext.preDexLibs = !project.hasProperty("disablePreDex")
+subprojects {
+ project.plugins.whenPluginAdded { plugin ->
+ if ("com.android.build.gradle.AppPlugin" == plugin.class.name) {
+ project.android.dexOptions.preDexLibraries = rootProject.ext.preDexLibs
+ } else if ("com.android.build.gradle.LibraryPlugin" == plugin.class.name) {
+ project.android.dexOptions.preDexLibraries = rootProject.ext.preDexLibs
+ }
+ }
+}
+
allprojects {
repositories {
jcenter()