-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
112 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
omniNotes/src/androidTest/java/it/feio/android/omninotes/utils/BitmapHelperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright (C) 2013-2019 Federico Iosue ([email protected]) | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package it.feio.android.omninotes.utils; | ||
|
||
import static it.feio.android.omninotes.utils.ConstantsBase.MIME_TYPE_IMAGE; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
|
||
import android.graphics.Bitmap; | ||
import android.net.Uri; | ||
import android.os.Looper; | ||
import android.support.test.internal.runner.junit4.statement.UiThreadStatement; | ||
import android.support.test.runner.AndroidJUnit4; | ||
import it.feio.android.omninotes.BaseAndroidTestCase; | ||
import it.feio.android.omninotes.models.Attachment; | ||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.TemporaryFolder; | ||
import org.junit.runner.RunWith; | ||
|
||
@RunWith(AndroidJUnit4.class) | ||
public class BitmapHelperTest extends BaseAndroidTestCase { | ||
|
||
@Rule | ||
public TemporaryFolder tempFolder = new TemporaryFolder(); | ||
|
||
private Attachment attachment; | ||
|
||
@Before | ||
public void setUp () throws IOException { | ||
File bitmapFile = tempFolder.newFile("bitmapFile.bmp"); | ||
|
||
Bitmap bmp = Bitmap.createBitmap(100, 200, Bitmap.Config.ARGB_8888); | ||
FileOutputStream out = new FileOutputStream(bitmapFile); | ||
bmp.compress(Bitmap.CompressFormat.PNG, 100, out); | ||
|
||
attachment = new Attachment(Uri.fromFile(bitmapFile), MIME_TYPE_IMAGE); | ||
} | ||
|
||
@Test | ||
public void getBitmapFromAttachment_backgroundThread () { | ||
Bitmap bmp = BitmapHelper.getBitmapFromAttachment(testContext, attachment, 100, 100); | ||
assertNotEquals("Thread MUST be a background one", Looper.getMainLooper(), Looper.myLooper()); | ||
assertNotNull("Bitmap should not be null", bmp); | ||
} | ||
|
||
@Test | ||
public void getBitmapFromAttachment_mainThread () throws Throwable { | ||
UiThreadStatement.runOnUiThread(() -> { | ||
Bitmap bmp = BitmapHelper.getBitmapFromAttachment(testContext, attachment, 100, 100); | ||
assertEquals("Thread MUST be a the main one", Looper.getMainLooper(), Looper.myLooper()); | ||
assertNotNull("Bitmap should not be null", bmp); | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters