Skip to content

Commit

Permalink
don't register sprites at IconRegistry
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskn committed Nov 3, 2024
1 parent 656ea75 commit 85bd06d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,15 @@ object IconRegistry {
* @throws MalformedURLException if url is invalid
*/
fun addIcon(name: String, url: String) {
validate(name, url)
iconNameToIconUrl[name.lowercase()] = URI(url).toURL()
}

internal fun validate(name: String, url: String) {
require(name.isNotBlank()) { "Icon name cannot be blank" }
require(url.endsWith(PUML_FILE_EXTENSION)) {
"Icon URL needs to point to .puml file but was $url"
}
iconNameToIconUrl[name.lowercase()] = URI(url).toURL()
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ data class PUmlSprite(
internal val colorValidated: String? = color?.let { toValidColor(color) }

init {
// TODO is the registry still needed?
IconRegistry.addIcon(name, url)
IconRegistry.validate(name, url)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class SpriteTest {
@Test
fun `PumlSprite is serialized and deserialized correctly`() {
val expectedSprite = PUmlSprite(
name = "android",
name = "some technology",
url = "https://test.com/sprites/android-icon.puml",
)
val style = ElementStyle("test", sprite = expectedSprite)
Expand All @@ -29,7 +29,7 @@ class SpriteTest {
@Test
fun `PumlSprite is serialized and deserialized correctly when color is used`() {
val expectedSprite = PUmlSprite(
name = "android",
name = "some technology",
url = "https://test.com/sprites/android-icon.puml",
color = "green"
)
Expand All @@ -41,7 +41,7 @@ class SpriteTest {
@Test
fun `PumlSprite is serialized and deserialized correctly when scale is used`() {
val expectedSprite = PUmlSprite(
name = "android",
name = "some technology",
url = "https://test.com/sprites/android-icon.puml",
scale = 0.4
)
Expand All @@ -53,7 +53,7 @@ class SpriteTest {
@Test
fun `PumlSprite is serialized and deserialized correctly when scale and color is used`() {
val expectedSprite = PUmlSprite(
name = "android",
name = "some technology",
url = "https://test.com/sprites/android-icon.puml",
scale = 0.4,
color = "green"
Expand Down

0 comments on commit 85bd06d

Please sign in to comment.