Skip to content

Commit a71db0d

Browse files
authored
PAINTROID-762 Update to Android 14 (#1342)
1 parent 6b433fd commit a71db0d

File tree

14 files changed

+112
-91
lines changed

14 files changed

+112
-91
lines changed

Paintroid/build.gradle

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,10 @@ android {
110110
}
111111

112112
packagingOptions {
113-
exclude "META-INF/AL2.0"
114-
exclude "META-INF/LGPL2.1"
113+
resources {
114+
excludes += ['META-INF/AL2.0', 'META-INF/LGPL2.1', "**/attach_hotspot_windows.dll"]
115+
merges += ['META-INF/licenses/ASM']
116+
}
115117
}
116118
}
117119

@@ -141,7 +143,7 @@ dependencies {
141143
androidTestImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.4.3'
142144
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
143145
androidTestImplementation 'androidx.test:rules:1.1.1'
144-
androidTestImplementation 'org.mockito:mockito-android:2.18.3'
146+
androidTestImplementation 'org.mockito:mockito-android:3.6.28'
145147
androidTestImplementation 'tools.fastlane:screengrab:2.1.0'
146148
androidTestImplementation 'com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0'
147149

Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/FileFromOtherSourceIntegrationTest.kt

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,16 +124,13 @@ class FileFromOtherSourceIntegrationTest {
124124
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
125125
contentValues.put(MediaStore.Images.Media.RELATIVE_PATH, Environment.DIRECTORY_PICTURES)
126126
}
127-
val imageUri =
128-
resolver?.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues)
127+
val imageUri = resolver?.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues)
129128
try {
130-
val requireNonNull = Objects.requireNonNull(imageUri)
131-
val fos = requireNonNull.let {
132-
it?.let { it1 -> resolver?.openOutputStream(it1) }
129+
val fos = imageUri?.let {
130+
resolver?.openOutputStream(it)
133131
}
134-
Assert.assertTrue(bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos))
135-
assert(fos != null)
136-
fos!!.close()
132+
Assert.assertTrue(bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos!!))
133+
fos.close()
137134
} catch (e: IOException) {
138135
throw AssertionError("Picture file could not be created.", e)
139136
}

Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/LayerIntegrationTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ class LayerIntegrationTest {
864864
)
865865
val imageUri = Uri.fromFile(imageFile)
866866
launchActivityRule.activity.myContentResolver.openOutputStream(imageUri).use { fos ->
867-
Assert.assertTrue(bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos))
867+
Assert.assertTrue(bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos!!))
868868
}
869869
deletionFileList.add(imageFile)
870870
return imageUri

Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/MainActivityIntentTest.kt

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import org.junit.runner.RunWith
3131
import org.mockito.MockitoAnnotations
3232
import java.io.File
3333
import java.io.IOException
34-
import java.util.Objects
3534

3635
@RunWith(AndroidJUnit4::class)
3736
class MainActivityIntentTest {
@@ -78,7 +77,7 @@ class MainActivityIntentTest {
7877
Intents.release()
7978
}
8079

81-
private fun createTestImageFile(): Uri? {
80+
private fun createTestImageFile(): Uri {
8281
val bitmap = Bitmap.createBitmap(400, 400, Bitmap.Config.ARGB_8888)
8382
val contentValues = ContentValues()
8483
contentValues.put(MediaStore.Images.Media.DISPLAY_NAME, "testfile.jpeg")
@@ -89,15 +88,13 @@ class MainActivityIntentTest {
8988
val imageUri =
9089
contentResolver?.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues)
9190
try {
92-
val fos = Objects.requireNonNull(imageUri)
93-
?.let { contentResolver?.openOutputStream(it) }
94-
Assert.assertTrue(bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos))
95-
assert(fos != null)
96-
fos?.close()
91+
val fos = imageUri?.let { contentResolver?.openOutputStream(it) }
92+
Assert.assertTrue(bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos!!))
93+
fos.close()
9794
} catch (e: IOException) {
9895
throw AssertionError("Picture file could not be created.", e)
9996
}
100-
val imageFile = File(imageUri?.path, "testfile.jpeg")
97+
val imageFile = File(imageUri.path, "testfile.jpeg")
10198
deletionFileList.add(imageFile)
10299
return imageUri
103100
}

Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/MenuFileActivityIntegrationTest.kt

Lines changed: 56 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import android.content.ContentValues
2424
import android.content.Context
2525
import android.content.Intent
2626
import android.graphics.Bitmap
27+
import android.graphics.BitmapFactory
2728
import android.graphics.Color
2829
import android.net.Uri
2930
import android.os.Build
@@ -75,6 +76,7 @@ import org.hamcrest.core.IsNot
7576
import org.junit.After
7677
import org.junit.Assert.assertEquals
7778
import org.junit.Assert.assertFalse
79+
import org.junit.Assert.assertNotEquals
7880
import org.junit.Assert.assertNotNull
7981
import org.junit.Assert.assertNotSame
8082
import org.junit.Assert.assertTrue
@@ -116,26 +118,28 @@ class MenuFileActivityIntegrationTest {
116118

117119
@After
118120
fun tearDown() {
119-
for (file in deletionFileList) {
120-
if (file != null && file.exists()) {
121-
assertTrue(file.delete())
121+
for (uri in deletionFileList) {
122+
if (uri != null && uri.exists()) {
123+
assertTrue(uri.delete())
122124
}
123125
}
124126
IdlingRegistry.getInstance().unregister(idlingResource)
125127
}
126128

127129
@Test
128130
fun testNewEmptyDrawingWithSave() {
131+
FileIO.fileType = FileIO.FileType.PNG
129132
onDrawingSurfaceView().perform(touchAt(MIDDLE))
130133
onDrawingSurfaceView().checkPixelColor(Color.BLACK, BitmapLocationProvider.MIDDLE)
131134
onTopBarView().performOpenMoreOptions()
132135
onView(withText(R.string.menu_new_image)).perform(click())
133136
onView(withText(R.string.save_button_text)).perform(click())
134-
onView(isRoot()).perform(waitFor(100))
137+
val fileName = "test987654"
135138
onView(withId(R.id.pocketpaint_image_name_save_text))
136-
.perform(replaceText("test987654"))
139+
.perform(replaceText(fileName))
137140
onView(withText(R.string.save_button_text)).perform(click())
138-
onView(isRoot()).perform(waitFor(100))
141+
onView(isRoot()).perform(waitFor(500))
142+
addFileToDeletionFileList(fileName, "png", Environment.DIRECTORY_PICTURES)
139143
onDrawingSurfaceView().checkPixelColor(Color.TRANSPARENT, BitmapLocationProvider.MIDDLE)
140144
}
141145

@@ -239,7 +243,6 @@ class MenuFileActivityIntegrationTest {
239243
onView(withId(R.id.pocketpaint_image_name_save_text))
240244
.perform(replaceText("test98765"))
241245
onView(withText(R.string.save_button_text)).perform(click())
242-
onView(isRoot()).perform(waitFor(100))
243246
assertNotNull(activity.model.savedPictureUri)
244247
addUriToDeletionFileList(activity.model.savedPictureUri)
245248
assertTrue(activity.model.isSaved)
@@ -268,21 +271,31 @@ class MenuFileActivityIntegrationTest {
268271
.edit()
269272
.clear()
270273
.commit()
274+
271275
onDrawingSurfaceView().perform(touchAt(MIDDLE))
272276
onTopBarView().performOpenMoreOptions()
273277
onView(withText(R.string.menu_save_image)).perform(click())
274278
onView(withId(R.id.pocketpaint_image_name_save_text))
275279
.perform(replaceText("testSaveCopy"))
276280
onView(withText(R.string.save_button_text)).perform(click())
281+
277282
assertNotNull(activity.model.savedPictureUri)
278283
if (!activity.model.isOpenedFromCatroid) {
279284
assertNotSame(
280285
"null",
281286
MainActivityPresenter.getPathFromUri(activity, activity.model.savedPictureUri!!)
282287
)
283288
}
289+
284290
addUriToDeletionFileList(activity.model.savedPictureUri)
285-
val oldFile = File(activity.model.savedPictureUri.toString())
291+
val savedImageFile =
292+
activity.model.savedPictureUri?.let {
293+
MainActivityPresenter.getPathFromUri(
294+
activity,
295+
it
296+
)
297+
}
298+
?.let { File(it) }
286299
onView(withText(R.string.pocketpaint_no)).perform(click())
287300
onView(withText(R.string.pocketpaint_ok)).perform(click())
288301
onDrawingSurfaceView().perform(touchAt(HALFWAY_BOTTOM_MIDDLE))
@@ -291,17 +304,13 @@ class MenuFileActivityIntegrationTest {
291304
onView(withId(R.id.pocketpaint_image_name_save_text))
292305
.perform(replaceText("copy1"))
293306
onView(withText(R.string.save_button_text)).perform(click())
294-
onView(isRoot()).perform(waitFor(100))
295-
val newFile = File(activity.model.savedPictureUri.toString())
296-
assertNotSame("Changes to saved", oldFile, newFile)
297-
assertNotNull(activity.model.savedPictureUri)
298-
if (!activity.model.isOpenedFromCatroid) {
299-
assertNotSame(
300-
"null",
301-
MainActivityPresenter.getPathFromUri(activity, activity.model.savedPictureUri!!)
302-
)
303-
}
304-
addUriToDeletionFileList(activity.model.savedPictureUri)
307+
308+
val savedCopyFile = createFileFromFileName("copy1", "png", Environment.DIRECTORY_PICTURES)
309+
val bitmap1 = BitmapFactory.decodeFile(savedImageFile?.absolutePath)
310+
val bitmap2 = BitmapFactory.decodeFile(savedCopyFile.absolutePath)
311+
assertNotEquals("Bitmaps should not be the same", bitmap1, bitmap2)
312+
313+
addFileToDeletionFileList("copy1", "png", Environment.DIRECTORY_PICTURES)
305314
}
306315

307316
@Test
@@ -328,13 +337,12 @@ class MenuFileActivityIntegrationTest {
328337
onView(withId(R.id.pocketpaint_image_name_save_text))
329338
.perform(replaceText("12345test12345"))
330339
onView(withText(R.string.save_button_text)).perform(click())
331-
onView(isRoot()).perform(waitFor(100))
340+
onView(isRoot()).perform(waitFor(300))
332341
assertNotNull(activity.model.savedPictureUri)
333342
addUriToDeletionFileList(activity.model.savedPictureUri)
334343
onTopBarView().performOpenMoreOptions()
335344
onView(withText(R.string.menu_save_image)).perform(click())
336345
onView(withText(R.string.save_button_text)).perform(click())
337-
onView(isRoot()).perform(waitFor(100))
338346
onView(withText(R.string.overwrite_button_text)).check(matches(isDisplayed()))
339347
}
340348

@@ -351,7 +359,6 @@ class MenuFileActivityIntegrationTest {
351359
onDrawingSurfaceView().perform(touchAt(MIDDLE))
352360
onTopBarView().performOpenMoreOptions()
353361
onView(withText(R.string.menu_save_image)).perform(click())
354-
onView(isRoot()).perform(waitFor(200))
355362
val newImageNumber = launchActivityRule.activity.presenter.imageNumber
356363
assertEquals((imageNumber + 1).toLong(), newImageNumber.toLong())
357364
}
@@ -365,7 +372,6 @@ class MenuFileActivityIntegrationTest {
365372
onView(withId(R.id.pocketpaint_image_name_save_text))
366373
.perform(replaceText("test9876"))
367374
onView(withText(R.string.save_button_text)).perform(click())
368-
onView(isRoot()).perform(waitFor(100))
369375
assertNotNull(activity.model.savedPictureUri)
370376
addUriToDeletionFileList(activity.model.savedPictureUri)
371377
val newImageNumber = launchActivityRule.activity.presenter.imageNumber
@@ -386,7 +392,6 @@ class MenuFileActivityIntegrationTest {
386392
onView(withId(R.id.pocketpaint_image_name_save_text))
387393
.perform(replaceText(defaultFileName))
388394
onView(withText(R.string.save_button_text)).perform(click())
389-
onView(isRoot()).perform(waitFor(100))
390395
assertNotNull(activity.model.savedPictureUri)
391396
addUriToDeletionFileList(activity.model.savedPictureUri)
392397
val oldFile = File(activity.model.savedPictureUri.toString())
@@ -398,7 +403,6 @@ class MenuFileActivityIntegrationTest {
398403
onView(withId(R.id.pocketpaint_image_name_save_text))
399404
.perform(replaceText(defaultFileName))
400405
onView(withText(R.string.save_button_text)).perform(click())
401-
onView(isRoot()).perform(waitFor(100))
402406
assertNotNull(activity.model.savedPictureUri)
403407
addUriToDeletionFileList(activity.model.savedPictureUri)
404408
val newFile = File(activity.model.savedPictureUri.toString())
@@ -450,7 +454,6 @@ class MenuFileActivityIntegrationTest {
450454
onData(allOf(`is`(instanceOf<Any>(String::class.java)), `is`("png")))
451455
.inRoot(RootMatchers.isPlatformPopup()).perform(click())
452456
onView(withText(R.string.save_button_text)).perform(click())
453-
onView(isRoot()).perform(waitFor(100))
454457
assertNotNull(activity.model.savedPictureUri)
455458
addUriToDeletionFileList(activity.model.savedPictureUri)
456459
onTopBarView().performOpenMoreOptions()
@@ -472,6 +475,7 @@ class MenuFileActivityIntegrationTest {
472475
.inRoot(RootMatchers.isPlatformPopup()).perform(click())
473476
onView(withText(R.string.save_button_text)).perform(click())
474477
onView(isRoot()).perform(waitFor(100))
478+
addFileToDeletionFileList("image$imageNumber", "png", Environment.DIRECTORY_PICTURES)
475479
onTopBarView().performOpenMoreOptions()
476480
onView(withText(R.string.menu_save_copy)).perform(click())
477481
imageNumber = launchActivityRule.activity.presenter.imageNumber
@@ -498,14 +502,14 @@ class MenuFileActivityIntegrationTest {
498502
val imageUri = resolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues)
499503
try {
500504
val fos = imageUri?.let { resolver.openOutputStream(it) }
501-
assertTrue(bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos))
505+
fos?.let { bitmap.compress(Bitmap.CompressFormat.JPEG, 100, it) }
506+
?.let { assertTrue(it) }
502507
assert(fos != null)
503508
fos?.close()
504509
} catch (e: IOException) {
505510
throw AssertionError("Picture file could not be created.", e)
506511
}
507-
val imageFile = File(imageUri?.path, "testfile.jpg")
508-
deletionFileList.add(imageFile)
512+
addUriToDeletionFileList(imageUri)
509513
return imageUri
510514
}
511515

@@ -534,15 +538,14 @@ class MenuFileActivityIntegrationTest {
534538
onView(withText(R.string.menu_save_image)).perform(click())
535539
onView(withText(R.string.save_button_text)).perform(click())
536540
onView(isRoot()).perform(waitFor(200))
541+
addUriToDeletionFileList(activity.model.savedPictureUri)
537542
val uri = activity.model.savedPictureUri
538543
onDrawingSurfaceView().perform(touchAt(MIDDLE))
539544
onTopBarView().performOpenMoreOptions()
540545
onView(withText(R.string.menu_save_image)).perform(click())
541546
onView(withText(R.string.save_button_text)).perform(click())
542-
onView(isRoot()).perform(waitFor(100))
543547
onView(withText(R.string.overwrite_button_text)).check(matches(isDisplayed()))
544548
onView(withText(R.string.overwrite_button_text)).perform(click())
545-
onView(isRoot()).perform(waitFor(500))
546549

547550
val oldFileName = uri?.path?.let { File(it).name }
548551
val newFileName = activity.model.savedPictureUri?.path?.let { File(it).name }
@@ -561,12 +564,14 @@ class MenuFileActivityIntegrationTest {
561564
onView(withText(R.string.menu_save_image)).perform(click())
562565
onView(withText(R.string.save_button_text)).perform(click())
563566
onView(isRoot()).perform(waitFor(200))
567+
addUriToDeletionFileList(activity.model.savedPictureUri)
564568
val uri = activity.model.savedPictureUri
565569
onDrawingSurfaceView().perform(touchAt(MIDDLE))
566570
onTopBarView().performOpenMoreOptions()
567571
onView(withText(R.string.menu_save_image)).perform(click())
568572
onView(withText(R.string.save_button_text)).perform(click())
569573
onView(isRoot()).perform(waitFor(100))
574+
addUriToDeletionFileList(activity.model.savedPictureUri)
570575
onView(withText(R.string.overwrite_button_text)).check(matches(isDisplayed()))
571576
onView(withText(R.string.overwrite_button_text)).perform(click())
572577
onView(isRoot()).perform(waitFor(500))
@@ -645,21 +650,35 @@ class MenuFileActivityIntegrationTest {
645650
assertEquals(oldFileName, newFileName)
646651

647652
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
648-
addFileToDeletionFileList(name, FileIO.fileType.value)
653+
addFileToDeletionFileList(name, FileIO.fileType.value, Environment.DIRECTORY_DOWNLOADS)
649654
} else {
650655
addUriToDeletionFileList(activity.model.savedPictureUri)
651656
}
652657
}
653658

654659
private fun addUriToDeletionFileList(uri: Uri?) {
655-
uri?.path?.let {
656-
deletionFileList.add(File(it))
660+
uri?.let {
661+
val path = MainActivityPresenter.getPathFromUri(activity, it)
662+
deletionFileList.add(File(path))
657663
}
658664
}
659665

660-
private fun addFileToDeletionFileList(fileName: String?, extension: String?) {
661-
val dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
662-
val file = File(dir, "$fileName.$extension")
666+
private fun addFileToDeletionFileList(
667+
fileName: String?,
668+
extension: String?,
669+
directory: String
670+
) {
671+
val file = createFileFromFileName(fileName, extension, directory)
663672
deletionFileList.add(file)
664673
}
674+
675+
private fun createFileFromFileName(
676+
fileName: String?,
677+
extension: String?,
678+
directory: String
679+
): File {
680+
val dir = Environment.getExternalStoragePublicDirectory(directory)
681+
val file = File(dir, "$fileName.$extension")
682+
return file
683+
}
665684
}

Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/OraFileIntentTest.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,9 @@ class OraFileIntentTest {
118118
}
119119
val imageUri = resolver!!.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues)
120120
try {
121-
val fos = Objects.requireNonNull(imageUri)?.let { resolver!!.openOutputStream(it) }
122-
Assert.assertTrue(bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos))
123-
assert(fos != null)
124-
fos!!.close()
121+
val fos = imageUri?.let { resolver?.openOutputStream(it) }
122+
Assert.assertTrue(bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos!!))
123+
fos.close()
125124
} catch (e: IOException) {
126125
throw AssertionError("Picture file could not be created.", e)
127126
}

Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/catroid/OpenedFromPocketCodeNewImageTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import org.catrobat.paintroid.common.PAINTROID_PICTURE_PATH
5656
import org.hamcrest.Matchers
5757
import org.junit.After
5858
import org.junit.Assert
59+
import org.junit.Assert.assertTrue
5960
import org.junit.Rule
6061
import org.junit.Test
6162
import java.io.File
@@ -175,9 +176,8 @@ class OpenedFromPocketCodeNewImageTest {
175176
val imageUri = Uri.fromFile(imageFile)
176177
try {
177178
val fos = activity?.contentResolver?.openOutputStream(Objects.requireNonNull(imageUri))
178-
Assert.assertTrue(bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos))
179-
assert(fos != null)
180-
fos?.close()
179+
assertTrue(bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos!!))
180+
fos.close()
181181
} catch (e: IOException) {
182182
throw AssertionError("Picture file could not be created.", e)
183183
}

0 commit comments

Comments
 (0)