forked from github/wulkanowy-mirror
Create tests (#26)
* Add unit and instrumented tests * Divide code coverage to two different tags on codecov * Change sdk image to 25 * Turn on console output in unit tests
This commit is contained in:
parent
1f5a03fba7
commit
fe54fa71f3
@ -7,7 +7,7 @@ references:
|
|||||||
|
|
||||||
container_config: &container_config
|
container_config: &container_config
|
||||||
docker:
|
docker:
|
||||||
- image: circleci/android:api-25-alpha
|
- image: circleci/android:api-26-alpha
|
||||||
working_directory: *workspace_root
|
working_directory: *workspace_root
|
||||||
environment:
|
environment:
|
||||||
environment:
|
environment:
|
||||||
@ -33,7 +33,7 @@ jobs:
|
|||||||
command: ./gradlew --no-daemon --stacktrace dependencies || true
|
command: ./gradlew --no-daemon --stacktrace dependencies || true
|
||||||
- run:
|
- run:
|
||||||
name: Initial build
|
name: Initial build
|
||||||
command: ./gradlew --no-daemon --stacktrace assembleDebug
|
command: ./gradlew --no-daemon --stacktrace assembleDebug -PdisablePreDex
|
||||||
- store_artifacts:
|
- store_artifacts:
|
||||||
path: ./app/build/outputs/apk/
|
path: ./app/build/outputs/apk/
|
||||||
destination: apks/
|
destination: apks/
|
||||||
@ -58,6 +58,8 @@ jobs:
|
|||||||
- store_artifacts:
|
- store_artifacts:
|
||||||
path: ./app/build/reports/
|
path: ./app/build/reports/
|
||||||
destination: lint_reports/app/
|
destination: lint_reports/app/
|
||||||
|
- store_test_results:
|
||||||
|
path: ./app/build/reports/
|
||||||
|
|
||||||
test:
|
test:
|
||||||
<<: *container_config
|
<<: *container_config
|
||||||
@ -69,8 +71,10 @@ jobs:
|
|||||||
name: Run Tests
|
name: Run Tests
|
||||||
command: ./gradlew --no-daemon --stacktrace test
|
command: ./gradlew --no-daemon --stacktrace test
|
||||||
- run:
|
- run:
|
||||||
name: Upload code coverage to codecov
|
name: Upload unit code coverage to codecov
|
||||||
command: ./gradlew --no-daemon --stacktrace jacocoTestReport && bash <(curl -s https://codecov.io/bash)
|
command: |
|
||||||
|
./gradlew --no-daemon --stacktrace jacocoTestReport
|
||||||
|
bash <(curl -s https://codecov.io/bash) -F unit
|
||||||
- run:
|
- run:
|
||||||
name: Upload code coverage to codacy
|
name: Upload code coverage to codacy
|
||||||
command: ./gradlew --no-daemon --stacktrace codacyUpload
|
command: ./gradlew --no-daemon --stacktrace codacyUpload
|
||||||
@ -83,6 +87,43 @@ jobs:
|
|||||||
- store_test_results:
|
- store_test_results:
|
||||||
path: ./app/build/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:
|
workflows:
|
||||||
version: 2
|
version: 2
|
||||||
|
|
||||||
@ -95,3 +136,6 @@ workflows:
|
|||||||
- test:
|
- test:
|
||||||
requires:
|
requires:
|
||||||
- build
|
- build
|
||||||
|
- instrumented:
|
||||||
|
requires:
|
||||||
|
- build
|
||||||
|
19
.codecov.yml
Normal file
19
.codecov.yml
Normal file
@ -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
|
@ -9,7 +9,7 @@ android {
|
|||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "io.github.wulkanowy"
|
applicationId "io.github.wulkanowy"
|
||||||
testApplicationId "io.github.tests.wulkanowy"
|
testApplicationId "io.github.tests.wulkanowy"
|
||||||
minSdkVersion 14
|
minSdkVersion 15
|
||||||
targetSdkVersion 26
|
targetSdkVersion 26
|
||||||
versionCode 1
|
versionCode 1
|
||||||
versionName "0.1.0"
|
versionName "0.1.0"
|
||||||
@ -26,6 +26,16 @@ android {
|
|||||||
ext.enableCrashlytics = false
|
ext.enableCrashlytics = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testOptions {
|
||||||
|
unitTests.all {
|
||||||
|
testLogging {
|
||||||
|
events "passed", "skipped", "failed", "standardOut", "standardError"
|
||||||
|
outputs.upToDateWhen {false}
|
||||||
|
showStandardStreams = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
greendao {
|
greendao {
|
||||||
@ -35,9 +45,7 @@ greendao {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile fileTree(include: ['*.jar'], dir: 'libs')
|
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:appcompat-v7:26.0.1'
|
||||||
compile 'com.android.support.constraint:constraint-layout:1.0.2'
|
compile 'com.android.support.constraint:constraint-layout:1.0.2'
|
||||||
compile 'com.android.support:design:26.0.1'
|
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:support-v4:26.0.1'
|
||||||
compile 'com.android.support:recyclerview-v7:26.0.1'
|
compile 'com.android.support:recyclerview-v7:26.0.1'
|
||||||
compile 'com.android.support:cardview-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.firebase:firebase-jobdispatcher:0.8.1'
|
||||||
compile 'com.thoughtbot:expandablerecyclerview:1.3'
|
compile 'com.thoughtbot:expandablerecyclerview:1.3'
|
||||||
compile 'org.apache.commons:commons-lang3:3.6'
|
compile 'org.apache.commons:commons-lang3:3.6'
|
||||||
@ -60,4 +67,12 @@ dependencies {
|
|||||||
|
|
||||||
testCompile 'junit:junit:4.12'
|
testCompile 'junit:junit:4.12'
|
||||||
testCompile 'org.mockito:mockito-core:2.10.0'
|
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'
|
||||||
}
|
}
|
||||||
|
@ -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 <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
|
||||||
*/
|
|
||||||
@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());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +1,10 @@
|
|||||||
package io.github.wulkanowy.dao.entities;
|
package io.github.wulkanowy.dao.entities;
|
||||||
|
|
||||||
|
import android.support.test.filters.SmallTest;
|
||||||
|
|
||||||
import org.greenrobot.greendao.test.AbstractDaoTestLongPk;
|
import org.greenrobot.greendao.test.AbstractDaoTestLongPk;
|
||||||
|
|
||||||
|
@SmallTest
|
||||||
public class AccountTest extends AbstractDaoTestLongPk<AccountDao, Account> {
|
public class AccountTest extends AbstractDaoTestLongPk<AccountDao, Account> {
|
||||||
|
|
||||||
public AccountTest() {
|
public AccountTest() {
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
package io.github.wulkanowy.dao.entities;
|
package io.github.wulkanowy.dao.entities;
|
||||||
|
|
||||||
|
import android.support.test.filters.SmallTest;
|
||||||
|
|
||||||
import org.greenrobot.greendao.test.AbstractDaoTestLongPk;
|
import org.greenrobot.greendao.test.AbstractDaoTestLongPk;
|
||||||
|
|
||||||
|
@SmallTest
|
||||||
public class GradeTest extends AbstractDaoTestLongPk<GradeDao, Grade> {
|
public class GradeTest extends AbstractDaoTestLongPk<GradeDao, Grade> {
|
||||||
|
|
||||||
public GradeTest() {
|
public GradeTest() {
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
package io.github.wulkanowy.dao.entities;
|
package io.github.wulkanowy.dao.entities;
|
||||||
|
|
||||||
|
import android.support.test.filters.SmallTest;
|
||||||
|
|
||||||
import org.greenrobot.greendao.test.AbstractDaoTestLongPk;
|
import org.greenrobot.greendao.test.AbstractDaoTestLongPk;
|
||||||
|
|
||||||
|
@SmallTest
|
||||||
public class SubjectTest extends AbstractDaoTestLongPk<SubjectDao, Subject> {
|
public class SubjectTest extends AbstractDaoTestLongPk<SubjectDao, Subject> {
|
||||||
|
|
||||||
public SubjectTest() {
|
public SubjectTest() {
|
||||||
|
@ -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)));
|
||||||
|
}
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
@ -72,11 +72,11 @@ public class AccountSynchronizationTest {
|
|||||||
public void loginCurrentUserTest() throws Exception {
|
public void loginCurrentUserTest() throws Exception {
|
||||||
AccountDao accountDao = daoSession.getAccountDao();
|
AccountDao accountDao = daoSession.getAccountDao();
|
||||||
|
|
||||||
Safety safety = new Safety(context);
|
Safety safety = new Safety();
|
||||||
|
|
||||||
Long userId = accountDao.insert(new Account()
|
Long userId = accountDao.insert(new Account()
|
||||||
.setEmail("TEST@TEST")
|
.setEmail("TEST@TEST")
|
||||||
.setPassword(safety.encrypt("TEST@TEST", "TEST"))
|
.setPassword(safety.encrypt("TEST@TEST", "TEST", context))
|
||||||
.setSymbol(""));
|
.setSymbol(""));
|
||||||
|
|
||||||
setUserIdSharePreferences(userId);
|
setUserIdSharePreferences(userId);
|
||||||
@ -117,7 +117,7 @@ public class AccountSynchronizationTest {
|
|||||||
Assert.assertNotNull(loginSession.getDaoSession());
|
Assert.assertNotNull(loginSession.getDaoSession());
|
||||||
Assert.assertEquals(loginSession.getVulcan(), vulcan);
|
Assert.assertEquals(loginSession.getVulcan(), vulcan);
|
||||||
|
|
||||||
Safety safety = new Safety(context);
|
Safety safety = new Safety();
|
||||||
Account account = daoSession.getAccountDao().load(userId);
|
Account account = daoSession.getAccountDao().load(userId);
|
||||||
|
|
||||||
Assert.assertNotNull(account);
|
Assert.assertNotNull(account);
|
||||||
|
@ -72,7 +72,7 @@ public class DashboardActivity extends AppCompatActivity {
|
|||||||
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
|
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
|
||||||
|
|
||||||
getSupportFragmentManager().beginTransaction()
|
getSupportFragmentManager().beginTransaction()
|
||||||
.add(R.id.fragment_container, boardFragment).commit();
|
.replace(R.id.fragment_container, boardFragment).commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
|
@ -44,17 +44,17 @@ public class GradesDialogFragment extends DialogFragment {
|
|||||||
dateText.setText(grade.getDate());
|
dateText.setText(grade.getDate());
|
||||||
colorText.setText(colorHexToColorName(grade.getColor()));
|
colorText.setText(colorHexToColorName(grade.getColor()));
|
||||||
|
|
||||||
if (grade.getDescription().equals("")) {
|
if ("".equals(grade.getDescription())) {
|
||||||
if (!grade.getSymbol().equals("")) {
|
if (!"".equals(grade.getSymbol())) {
|
||||||
descriptionText.setText(grade.getSymbol());
|
descriptionText.setText(grade.getSymbol());
|
||||||
}
|
}
|
||||||
} else if (!grade.getSymbol().equals("")) {
|
} else if (!"".equals(grade.getSymbol())) {
|
||||||
descriptionText.setText(grade.getSymbol() + " - " + grade.getDescription());
|
descriptionText.setText(grade.getSymbol() + " - " + grade.getDescription());
|
||||||
} else {
|
} else {
|
||||||
descriptionText.setText(grade.getDescription());
|
descriptionText.setText(grade.getDescription());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!grade.getTeacher().equals("")) {
|
if (!"".equals(grade.getTeacher())) {
|
||||||
teacherText.setText(grade.getTeacher());
|
teacherText.setText(grade.getTeacher());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ public class GradesDialogFragment extends DialogFragment {
|
|||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int colorHexToColorName(String hexColor) {
|
public static int colorHexToColorName(String hexColor) {
|
||||||
switch (hexColor) {
|
switch (hexColor) {
|
||||||
case "000000": {
|
case "000000": {
|
||||||
return R.string.color_black_text;
|
return R.string.color_black_text;
|
||||||
|
@ -35,7 +35,8 @@ public class GradesFragment extends Fragment {
|
|||||||
|
|
||||||
DaoSession daoSession = ((WulkanowyApp) getActivity().getApplication()).getDaoSession();
|
DaoSession daoSession = ((WulkanowyApp) getActivity().getApplication()).getDaoSession();
|
||||||
|
|
||||||
if (subjectWithGradesList.equals(new ArrayList<>())) {
|
if (new ArrayList<>().equals(subjectWithGradesList)) {
|
||||||
|
createExpListView();
|
||||||
new GradesTask(daoSession).execute();
|
new GradesTask(daoSession).execute();
|
||||||
} else if (subjectWithGradesList.size() > 0) {
|
} else if (subjectWithGradesList.size() > 0) {
|
||||||
createExpListView();
|
createExpListView();
|
||||||
@ -45,7 +46,7 @@ public class GradesFragment extends Fragment {
|
|||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createExpListView() {
|
private void createExpListView() {
|
||||||
|
|
||||||
RecyclerView recyclerView = view.findViewById(R.id.subject_grade_recycler);
|
RecyclerView recyclerView = view.findViewById(R.id.subject_grade_recycler);
|
||||||
recyclerView.setLayoutManager(new LinearLayoutManager(view.getContext()));
|
recyclerView.setLayoutManager(new LinearLayoutManager(view.getContext()));
|
||||||
|
@ -7,7 +7,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import io.github.wulkanowy.dao.entities.Grade;
|
import io.github.wulkanowy.dao.entities.Grade;
|
||||||
|
|
||||||
public class EntitiesCompare {
|
public abstract class EntitiesCompare {
|
||||||
|
|
||||||
public static List<Grade> compareGradeList(List<Grade> newList, List<Grade> oldList) {
|
public static List<Grade> compareGradeList(List<Grade> newList, List<Grade> oldList) {
|
||||||
|
|
||||||
|
@ -9,16 +9,12 @@ import io.github.wulkanowy.utilities.RootUtilities;
|
|||||||
|
|
||||||
public class Safety extends Scrambler {
|
public class Safety extends Scrambler {
|
||||||
|
|
||||||
public Safety(Context context) {
|
public String encrypt(String email, String plainText, Context context) throws CryptoException, UnsupportedOperationException {
|
||||||
super(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String encrypt(String email, String plainText) throws CryptoException, UnsupportedOperationException {
|
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
||||||
|
|
||||||
loadKeyStore();
|
loadKeyStore();
|
||||||
generateNewKey(email);
|
generateNewKey(email, context);
|
||||||
return encryptString(email, plainText);
|
return encryptString(email, plainText);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
@ -29,19 +29,14 @@ import javax.security.auth.x500.X500Principal;
|
|||||||
|
|
||||||
public class Scrambler {
|
public class Scrambler {
|
||||||
|
|
||||||
public final static String DEBUG_TAG = "WulkanowySecurity";
|
|
||||||
|
|
||||||
private static final String ANDROID_KEYSTORE = "AndroidKeyStore";
|
private static final String ANDROID_KEYSTORE = "AndroidKeyStore";
|
||||||
|
|
||||||
protected Context context;
|
public final static String DEBUG_TAG = "WulkanowySecurity";
|
||||||
|
|
||||||
private KeyStore keyStore;
|
private KeyStore keyStore;
|
||||||
|
|
||||||
protected Scrambler(Context context) {
|
public void loadKeyStore() throws CryptoException {
|
||||||
this.context = context;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void loadKeyStore() throws CryptoException {
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
keyStore = KeyStore.getInstance(ANDROID_KEYSTORE);
|
keyStore = KeyStore.getInstance(ANDROID_KEYSTORE);
|
||||||
@ -54,7 +49,7 @@ public class Scrambler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@TargetApi(18)
|
@TargetApi(18)
|
||||||
protected void generateNewKey(String alias) throws CryptoException {
|
protected void generateNewKey(String alias, Context context) throws CryptoException {
|
||||||
|
|
||||||
Calendar start = Calendar.getInstance();
|
Calendar start = Calendar.getInstance();
|
||||||
Calendar end = Calendar.getInstance();
|
Calendar end = Calendar.getInstance();
|
||||||
@ -62,7 +57,7 @@ public class Scrambler {
|
|||||||
AlgorithmParameterSpec spec;
|
AlgorithmParameterSpec spec;
|
||||||
|
|
||||||
end.add(Calendar.YEAR, 10);
|
end.add(Calendar.YEAR, 10);
|
||||||
if (!alias.isEmpty()) {
|
if (!"".equals(alias)) {
|
||||||
try {
|
try {
|
||||||
if (!keyStore.containsAlias(alias)) {
|
if (!keyStore.containsAlias(alias)) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
|
@ -33,7 +33,7 @@ public class AccountSynchronisation {
|
|||||||
|
|
||||||
Log.d(VulcanSync.DEBUG_TAG, "Login current user id=" + String.valueOf(userId));
|
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);
|
Account account = accountDao.load(userId);
|
||||||
vulcan.login(
|
vulcan.login(
|
||||||
account.getEmail(),
|
account.getEmail(),
|
||||||
@ -60,12 +60,12 @@ public class AccountSynchronisation {
|
|||||||
|
|
||||||
PersonalData personalData = vulcan.getBasicInformation().getPersonalData();
|
PersonalData personalData = vulcan.getBasicInformation().getPersonalData();
|
||||||
AccountDao accountDao = daoSession.getAccountDao();
|
AccountDao accountDao = daoSession.getAccountDao();
|
||||||
Safety safety = new Safety(context);
|
Safety safety = new Safety();
|
||||||
|
|
||||||
Account account = new Account()
|
Account account = new Account()
|
||||||
.setName(personalData.getFirstAndLastName())
|
.setName(personalData.getFirstAndLastName())
|
||||||
.setEmail(email)
|
.setEmail(email)
|
||||||
.setPassword(safety.encrypt(email, password))
|
.setPassword(safety.encrypt(email, password, context))
|
||||||
.setSymbol(symbol);
|
.setSymbol(symbol);
|
||||||
|
|
||||||
userId = accountDao.insert(account);
|
userId = accountDao.insert(account);
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package io.github.wulkanowy.utilities;
|
package io.github.wulkanowy.utilities;
|
||||||
|
|
||||||
|
|
||||||
import java.text.ParseException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -25,7 +24,7 @@ public abstract class ConversionVulcanObject {
|
|||||||
return subjectEntityList;
|
return subjectEntityList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Grade> gradesToGradeEntities(List<io.github.wulkanowy.api.grades.Grade> gradeList) throws ParseException {
|
public static List<Grade> gradesToGradeEntities(List<io.github.wulkanowy.api.grades.Grade> gradeList) {
|
||||||
|
|
||||||
List<Grade> gradeEntityList = new ArrayList<>();
|
List<Grade> gradeEntityList = new ArrayList<>();
|
||||||
|
|
||||||
|
@ -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(""));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -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<Grade> gradeListEmpty = new ArrayList<>();
|
||||||
|
|
||||||
|
private List<Grade> 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());
|
||||||
|
}
|
||||||
|
}
|
@ -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));
|
||||||
|
}
|
||||||
|
}
|
@ -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<Subject> subjectList = new ArrayList<>();
|
||||||
|
subjectList.add(new Subject().setName("Matematyka"));
|
||||||
|
List<io.github.wulkanowy.dao.entities.Subject> subjectEntitiesList =
|
||||||
|
ConversionVulcanObject.subjectsToSubjectEntities(subjectList);
|
||||||
|
|
||||||
|
Assert.assertEquals("Matematyka", subjectEntitiesList.get(0).getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void subjectConversionEmptyTest() {
|
||||||
|
Assert.assertEquals(new ArrayList<>(),
|
||||||
|
ConversionVulcanObject.subjectsToSubjectEntities(new ArrayList<Subject>()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void gradesConversionTest() {
|
||||||
|
List<Grade> gradeList = new ArrayList<>();
|
||||||
|
gradeList.add(new Grade().setDescription("Lorem ipsum"));
|
||||||
|
List<io.github.wulkanowy.dao.entities.Grade> gradeEntitiesList =
|
||||||
|
ConversionVulcanObject.gradesToGradeEntities(gradeList);
|
||||||
|
|
||||||
|
Assert.assertEquals("Lorem ipsum", gradeEntitiesList.get(0).getDescription());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void gradeConversionEmptyTest() {
|
||||||
|
Assert.assertEquals(new ArrayList<>(),
|
||||||
|
ConversionVulcanObject.gradesToGradeEntities(new ArrayList<Grade>()));
|
||||||
|
}
|
||||||
|
}
|
11
build.gradle
11
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 {
|
allprojects {
|
||||||
repositories {
|
repositories {
|
||||||
jcenter()
|
jcenter()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user