🔀 Merge branch 'release/v82'
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / core / SoneParserTest.kt
index 0648d1f..38419a2 100644 (file)
@@ -5,6 +5,7 @@ import com.google.common.base.Optional.*
 import freenet.crypt.*
 import freenet.keys.InsertableClientSSK.*
 import net.pterodactylus.sone.data.*
+import net.pterodactylus.sone.data.impl.AlbumImpl
 import net.pterodactylus.sone.database.memory.*
 import net.pterodactylus.sone.freenet.wot.*
 import net.pterodactylus.sone.test.*
@@ -41,6 +42,7 @@ class SoneParserTest {
                whenever(sone.identity).thenReturn(identity)
                whenever(sone.requestUri).thenAnswer { clientSSK.uri.setKeyType("USK").setDocName("Sone") }
                whenever(sone.time).thenReturn(currentTimeMillis() - DAYS.toMillis(1))
+               whenever(sone.rootAlbum).thenReturn(AlbumImpl(sone))
        }
 
        @Test
@@ -398,10 +400,18 @@ class SoneParserTest {
        }
 
        @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.parsing.duration")
+               val histogram = metricRegistry.histogram("sone.parse.duration")
                assertThat(histogram.count, equalTo(1L))
        }