1
0

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:
Rafał Borcz
2017-09-23 22:17:13 +02:00
committed by Mikołaj Pich
parent 1f5a03fba7
commit fe54fa71f3
24 changed files with 368 additions and 67 deletions

View File

@ -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() {

View File

@ -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;

View File

@ -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()));

View File

@ -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<Grade> compareGradeList(List<Grade> newList, List<Grade> oldList) {

View File

@ -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 {

View File

@ -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) {

View File

@ -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);

View File

@ -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<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<>();