-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
ddd7f13
commit d16d4e8
Showing
17 changed files
with
526 additions
and
513 deletions.
There are no files selected for viewing
63 changes: 0 additions & 63 deletions
63
...java/com/github/natche/gravatarjavaclient/avatar/GravatarAvatarRequestImageSaverTest.java
This file was deleted.
Oops, something went wrong.
450 changes: 0 additions & 450 deletions
450
src/test/java/com/github/natche/gravatarjavaclient/avatar/GravatarAvatarRequestTest.java
This file was deleted.
Oops, something went wrong.
File renamed without changes.
59 changes: 59 additions & 0 deletions
59
...kotlin/com/github/natche/gravatarjavaclient/avatar/GravatarAvatarRequestImageSaverTest.kt
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,59 @@ | ||
package com.github.natche.gravatarjavaclient.avatar | ||
|
||
import com.github.natche.gravatarjavaclient.exceptions.GravatarJavaClientException | ||
import com.google.common.collect.ImmutableList | ||
import org.junit.jupiter.api.Assertions | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import org.mockito.Mockito | ||
import java.awt.image.BufferedImage | ||
import java.io.File | ||
|
||
/** | ||
* Tests for the [GravatarAvatarRequestImageSaver]. | ||
*/ | ||
class GravatarAvatarRequestImageSaverTest { | ||
/** | ||
* Sets the SUPPORTED_IMAGE_FORMATS to an ArrayList containing a blank string which will cause | ||
* the image write to fail. This is performed for testing coverage purposes. | ||
*/ | ||
@BeforeEach | ||
fun injectBlankFormat() { | ||
try { | ||
val formatsField = GravatarAvatarRequestImageSaver::class.java | ||
.getDeclaredField("SUPPORTED_IMAGE_FORMATS") | ||
formatsField.isAccessible = true | ||
@Suppress("UNCHECKED_CAST") | ||
val originalList = formatsField[GravatarAvatarRequestImageSaver.INSTANCE] as ImmutableList<String> | ||
val mutableList: MutableList<String> = ArrayList(originalList) | ||
mutableList.add("") | ||
formatsField[GravatarAvatarRequestImageSaver.INSTANCE] = ImmutableList.copyOf(mutableList) | ||
} catch (e: Exception) { | ||
// Swallow | ||
} | ||
} | ||
|
||
/** | ||
* Tests for the save to method. | ||
*/ | ||
@Test | ||
fun testSaveTo() { | ||
Assertions.assertThrows( | ||
NullPointerException::class.java | ||
) { GravatarAvatarRequestImageSaver.INSTANCE.saveTo(null, null, null) } | ||
val mockImage = Mockito.mock(BufferedImage::class.java) | ||
Assertions.assertThrows( | ||
NullPointerException::class.java | ||
) { GravatarAvatarRequestImageSaver.INSTANCE.saveTo(mockImage, null, null) } | ||
val mockFile = Mockito.mock(File::class.java) | ||
Assertions.assertThrows( | ||
NullPointerException::class.java | ||
) { GravatarAvatarRequestImageSaver.INSTANCE.saveTo(mockImage, mockFile, null) } | ||
Assertions.assertThrows( | ||
IllegalArgumentException::class.java | ||
) { GravatarAvatarRequestImageSaver.INSTANCE.saveTo(mockImage, File("."), null) } | ||
Assertions.assertThrows( | ||
GravatarJavaClientException::class.java | ||
) { GravatarAvatarRequestImageSaver.INSTANCE.saveTo(mockImage, mockFile, "") } | ||
} | ||
} |
Oops, something went wrong.