From 56b0454be450b43186b627b917f9e80231889f21 Mon Sep 17 00:00:00 2001 From: Hadi Satrio Date: Wed, 18 Sep 2024 21:39:24 +0700 Subject: [PATCH] Rename exception class to better clarify intent --- ...cationException.kt => SizeExceededException.kt} | 2 +- .../ruler/common/veritication/Verificator.kt | 4 ++-- .../ruler/common/verificator/VerificatorTest.kt | 14 +++++++------- 3 files changed, 10 insertions(+), 10 deletions(-) rename ruler-common/src/main/java/com/spotify/ruler/common/veritication/{VerificationException.kt => SizeExceededException.kt} (91%) diff --git a/ruler-common/src/main/java/com/spotify/ruler/common/veritication/VerificationException.kt b/ruler-common/src/main/java/com/spotify/ruler/common/veritication/SizeExceededException.kt similarity index 91% rename from ruler-common/src/main/java/com/spotify/ruler/common/veritication/VerificationException.kt rename to ruler-common/src/main/java/com/spotify/ruler/common/veritication/SizeExceededException.kt index 2c58ab1..cf94ced 100644 --- a/ruler-common/src/main/java/com/spotify/ruler/common/veritication/VerificationException.kt +++ b/ruler-common/src/main/java/com/spotify/ruler/common/veritication/SizeExceededException.kt @@ -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.") diff --git a/ruler-common/src/main/java/com/spotify/ruler/common/veritication/Verificator.kt b/ruler-common/src/main/java/com/spotify/ruler/common/veritication/Verificator.kt index 41585e8..f0ee71a 100644 --- a/ruler-common/src/main/java/com/spotify/ruler/common/veritication/Verificator.kt +++ b/ruler-common/src/main/java/com/spotify/ruler/common/veritication/Verificator.kt @@ -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) } } } diff --git a/ruler-common/src/test/kotlin/com/spotify/ruler/common/verificator/VerificatorTest.kt b/ruler-common/src/test/kotlin/com/spotify/ruler/common/verificator/VerificatorTest.kt index 2f9101c..3be30e3 100644 --- a/ruler-common/src/test/kotlin/com/spotify/ruler/common/verificator/VerificatorTest.kt +++ b/ruler-common/src/test/kotlin/com/spotify/ruler/common/verificator/VerificatorTest.kt @@ -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 @@ -31,7 +31,7 @@ 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) @@ -39,15 +39,15 @@ class VerificatorTest { } @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 { verificator.verify(appFiles) } + assertThrows { 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) @@ -55,11 +55,11 @@ class VerificatorTest { } @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 { verificator.verify(appFiles) } + assertThrows { verificator.verify(appFiles) } } private fun generateAppFiles(