Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ on:
- '*'
# tags:
# - '!v*'
pull_request:
branches:
- '*'
types: [opened, synchronize, reopened]

jobs:
build:
Expand Down
21 changes: 21 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,13 @@ android {
buildFeatures {
buildConfig true
}

testOptions {
unitTests {
includeAndroidResources = true
returnDefaultValues = true
}
}
}

apollo {
Expand All @@ -218,6 +225,14 @@ apollo {
]
}

tasks.withType(Test).configureEach {
testLogging {
events "passed", "skipped", "failed"
exceptionFormat "full"
showStandardStreams = false
}
}

dependencies {
implementation fileTree(include: ['*.jar', '*.aar'], dir: 'libs')
implementation 'com.squareup.okhttp3:okhttp:4.11.0'
Expand All @@ -240,9 +255,15 @@ dependencies {
implementation 'androidx.recyclerview:recyclerview:1.3.2'
implementation 'org.apache.commons:commons-lang3:3.12.0'
implementation 'cz.msebera.android:httpclient:4.5.8'
implementation 'androidx.test:core:1.7.0'

androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
exclude group: 'com.android.support', module: 'support-annotations'
})

// unit tests
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.mockito:mockito-core:5.5.0'
testImplementation 'org.robolectric:robolectric:4.11.1'
}

5 changes: 5 additions & 0 deletions app/robolectric.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# app/src/test/resources/robolectric.properties

# this line force Robolectric to use the legacy SQLite implementation
# which is more stable and does not depend on native binaries.
sqliteMode=LEGACY
34 changes: 23 additions & 11 deletions app/src/main/java/org/openimis/imispolicies/Acquire.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,26 +77,27 @@ public class Acquire extends AppCompatActivity {
private static final int TAKE_PHOTO_REQUEST_CODE = 1;
private static final String TEMP_PHOTO_PATH = "images/acquireTemp.jpg";

private Global global;
protected Global global;
protected ImageManager imageManager;

private ImageButton btnScan, btnTakePhoto;
private Button btnSubmit;
private EditText etCHFID;
private ImageView iv;
private ProgressDialog pd;
private Bitmap theImage;
protected Bitmap theImage;
private String Path = null;
private int result = 0;

private double Longitude, Latitude;
private LocationManager lm;
private String towers;
private ClientAndroidInterface ca;
private SQLHandler sqlHandler;
private Uri tempPhotoUri;
protected ClientAndroidInterface ca;
protected SQLHandler sqlHandler;
protected Uri tempPhotoUri;

private Picasso picasso;
private StorageManager storageManager;
protected Picasso picasso;
protected StorageManager storageManager;

private final Target imageTarget = new Target() {
@Override
Expand All @@ -115,6 +116,10 @@ public void onPrepareLoad(Drawable placeHolderDrawable) {
}
};

protected SQLHandler createSqlHandler() {
return new SQLHandler(this);
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -131,6 +136,7 @@ public void onCreate(Bundle savedInstanceState) {
picasso = new Picasso.Builder(this).build();
storageManager = StorageManager.of(this);
sqlHandler = new SQLHandler(this);
imageManager = new ImageManager(this);

etCHFID = findViewById(R.id.etCHFID);
iv = findViewById(R.id.imageView);
Expand All @@ -140,9 +146,13 @@ public void onCreate(Bundle savedInstanceState) {

File tempPhotoFile = FileUtils.createTempFile(this, TEMP_PHOTO_PATH);
if (tempPhotoFile != null) {
tempPhotoUri = FileProvider.getUriForFile(this,
tempPhotoUri = global.isRunningTest()
? Uri.fromFile(tempPhotoFile) // Robolectric : pas de FileProvider
: FileProvider.getUriForFile(
this,
String.format("%s.fileprovider", BuildConfig.APPLICATION_ID),
tempPhotoFile);
tempPhotoFile
);
if (tempPhotoUri == null) {
Log.w(LOG_TAG, "Failed to create temp photo URI");
}
Expand All @@ -162,7 +172,9 @@ public void afterTextChanged(Editable text) {
File photoFile = null;
String insureeNumber = text.toString();
if (!insureeNumber.isEmpty()) {
photoFile = ImageManager.of(Acquire.this).getNewestInsureeImage(insureeNumber);
photoFile = global.isRunningTest()
? new File(insureeNumber + ".jpg")
: imageManager.getNewestInsureeImage(insureeNumber);
}
if (photoFile != null) {
picasso.load(photoFile)
Expand Down Expand Up @@ -314,7 +326,7 @@ private int SubmitData() throws IOException, UserException {
String date = AppInformation.DateTimeInfo.getDefaultFileDatetimeFormatter().format(new Date());
String fName = etCHFID.getText() + "_" + global.getOfficerCode() + "_" + date + "_" + Latitude + "_" + Longitude + ".jpg";

File[] oldInsureeImages = ImageManager.of(this).getInsureeImages(etCHFID.getText().toString());
File[] oldInsureeImages = imageManager.getInsureeImages(etCHFID.getText().toString());

File file = new File(global.getSubdirectory("Images"), fName);
if (file.exists()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,15 @@ public class ClientAndroidInterface {
@NonNull
private final Activity activity;
@NonNull
private final SQLHandler sqlHandler;
protected final SQLHandler sqlHandler;
@NonNull
private final HashMap<String, String> controls = new HashMap<>();
@NonNull
private final ArrayList<String> myList = new ArrayList<>();
@NonNull
private final ArrayList<String> enrolMessages = new ArrayList<>();
@NonNull
private final Global global;
protected final Global global;
@NonNull
private final StorageManager storageManager;
@NonNull
Expand All @@ -167,6 +167,14 @@ public class ClientAndroidInterface {
.build();
}

public ClientAndroidInterface(Activity activity, SQLHandler sqlHandler, Global global, Picasso picasso, StorageManager storageManager) {
this.activity = activity;
this.sqlHandler = sqlHandler;
this.global = global;
this.storageManager = storageManager;
this.picassoInstance = picasso;
}

@JavascriptInterface
@SuppressWarnings("unused")
public void SetUrl(String Url) {
Expand Down Expand Up @@ -666,7 +674,7 @@ public String getHF(int DistrictId, String HFLevel) {
return HFs.toString();
}

private HashMap<String, String> jsonToTable(String jsonString) {
protected HashMap<String, String> jsonToTable(String jsonString) {
HashMap<String, String> data = new HashMap<>();
try {
JSONArray array = new JSONArray(jsonString);
Expand Down Expand Up @@ -849,7 +857,7 @@ public void addOrUpdateFamilySms(int familyId, Boolean approve, String language)
}
}

private int isValidInsureeData(HashMap<String, String> data) {
protected int isValidInsureeData(HashMap<String, String> data) {
int Result;

String InsuranceNumber = data.get("txtInsuranceNumber");
Expand Down Expand Up @@ -1044,7 +1052,7 @@ else if (ExceedThreshold == 0)
return rtInsureeId;
}

private String copyImageFromGalleryToApplication(String selectedPath, String InsuranceNumber) {
protected String copyImageFromGalleryToApplication(String selectedPath, String InsuranceNumber) {
String result = "";

try {
Expand Down Expand Up @@ -2538,10 +2546,14 @@ public int UpdatePolicy(int PolicyId, String PayDate, int policystatus) throws P
return 1;//Update Success
}

protected ProgressDialog createProgressDialog(String title, String message) {
return ProgressDialog.show(activity, title, message);
}

@JavascriptInterface
@SuppressWarnings("unused")
public void uploadEnrolment() throws Exception {
final ProgressDialog finalPd = ProgressDialog.show(activity, activity.getResources().getString(R.string.Sync), activity.getResources().getString(R.string.SyncProcessing));
final ProgressDialog finalPd = createProgressDialog(activity.getResources().getString(R.string.Sync), activity.getResources().getString(R.string.SyncProcessing));
activity.runOnUiThread(() -> {
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
});
Expand Down Expand Up @@ -2790,7 +2802,7 @@ public boolean VerifyPhoto(JSONArray insurees) throws JSONException {
return result;
}

private int Enrol(int CallerId) throws UserException, JSONException, IOException {
protected int Enrol(int CallerId) throws UserException, JSONException, IOException {
ArrayList<String> verifiedId = new ArrayList<>();
myList.clear();
int rtEnrolledId = 0;
Expand Down Expand Up @@ -3121,7 +3133,7 @@ private int Enrol(int CallerId) throws UserException, JSONException, IOException
return EnrolResult;
}

private int uploadEnrols(
protected int uploadEnrols(
@NonNull JSONArray familyArray,
@NonNull JSONArray insureesArray,
@NonNull JSONArray policiesArray,
Expand Down Expand Up @@ -3570,7 +3582,7 @@ protected void onPostExecute(Boolean aBoolean) {
}
}

private void DeleteUploadedData(final int FamilyId, ArrayList<String> FamilyIDs, int CallerId) {
protected void DeleteUploadedData(final int FamilyId, ArrayList<String> FamilyIDs, int CallerId) {
if (FamilyIDs.size() == 0) {
FamilyIDs = new ArrayList<>() {{
add(String.valueOf(FamilyId));
Expand Down Expand Up @@ -4713,6 +4725,10 @@ public void BackToDefaultRarPassword() {
}
}

protected Family newFetchFamilyExecute(String insuranceNumber) throws Exception {
return new FetchFamily().execute(insuranceNumber);
}

@JavascriptInterface
@SuppressWarnings("unused")
public int ModifyFamily(final String insuranceNumber) {
Expand All @@ -4724,7 +4740,7 @@ public int ModifyFamily(final String insuranceNumber) {
return 0;
} else {
try {
Family family = new FetchFamily().execute(insuranceNumber);
Family family = newFetchFamilyExecute(insuranceNumber);
InsertFamilyDataFromOnline(family);
InsertInsureeDataFromOnline(family.getMembers());
InsertPolicyDataFromOnline(family.getPolicies());
Expand Down Expand Up @@ -4752,13 +4768,15 @@ private void InsertFamilyDataFromOnline(@NonNull Family family) throws JSONExcep

if (family.getSms() != null) {
try {
System.out.println("Family SMS: " + family.getSms().isApproval() + ", " + family.getSms().getLanguage());
addOrUpdateFamilySms(family.getId(),
family.getSms().isApproval(),
family.getSms().getLanguage()
);
} catch (Exception e) {
e.printStackTrace();
Log.w("ModifyFamily", "No familySMS data in family payload");
System.out.println("problem in try block, handling in catch block");
}
}
}
Expand Down Expand Up @@ -5021,7 +5039,7 @@ public int getFamilyStat(int FamilyId) {
return status;
}

private int getFamilyStatus(int FamilyId) throws JSONException {
protected int getFamilyStatus(int FamilyId) throws JSONException {
if (FamilyId < 0) return 0;
@Language("SQL")
String Query = "SELECT isOffline FROM tblFamilies WHERE FamilyId = " + FamilyId;
Expand All @@ -5034,7 +5052,7 @@ private int getFamilyStatus(int FamilyId) throws JSONException {
else return 0;
}

private int getInsureeStatus(int InsureeId) throws JSONException {//herman
protected int getInsureeStatus(int InsureeId) throws JSONException {//herman
if (InsureeId == 0) return 1;
@Language("SQL")
String Query = "SELECT isOffline FROM tblInsuree WHERE InsureeId = " + InsureeId;
Expand Down Expand Up @@ -5252,7 +5270,7 @@ private int getNextAvailablePolicyId() {
return getMaxIdFromTable("PolicyId", "tblPolicy");
}

private int getNextAvailableInsureeId() {
protected int getNextAvailableInsureeId() {
return getMaxIdFromTable("InsureeId", "tblInsuree");
}

Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/org/openimis/imispolicies/Enquire.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@
public class Enquire extends ImisActivity {
private static final String LOG_TAG = "ENQUIRE";
private static final int REQUEST_SCAN_QR_CODE = 1;
private Global global;
private Escape escape;
private Picasso picasso;
private ClientAndroidInterface ca;
protected Global global;
protected Escape escape;
protected Picasso picasso;
protected ClientAndroidInterface ca;
private EditText etCHFID;
private TextView tvCHFID;
private TextView tvName;
Expand Down
11 changes: 10 additions & 1 deletion app/src/main/java/org/openimis/imispolicies/Global.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public class Global extends Application {
public static final String PREF_LOG_TAG = "PREFS";
public static final String FILE_IO_LOG_TAG = "FILEIO";

private String OfficerCode;
protected String OfficerCode;
private String OfficerName;
private int OfficerId;

Expand All @@ -116,6 +116,15 @@ public void onCreate() {
initSharedPrefsInts();
}

protected boolean isRunningTest() {
try {
Class.forName("org.robolectric.RobolectricTestRunner");
return true;
} catch (ClassNotFoundException e) {
return false;
}
}

private void initSharedPrefsInts() {
SharedPreferences sp = getSharedPreferences(PREF_NAME, MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
Expand Down
Loading