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