Skip to content

Commit cb37769

Browse files
authored
Merge branch 'develop' into feature-33539
2 parents 69b0001 + d091727 commit cb37769

15 files changed

Lines changed: 1424 additions & 38 deletions

File tree

.github/workflows/main.yml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,20 @@ on:
66
- '*'
77
# tags:
88
# - '!v*'
9+
pull_request:
10+
branches:
11+
- '*'
12+
types: [opened, synchronize, reopened]
913

1014
jobs:
1115
build:
1216
runs-on: ubuntu-latest
1317

1418
steps:
15-
- uses: actions/checkout@v2
19+
- uses: actions/checkout@v4
1620

1721
- name: Setup JDK 17
18-
uses: actions/setup-java@v2
22+
uses: actions/setup-java@v5
1923
with:
2024
distribution: 'temurin'
2125
java-version: '17'
@@ -31,7 +35,10 @@ jobs:
3135
3236
- name: build
3337
run: |
34-
./gradlew assembleDebug --stacktrace
38+
./gradlew assembleDemoProdDebug --stacktrace
39+
40+
- name: Run gradle tests
41+
run: ./gradlew testDemoProdDebugUnitTest
3542

3643
- name: Environment info
3744
run: |
@@ -44,7 +51,7 @@ jobs:
4451

4552
- name: build
4653
run: |
47-
./gradlew bundleDebug --stacktrace
54+
./gradlew bundleDemoProdDebug --stacktrace
4855
4956
- name: Environment info
5057
run: |

.github/workflows/manual.yml

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ on:
1111
description: Display name of the application
1212
required: false
1313
default: Policies Manual
14+
app_version:
15+
description: Version of the application
16+
required: true
17+
default: v1.0.0
1418
app_dir:
1519
description: Name of the folder in Documents, default IMIS-CLI
1620
required: false
@@ -34,23 +38,23 @@ jobs:
3438
runs-on: ubuntu-latest
3539

3640
steps:
37-
- uses: actions/checkout@v2
41+
- uses: actions/checkout@v4
3842

3943
- name: Setup JDK 17
40-
uses: actions/setup-java@v2
44+
uses: actions/setup-java@v5
4145
with:
4246
distribution: 'temurin'
4347
java-version: '17'
4448
cache: 'gradle'
4549

46-
- uses: actions/cache@v2
50+
- uses: actions/cache@v4
4751
with:
4852
path: |
4953
~/.gradle/caches
5054
~/.gradle/wrapper
5155
key: ${{ runner.os }}-${{ github.event.inputs.application_id }}-${{ hashFiles('**/*.gradle*') }}-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }}-${{ hashFiles('**/buildSrc/**/*.kt') }}
5256

53-
- uses: actions/cache@v2
57+
- uses: actions/cache@v4
5458
with:
5559
path: |
5660
~/.android
@@ -88,11 +92,27 @@ jobs:
8892
run: |
8993
gradle --version
9094
95+
# Run Tests Build
96+
- name: Run gradle tests
97+
run: ./gradlew testCliDebugUnitTest
98+
9199
- uses: actions/upload-artifact@v4
92100
with:
93101
name: openimis-policies-apk-${{github.run_number}}-${{github.sha}}
94102
path: ./app/build/outputs/**/*.apk
95103

104+
#publish in release
105+
- name: Edit release ${{ github.event.inputs.app_version }}
106+
uses: softprops/action-gh-release@v1
107+
with:
108+
tag_name: ${{ github.event.inputs.app_version }} # Sets the release tag to the pushed tag name (e.g., v1.0.0)
109+
name: ${{ github.event.inputs.app_version }} # Sets the release name to the pushed tag name (e.g., Release v1.0.0)
110+
files: ./app/build/outputs/**/*.apk
111+
draft: false
112+
prerelease: false
113+
env:
114+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
115+
96116
# - name: build
97117
# run: |
98118
# ./gradlew bundleDebug --stacktrace

app/build.gradle

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,13 @@ android {
206206
buildFeatures {
207207
buildConfig true
208208
}
209+
210+
testOptions {
211+
unitTests {
212+
includeAndroidResources = true
213+
returnDefaultValues = true
214+
}
215+
}
209216
}
210217

211218
apollo {
@@ -219,6 +226,14 @@ apollo {
219226
]
220227
}
221228

229+
tasks.withType(Test).configureEach {
230+
testLogging {
231+
events "passed", "skipped", "failed"
232+
exceptionFormat "full"
233+
showStandardStreams = false
234+
}
235+
}
236+
222237
dependencies {
223238
implementation fileTree(include: ['*.jar', '*.aar'], dir: 'libs')
224239
implementation 'com.squareup.okhttp3:okhttp:4.11.0'
@@ -241,10 +256,16 @@ dependencies {
241256
implementation 'androidx.recyclerview:recyclerview:1.3.2'
242257
implementation 'org.apache.commons:commons-lang3:3.12.0'
243258
implementation 'cz.msebera.android:httpclient:4.5.8'
259+
implementation 'androidx.test:core:1.7.0'
244260

245261
androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
246262
exclude group: 'com.android.support', module: 'support-annotations'
247263
})
264+
265+
// unit tests
248266
testImplementation 'junit:junit:4.13.2'
249267
implementation 'io.sentry:sentry-android:4.2.0'
268+
testImplementation 'org.mockito:mockito-core:5.5.0'
269+
testImplementation 'org.robolectric:robolectric:4.11.1'
250270
}
271+

app/robolectric.properties

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# app/src/test/resources/robolectric.properties
2+
3+
# this line force Robolectric to use the legacy SQLite implementation
4+
# which is more stable and does not depend on native binaries.
5+
sqliteMode=LEGACY

app/src/main/java/org/openimis/imispolicies/Acquire.java

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,26 +77,27 @@ public class Acquire extends AppCompatActivity {
7777
private static final int TAKE_PHOTO_REQUEST_CODE = 1;
7878
private static final String TEMP_PHOTO_PATH = "images/acquireTemp.jpg";
7979

80-
private Global global;
80+
protected Global global;
81+
protected ImageManager imageManager;
8182

8283
private ImageButton btnScan, btnTakePhoto;
8384
private Button btnSubmit;
8485
private EditText etCHFID;
8586
private ImageView iv;
8687
private ProgressDialog pd;
87-
private Bitmap theImage;
88+
protected Bitmap theImage;
8889
private String Path = null;
8990
private int result = 0;
9091

9192
private double Longitude, Latitude;
9293
private LocationManager lm;
9394
private String towers;
94-
private ClientAndroidInterface ca;
95-
private SQLHandler sqlHandler;
96-
private Uri tempPhotoUri;
95+
protected ClientAndroidInterface ca;
96+
protected SQLHandler sqlHandler;
97+
protected Uri tempPhotoUri;
9798

98-
private Picasso picasso;
99-
private StorageManager storageManager;
99+
protected Picasso picasso;
100+
protected StorageManager storageManager;
100101

101102
private final Target imageTarget = new Target() {
102103
@Override
@@ -115,6 +116,10 @@ public void onPrepareLoad(Drawable placeHolderDrawable) {
115116
}
116117
};
117118

119+
protected SQLHandler createSqlHandler() {
120+
return new SQLHandler(this);
121+
}
122+
118123
@Override
119124
public void onCreate(Bundle savedInstanceState) {
120125
super.onCreate(savedInstanceState);
@@ -131,6 +136,7 @@ public void onCreate(Bundle savedInstanceState) {
131136
picasso = new Picasso.Builder(this).build();
132137
storageManager = StorageManager.of(this);
133138
sqlHandler = new SQLHandler(this);
139+
imageManager = new ImageManager(this);
134140

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

141147
File tempPhotoFile = FileUtils.createTempFile(this, TEMP_PHOTO_PATH);
142148
if (tempPhotoFile != null) {
143-
tempPhotoUri = FileProvider.getUriForFile(this,
149+
tempPhotoUri = global.isRunningTest()
150+
? Uri.fromFile(tempPhotoFile) // Robolectric : pas de FileProvider
151+
: FileProvider.getUriForFile(
152+
this,
144153
String.format("%s.fileprovider", BuildConfig.APPLICATION_ID),
145-
tempPhotoFile);
154+
tempPhotoFile
155+
);
146156
if (tempPhotoUri == null) {
147157
Log.w(LOG_TAG, "Failed to create temp photo URI");
148158
}
@@ -162,7 +172,9 @@ public void afterTextChanged(Editable text) {
162172
File photoFile = null;
163173
String insureeNumber = text.toString();
164174
if (!insureeNumber.isEmpty()) {
165-
photoFile = ImageManager.of(Acquire.this).getNewestInsureeImage(insureeNumber);
175+
photoFile = global.isRunningTest()
176+
? new File(insureeNumber + ".jpg")
177+
: imageManager.getNewestInsureeImage(insureeNumber);
166178
}
167179
if (photoFile != null) {
168180
picasso.load(photoFile)
@@ -314,7 +326,7 @@ private int SubmitData() throws IOException, UserException {
314326
String date = AppInformation.DateTimeInfo.getDefaultFileDatetimeFormatter().format(new Date());
315327
String fName = etCHFID.getText() + "_" + global.getOfficerCode() + "_" + date + "_" + Latitude + "_" + Longitude + ".jpg";
316328

317-
File[] oldInsureeImages = ImageManager.of(this).getInsureeImages(etCHFID.getText().toString());
329+
File[] oldInsureeImages = imageManager.getInsureeImages(etCHFID.getText().toString());
318330

319331
File file = new File(global.getSubdirectory("Images"), fName);
320332
if (file.exists()) {

0 commit comments

Comments
 (0)