Skip to content

Commit

Permalink
Rename exception class to better clarify intent
Browse files Browse the repository at this point in the history
  • Loading branch information
MrHadiSatrio committed Sep 18, 2024
1 parent 19c4460 commit 6fd2859
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@

package com.spotify.ruler.common.veritication

class VerificationException(label: String, size: Long, threshold: Long) :
class SizeExceededException(label: String, size: Long, threshold: Long) :
Exception("$label size exceeds the threshold by ${size - threshold} bytes.")
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ class Verificator(private val config: VerificationConfig) {
val downloadSize = components.sumOf(AppFile::downloadSize)
val downloadSizeThreshold = config.downloadSizeThreshold
if (downloadSize > downloadSizeThreshold) {
throw VerificationException("Download", downloadSize, downloadSizeThreshold)
throw SizeExceededException("Download", downloadSize, downloadSizeThreshold)
}

val installSize = components.sumOf(AppFile::installSize)
val installSizeThreshold = config.installSizeThreshold
if (installSize > installSizeThreshold) {
throw VerificationException("Install", installSize, installSizeThreshold)
throw SizeExceededException("Install", installSize, installSizeThreshold)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

package com.spotify.ruler.common.verificator

import com.spotify.ruler.common.veritication.SizeExceededException
import com.spotify.ruler.common.veritication.VerificationConfig
import com.spotify.ruler.common.veritication.VerificationException
import com.spotify.ruler.common.veritication.Verificator
import com.spotify.ruler.models.AppFile
import com.spotify.ruler.models.FileType
Expand All @@ -31,35 +31,35 @@ class VerificatorTest {
private val verificator = Verificator(config)

@Test
fun `Download size under threshold does not trigger VerificationException`() {
fun `Download size under threshold does not trigger SizeExceededException`() {
val downloadSize = config.downloadSizeThreshold / 2
val appFiles = generateAppFiles(downloadSize)

assertDoesNotThrow { verificator.verify(appFiles) }
}

@Test
fun `Download size exceeding threshold triggers VerificationException`() {
fun `Download size exceeding threshold triggers SizeExceededException`() {
val downloadSize = config.downloadSizeThreshold * 2
val appFiles = generateAppFiles(downloadSize)

assertThrows<VerificationException> { verificator.verify(appFiles) }
assertThrows<SizeExceededException> { verificator.verify(appFiles) }
}

@Test
fun `Install size under threshold does not trigger VerificationException`() {
fun `Install size under threshold does not trigger SizeExceededException`() {
val installSize = config.installSizeThreshold / 2
val appFiles = generateAppFiles(config.downloadSizeThreshold, installSize)

assertDoesNotThrow { verificator.verify(appFiles) }
}

@Test
fun `Install size exceeding threshold triggers VerificationException`() {
fun `Install size exceeding threshold triggers SizeExceededException`() {
val installSize = config.downloadSizeThreshold * 2
val appFiles = generateAppFiles(config.downloadSizeThreshold, installSize)

assertThrows<VerificationException> { verificator.verify(appFiles) }
assertThrows<SizeExceededException> { verificator.verify(appFiles) }
}

private fun generateAppFiles(
Expand Down

0 comments on commit 6fd2859

Please sign in to comment.