Skip to content

Commit

Permalink
finish converting tests to kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanCheshire committed Sep 11, 2024
1 parent ddd7f13 commit d16d4e8
Show file tree
Hide file tree
Showing 17 changed files with 526 additions and 513 deletions.

This file was deleted.

This file was deleted.

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, "") }
}
}
Loading

0 comments on commit d16d4e8

Please sign in to comment.