X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FSoneParserTest.kt;h=336d8555d9526568be3fce528433ecd2423f63eb;hb=a01e3b29a9dab0f8db0fbbdf718747229300781b;hp=3a7010a19e0abc7b110213c538a8f4a9a423dfe6;hpb=388401b79c3eacd94eb070b5c8ebab6055740246;p=Sone.git diff --git a/src/test/kotlin/net/pterodactylus/sone/core/SoneParserTest.kt b/src/test/kotlin/net/pterodactylus/sone/core/SoneParserTest.kt index 3a7010a..336d855 100644 --- a/src/test/kotlin/net/pterodactylus/sone/core/SoneParserTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/core/SoneParserTest.kt @@ -1,5 +1,6 @@ package net.pterodactylus.sone.core +import com.codahale.metrics.* import com.google.common.base.Optional.* import freenet.crypt.* import freenet.keys.InsertableClientSSK.* @@ -21,7 +22,8 @@ import kotlin.test.* class SoneParserTest { private val database = MemoryDatabase(Configuration(MapConfigurationBackend())) - private val soneParser = SoneParser(database) + private val metricRegistry = MetricRegistry() + private val soneParser = SoneParser(database, metricRegistry) private val sone = mock() @BeforeTest @@ -395,4 +397,20 @@ class SoneParserTest { assertThat(sone.profile.avatar, equalTo("image-id")) } + @Test + fun `unsuccessful parsing does not add a histogram entry`() { + val inputStream = javaClass.getResourceAsStream("sone-parser-with-invalid-image-height.xml") + assertThat(soneParser.parseSone(sone, inputStream), nullValue()) + val histogram = metricRegistry.histogram("sone.parse.duration") + assertThat(histogram.count, equalTo(0L)) + } + + @Test + fun `successful parsing adds histogram entry`() { + val inputStream = javaClass.getResourceAsStream("sone-parser-without-images.xml") + assertThat(soneParser.parseSone(sone, inputStream), notNullValue()) + val histogram = metricRegistry.histogram("sone.parse.duration") + assertThat(histogram.count, equalTo(1L)) + } + }