2020-08-06 11:07:25 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2020 dorkbox, llc
|
|
|
|
* Copyright (C) 2014 ZeroTurnaround <support@zeroturnaround.com>
|
|
|
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2020-08-07 23:22:31 +02:00
|
|
|
package dorkbox.executor
|
2020-08-06 11:07:25 +02:00
|
|
|
|
|
|
|
import dorkbox.executor.stream.LogOutputStream
|
2022-01-20 00:04:59 +01:00
|
|
|
import org.junit.jupiter.api.Assertions
|
|
|
|
import org.junit.jupiter.api.Test
|
2020-08-06 11:07:25 +02:00
|
|
|
import java.io.IOException
|
|
|
|
import java.io.UnsupportedEncodingException
|
|
|
|
import java.util.*
|
|
|
|
|
|
|
|
class LogOutputStreamTest {
|
|
|
|
@Throws(UnsupportedEncodingException::class, IOException::class)
|
|
|
|
private fun testLogOutputStream(multiLineString: String, vararg expectedLines: String) {
|
|
|
|
val processedLines: MutableList<String> = ArrayList()
|
|
|
|
val logOutputStream: LogOutputStream = object : LogOutputStream() {
|
|
|
|
override fun processLine(line: String) {
|
|
|
|
processedLines.add(line)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-03 20:23:01 +01:00
|
|
|
logOutputStream.use { stream ->
|
|
|
|
stream.write(multiLineString.toByteArray(charset("UTF-8")))
|
2020-08-06 11:07:25 +02:00
|
|
|
}
|
|
|
|
|
2022-01-20 00:04:59 +01:00
|
|
|
Assertions.assertEquals(listOf(*expectedLines), processedLines)
|
2020-08-06 11:07:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Throws(UnsupportedEncodingException::class, IOException::class)
|
|
|
|
fun testSimple() {
|
|
|
|
testLogOutputStream("foo", "foo")
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Throws(UnsupportedEncodingException::class, IOException::class)
|
|
|
|
fun testNewLine() {
|
|
|
|
testLogOutputStream("foo\nbar", "foo", "bar")
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Throws(UnsupportedEncodingException::class, IOException::class)
|
|
|
|
fun testNewLineWithMultipleLines() {
|
|
|
|
testLogOutputStream("foo1\nbar1\nfoo2\nbar2", "foo1", "bar1", "foo2", "bar2")
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Throws(UnsupportedEncodingException::class, IOException::class)
|
|
|
|
fun testCarriageReturn() {
|
|
|
|
testLogOutputStream("foo\rbar", "foo", "bar")
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Throws(UnsupportedEncodingException::class, IOException::class)
|
|
|
|
fun testCarriageReturnWithMultipleLines() {
|
|
|
|
testLogOutputStream("foo1\rbar1\rfoo2\rbar2", "foo1", "bar1", "foo2", "bar2")
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Throws(UnsupportedEncodingException::class, IOException::class)
|
|
|
|
fun testCarriageReturnAndNewLine() {
|
|
|
|
testLogOutputStream("foo\r\nbar", "foo", "bar")
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Throws(UnsupportedEncodingException::class, IOException::class)
|
|
|
|
fun testCarriageReturnAndNewLineWithMultipleLines() {
|
|
|
|
testLogOutputStream("foo1\r\nbar1\r\nfoo2\r\nbar2", "foo1", "bar1", "foo2", "bar2")
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Throws(UnsupportedEncodingException::class, IOException::class)
|
|
|
|
fun testTwoNewLines() {
|
|
|
|
testLogOutputStream("foo\n\nbar", "foo", "bar")
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Throws(UnsupportedEncodingException::class, IOException::class)
|
|
|
|
fun testNewLineAtTheEnd() {
|
|
|
|
testLogOutputStream("foo\n", "foo")
|
|
|
|
}
|
|
|
|
}
|