1
+ /*
2
+ * Copyright © All Contributors. See LICENSE and AUTHORS in the root directory for details.
3
+ */
4
+
5
+ package at.bitfire.davdroid.log
6
+
7
+ import org.junit.Assert.assertEquals
8
+ import org.junit.Assert.assertTrue
9
+ import org.junit.Test
10
+ import java.util.logging.Formatter
11
+ import java.util.logging.Level
12
+ import java.util.logging.LogRecord
13
+
14
+ class StringHandlerTest {
15
+
16
+ @Test
17
+ fun test_logSomeText () {
18
+ val handler = StringHandler (1000 )
19
+ handler.publish(LogRecord (Level .INFO , " Line 1" ))
20
+ handler.publish(LogRecord (Level .FINEST , " Line 2" ))
21
+ val str = handler.toString()
22
+ assertTrue(str.contains(" Line 1\n " ))
23
+ assertTrue(str.contains(" Line 2\n " ))
24
+ }
25
+
26
+ @Test
27
+ fun test_logSomeText_ExceedingMaxSize () {
28
+ val handler = StringHandler (10 ).apply {
29
+ formatter = object : Formatter () {
30
+ override fun format (record : LogRecord ) = record.message
31
+ }
32
+ }
33
+ handler.publish(LogRecord (Level .INFO , " Line 1 Line 1 Line 1 Line 1 Line 1" ))
34
+ handler.publish(LogRecord (Level .FINEST , " Line 2" ))
35
+
36
+ val str = handler.toString()
37
+ assertEquals(10 , handler.toString().length)
38
+ assertEquals(" Line [...]" , str)
39
+ }
40
+
41
+ }
0 commit comments