From ca1270a318a67a5c51a0cee5ab54a45f2e472916 Mon Sep 17 00:00:00 2001 From: piotradamczyk5 <65554637+piotradamczyk5@users.noreply.github.com> Date: Thu, 16 Jul 2020 15:50:48 +0200 Subject: [PATCH] #835 Added printing Android devices list (#888) * #835 Added printing Android devices list * #835 Updated release notes * #835 Fixed PR comments --- release_notes.md | 5 +-- .../docs/ascii/flank.jar_-android.adoc | 3 ++ .../flank.jar_-firebase-test-android.adoc | 3 ++ .../main/kotlin/ftl/android/AndroidCatalog.kt | 41 +++++++------------ .../ftl/cli/firebase/test/AndroidCommand.kt | 4 +- .../test/android/AndroidDoctorCommand.kt | 3 +- .../android/models/AndroidModelsCommand.kt | 21 ++++++++++ .../models/AndroidModelsListCommand.kt | 31 ++++++++++++++ .../ftl/environment/ListAndroidDevices.kt | 38 +++++++++++++++++ .../ftl/environment/TestEnvironmentInfo.kt | 30 ++++++++++++++ .../main/kotlin/ftl/util/LogTableBuilder.kt | 14 +++---- .../main/kotlin/ftl/util/SystemOutColor.kt | 7 ++-- .../cli/firebase/test/AndroidCommandTest.kt | 28 ------------- .../models/AndroidModelsListCommandTest.kt | 29 +++++++++++++ .../environment/TestEnvironmentInfoTest.kt | 28 +++++++++++++ .../kotlin/ftl/util/LogTableBuilderTest.kt | 22 +++++++--- 16 files changed, 231 insertions(+), 76 deletions(-) create mode 100644 test_runner/src/main/kotlin/ftl/cli/firebase/test/android/models/AndroidModelsCommand.kt create mode 100644 test_runner/src/main/kotlin/ftl/cli/firebase/test/android/models/AndroidModelsListCommand.kt create mode 100644 test_runner/src/main/kotlin/ftl/environment/ListAndroidDevices.kt create mode 100644 test_runner/src/main/kotlin/ftl/environment/TestEnvironmentInfo.kt delete mode 100644 test_runner/src/test/kotlin/ftl/cli/firebase/test/AndroidCommandTest.kt create mode 100644 test_runner/src/test/kotlin/ftl/cli/firebase/test/android/models/AndroidModelsListCommandTest.kt create mode 100644 test_runner/src/test/kotlin/ftl/environment/TestEnvironmentInfoTest.kt diff --git a/release_notes.md b/release_notes.md index 4c7e0fc94a..3e7f236dc7 100644 --- a/release_notes.md +++ b/release_notes.md @@ -1,5 +1,6 @@ ## next (unreleased) -- +- [#890](https://github.com/Flank/flank/pull/890) Convert bitrise ubuntu workflow into GitHub actions. ([piotradamczyk5](https://github.com/piotradamczyk5)) +- [#876](https://github.com/Flank/flank/pull/876) Added option to print Android available devices to test against. ([piotradamczyk5](https://github.com/piotradamczyk5)) - - @@ -13,8 +14,6 @@ - [#862](https://github.com/Flank/flank/pull/862) Added printing outcome details. ([piotradamczyk5](https://github.com/piotradamczyk5), [jan-gogo](https://github.com/jan-gogo)) - [#876](https://github.com/Flank/flank/pull/876) Added --directories-to-pull validation and avoid making request with empty toolStepResult. ([piotradamczyk5](https://github.com/piotradamczyk5)) - [#875](https://github.com/Flank/flank/pull/875) Enhance permission denied exception logs. ([adamfilipow92](https://github.com/adamfilipow92), [pawelpasterz](https://github.com/pawelpasterz)) -- [#890](https://github.com/Flank/flank/pull/890) Convert bitrise ubuntu workflow into GitHub actions. ([piotradamczyk5](https://github.com/piotradamczyk5)) -- ## v20.06.2 - [#853](https://github.com/Flank/flank/pull/853) Store @Ignore tests in the JUnit XML without sending ignored tests to FTL. ([piotradamczyk5](https://github.com/piotradamczyk5), [adamfilipow92](https://github.com/adamfilipow92)) diff --git a/test_runner/docs/ascii/flank.jar_-android.adoc b/test_runner/docs/ascii/flank.jar_-android.adoc index fddab01889..0b71db91c3 100644 --- a/test_runner/docs/ascii/flank.jar_-android.adoc +++ b/test_runner/docs/ascii/flank.jar_-android.adoc @@ -32,6 +32,9 @@ flank.jar *doctor*:: Verifies flank firebase is setup correctly +*models*:: + Information about available models + // end::picocli-generated-man-section-commands[] // end::picocli-generated-full-manpage[] \ No newline at end of file diff --git a/test_runner/docs/ascii/flank.jar_-firebase-test-android.adoc b/test_runner/docs/ascii/flank.jar_-firebase-test-android.adoc index b4cd3f5144..dab0bb11f4 100644 --- a/test_runner/docs/ascii/flank.jar_-firebase-test-android.adoc +++ b/test_runner/docs/ascii/flank.jar_-firebase-test-android.adoc @@ -32,6 +32,9 @@ flank.jar *doctor*:: Verifies flank firebase is setup correctly +*models*:: + Information about available models + // end::picocli-generated-man-section-commands[] // end::picocli-generated-full-manpage[] \ No newline at end of file diff --git a/test_runner/src/main/kotlin/ftl/android/AndroidCatalog.kt b/test_runner/src/main/kotlin/ftl/android/AndroidCatalog.kt index 8dbace4b12..2e7a3228d0 100644 --- a/test_runner/src/main/kotlin/ftl/android/AndroidCatalog.kt +++ b/test_runner/src/main/kotlin/ftl/android/AndroidCatalog.kt @@ -2,6 +2,7 @@ package ftl.android import com.google.api.services.testing.model.AndroidDevice import com.google.api.services.testing.model.AndroidDeviceCatalog +import ftl.environment.asPrintableTable import ftl.gc.GcTesting import ftl.http.executeWithRetry @@ -14,42 +15,28 @@ object AndroidCatalog { private val modelMap: MutableMap> = mutableMapOf() private val versionMap: MutableMap> = mutableMapOf() - private fun androidDeviceCatalog(projectId: String): AndroidDeviceCatalog { - val cached = catalogMap[projectId] - if (cached != null) return cached - - val newCatalog = GcTesting.get.testEnvironmentCatalog() + private fun deviceCatalog(projectId: String) = catalogMap.getOrPut(projectId) { + GcTesting.get.testEnvironmentCatalog() .get("android") .setProjectId(projectId) - .executeWithRetry().androidDeviceCatalog - catalogMap[projectId] = newCatalog - return newCatalog + .executeWithRetry() + .androidDeviceCatalog } - fun androidModelIds(projectId: String): List { - val cached = modelMap[projectId] - if (cached != null) return cached + fun devicesCatalogAsTable(projectId: String) = deviceCatalog(projectId).models.asPrintableTable() - val newModels = androidDeviceCatalog(projectId).models.map { it.id } - modelMap[projectId] = newModels - return newModels - } + fun androidModelIds(projectId: String) = + modelMap.getOrPut(projectId) { deviceCatalog(projectId).models.map { it.id } } - fun androidVersionIds(projectId: String): List { - val cached = versionMap[projectId] - if (cached != null) return cached - - val newVersions = androidDeviceCatalog(projectId).versions.map { it.id } - versionMap[projectId] = newVersions - return newVersions - } + fun androidVersionIds(projectId: String) = + versionMap.getOrPut(projectId) { deviceCatalog(projectId).versions.map { it.id } } fun supportedDeviceConfig(modelId: String, versionId: String, projectId: String): DeviceConfigCheck { - val foundModel = androidDeviceCatalog(projectId).models.find { it.id == modelId } ?: return UnsupportedModelId + + val foundModel = deviceCatalog(projectId).models.find { it.id == modelId } ?: return UnsupportedModelId if (!androidVersionIds(projectId).contains(versionId)) return UnsupportedVersionId - val supportedVersionIds = foundModel.supportedVersionIds - supportedVersionIds?.let { + foundModel.supportedVersionIds?.let { if (!it.contains(versionId)) return IncompatibleModelVersion } ?: return UnsupportedModelId @@ -58,7 +45,7 @@ object AndroidCatalog { fun isVirtualDevice(device: AndroidDevice?, projectId: String): Boolean { val modelId = device?.androidModelId ?: return false - val form = androidDeviceCatalog(projectId).models.find { it.id == modelId }?.form ?: "PHYSICAL" + val form = deviceCatalog(projectId).models.find { it.id == modelId }?.form ?: "PHYSICAL" return form == "VIRTUAL" } } diff --git a/test_runner/src/main/kotlin/ftl/cli/firebase/test/AndroidCommand.kt b/test_runner/src/main/kotlin/ftl/cli/firebase/test/AndroidCommand.kt index b546c7d2e1..249bfbb3b4 100644 --- a/test_runner/src/main/kotlin/ftl/cli/firebase/test/AndroidCommand.kt +++ b/test_runner/src/main/kotlin/ftl/cli/firebase/test/AndroidCommand.kt @@ -2,6 +2,7 @@ package ftl.cli.firebase.test import ftl.cli.firebase.test.android.AndroidDoctorCommand import ftl.cli.firebase.test.android.AndroidRunCommand +import ftl.cli.firebase.test.android.models.AndroidModelsCommand import picocli.CommandLine import picocli.CommandLine.Command @@ -10,7 +11,8 @@ import picocli.CommandLine.Command synopsisHeading = "", subcommands = [ AndroidRunCommand::class, - AndroidDoctorCommand::class + AndroidDoctorCommand::class, + AndroidModelsCommand::class ], usageHelpAutoWidth = true ) diff --git a/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/AndroidDoctorCommand.kt b/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/AndroidDoctorCommand.kt index 4b1ba592da..372ce3c4b3 100644 --- a/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/AndroidDoctorCommand.kt +++ b/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/AndroidDoctorCommand.kt @@ -2,6 +2,7 @@ package ftl.cli.firebase.test.android import ftl.args.AndroidArgs import ftl.cli.firebase.test.processValidation +import ftl.config.FtlConstants import ftl.doctor.Doctor.validateYaml import java.nio.file.Paths import picocli.CommandLine.Command @@ -28,7 +29,7 @@ class AndroidDoctorCommand : Runnable { } @Option(names = ["-c", "--config"], description = ["YAML config file path"]) - var configPath: String = "./flank.yml" + var configPath: String = FtlConstants.defaultAndroidConfig @Option(names = ["-h", "--help"], usageHelp = true, description = ["Prints this help message"]) var usageHelpRequested: Boolean = false diff --git a/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/models/AndroidModelsCommand.kt b/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/models/AndroidModelsCommand.kt new file mode 100644 index 0000000000..f44b23e851 --- /dev/null +++ b/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/models/AndroidModelsCommand.kt @@ -0,0 +1,21 @@ +package ftl.cli.firebase.test.android.models + +import picocli.CommandLine + +@CommandLine.Command( + name = "models", + headerHeading = "", + synopsisHeading = "%n", + descriptionHeading = "%n@|bold,underline Description:|@%n%n", + parameterListHeading = "%n@|bold,underline Parameters:|@%n", + optionListHeading = "%n@|bold,underline Options:|@%n", + header = ["Information about available models"], + description = ["Information about available models. For example prints list of available models to test against"], + subcommands = [AndroidModelsListCommand::class], + usageHelpAutoWidth = true +) +class AndroidModelsCommand : Runnable { + override fun run() { + CommandLine.usage(AndroidModelsCommand(), System.out) + } +} diff --git a/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/models/AndroidModelsListCommand.kt b/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/models/AndroidModelsListCommand.kt new file mode 100644 index 0000000000..3ece9df415 --- /dev/null +++ b/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/models/AndroidModelsListCommand.kt @@ -0,0 +1,31 @@ +package ftl.cli.firebase.test.android.models + +import ftl.android.AndroidCatalog +import ftl.args.AndroidArgs +import ftl.config.FtlConstants +import picocli.CommandLine +import java.nio.file.Paths + +@CommandLine.Command( + name = "list", + headerHeading = "", + synopsisHeading = "%n", + descriptionHeading = "%n@|bold,underline Description:|@%n%n", + parameterListHeading = "%n@|bold,underline Parameters:|@%n", + optionListHeading = "%n@|bold,underline Options:|@%n", + header = ["Print current list of devices available to test against"], + description = ["Print current list of Android devices available to test against"], + usageHelpAutoWidth = true +) +class AndroidModelsListCommand : Runnable { + override fun run() { + val config = AndroidArgs.load(Paths.get(configPath)) + println(AndroidCatalog.devicesCatalogAsTable(config.project)) + } + + @CommandLine.Option(names = ["-c", "--config"], description = ["YAML config file path"]) + var configPath: String = FtlConstants.defaultAndroidConfig + + @CommandLine.Option(names = ["-h", "--help"], usageHelp = true, description = ["Prints this help message"]) + var usageHelpRequested: Boolean = false +} diff --git a/test_runner/src/main/kotlin/ftl/environment/ListAndroidDevices.kt b/test_runner/src/main/kotlin/ftl/environment/ListAndroidDevices.kt new file mode 100644 index 0000000000..ed87732d15 --- /dev/null +++ b/test_runner/src/main/kotlin/ftl/environment/ListAndroidDevices.kt @@ -0,0 +1,38 @@ +package ftl.environment + +import com.google.api.services.testing.model.AndroidModel +import ftl.util.SystemOutColor +import ftl.util.applyColorsUsing +import ftl.util.buildTable + +fun List.asPrintableTable() = createTestEnvironmentInfo().createAndroidDevicesTable() + +private fun List.createTestEnvironmentInfo() = + fold(mutableMapOf>()) { devicesInfo, androidDevice -> + devicesInfo.apply { + getOrCreateList(MODEL_ID).add(androidDevice.codename.orUnknown()) + getOrCreateList(MAKE).add(androidDevice.manufacturer.orUnknown()) + getOrCreateList(MODEL_NAME).add(androidDevice.name.orUnknown()) + getOrCreateList(FORM).add(androidDevice.form.orUnknown()) + getOrCreateList(RESOLUTION).add(androidDevice.resolution) + getOrCreateList(OS_VERSION_IDS).add(androidDevice.supportedVersionIds?.joinToString().orEmpty()) + getOrCreateList(TAGS).add(androidDevice.tags?.joinToString().orEmpty()) + } + } + +private fun TestEnvironmentInfo.createAndroidDevicesTable() = buildTable( + createTableColumnFor(MODEL_ID), + createTableColumnFor(MAKE), + createTableColumnFor(MODEL_NAME), + createTableColumnFor(FORM).applyColorsUsing(formToSystemOutColorMapper), + createTableColumnFor(RESOLUTION), + createTableColumnFor(OS_VERSION_IDS), + createTableColumnFor(TAGS).applyColorsUsing(tagToSystemOutColorMapper) +) + +private val AndroidModel.resolution + get() = if (screenX == null || screenY == null) "UNKNOWN" else "$screenY x $screenX" + +private val formToSystemOutColorMapper: (String) -> SystemOutColor = { + if (it == PHYSICAL_DEVICE) SystemOutColor.YELLOW else SystemOutColor.BLUE +} diff --git a/test_runner/src/main/kotlin/ftl/environment/TestEnvironmentInfo.kt b/test_runner/src/main/kotlin/ftl/environment/TestEnvironmentInfo.kt new file mode 100644 index 0000000000..b2f2ef2672 --- /dev/null +++ b/test_runner/src/main/kotlin/ftl/environment/TestEnvironmentInfo.kt @@ -0,0 +1,30 @@ +package ftl.environment + +import ftl.util.SystemOutColor +import ftl.util.TableColumn + +typealias TestEnvironmentInfo = MutableMap> + +internal fun TestEnvironmentInfo.getOrCreateList(key: String) = getOrPut(key) { mutableListOf() } + +internal fun TestEnvironmentInfo.createTableColumnFor(key: String) = TableColumn(key, getValue(key)) + +internal val tagToSystemOutColorMapper: (String) -> SystemOutColor = { + when { + it.contains("deprecated=") -> SystemOutColor.RED + it == "default" -> SystemOutColor.GREEN + it == "beta" -> SystemOutColor.YELLOW + else -> SystemOutColor.DEFAULT + } +} + +internal fun String?.orUnknown() = this ?: "UNKNOWN" + +const val MODEL_ID = "MODEL_ID" +const val MAKE = "MAKE" +const val MODEL_NAME = "MODEL_NAME" +const val FORM = "FORM" +const val RESOLUTION = "RESOLUTION" +const val OS_VERSION_IDS = "OS_VERSION_IDS" +const val TAGS = "TAGS" +const val PHYSICAL_DEVICE = "PHYSICAL" diff --git a/test_runner/src/main/kotlin/ftl/util/LogTableBuilder.kt b/test_runner/src/main/kotlin/ftl/util/LogTableBuilder.kt index d50ecb97b9..589dddb696 100644 --- a/test_runner/src/main/kotlin/ftl/util/LogTableBuilder.kt +++ b/test_runner/src/main/kotlin/ftl/util/LogTableBuilder.kt @@ -5,8 +5,8 @@ import com.google.common.annotations.VisibleForTesting data class TableColumn( val header: String, val data: List, - val columnSize: Int = ((data + header).maxBy { it.length }?.length ?: 0) + DEFAULT_COLUMN_PADDING, - val dataColor: List = listOf() + val dataColor: List = listOf(), + val columnSize: Int = ((data + header).maxBy { it.length }?.length ?: 0) + DEFAULT_COLUMN_PADDING ) private data class DataWithSize( @@ -47,7 +47,7 @@ private fun StringBuilder.startTable(rowSizes: List) { endChar = START_TABLE_END_CHAR, rowSizes = rowSizes ) - newLine() + appendln() } private fun StringBuilder.rowSeparator(rowSizes: List) { @@ -57,7 +57,7 @@ private fun StringBuilder.rowSeparator(rowSizes: List) { endChar = MIDDLE_TABLE_END_CHAR, rowSizes = rowSizes ) - newLine() + appendln() } private fun StringBuilder.appendData(tableColumns: Array) { @@ -99,7 +99,7 @@ private fun StringBuilder.appendDataRow(data: List) { append(data.center(size)) append(TABLE_VERTICAL_LINE) } - newLine() + appendln() } private fun String.center(columnSize: Int): String? { @@ -109,6 +109,4 @@ private fun String.center(columnSize: Int): String? { ) } -private fun StringBuilder.newLine() { - append(System.lineSeparator()) -} +inline fun TableColumn.applyColorsUsing(mapper: (String) -> SystemOutColor) = copy(dataColor = data.map(mapper)) diff --git a/test_runner/src/main/kotlin/ftl/util/SystemOutColor.kt b/test_runner/src/main/kotlin/ftl/util/SystemOutColor.kt index d6490abf91..2cabd36e70 100644 --- a/test_runner/src/main/kotlin/ftl/util/SystemOutColor.kt +++ b/test_runner/src/main/kotlin/ftl/util/SystemOutColor.kt @@ -1,10 +1,11 @@ package ftl.util -enum class SystemOutColor(val ansiCode: String) { +enum class SystemOutColor(private val ansiCode: String) { DEFAULT("\u001B[0m"), RED("\u001B[31m"), - BLUE("\u001B[34m"), - GREEN("\u001B[32m"); + GREEN("\u001B[32m"), + YELLOW("\u001B[33m"), + BLUE("\u001B[34m"); fun applyTo(value: String) = ansiCode + value + DEFAULT.ansiCode diff --git a/test_runner/src/test/kotlin/ftl/cli/firebase/test/AndroidCommandTest.kt b/test_runner/src/test/kotlin/ftl/cli/firebase/test/AndroidCommandTest.kt deleted file mode 100644 index 08420e16d9..0000000000 --- a/test_runner/src/test/kotlin/ftl/cli/firebase/test/AndroidCommandTest.kt +++ /dev/null @@ -1,28 +0,0 @@ -package ftl.cli.firebase.test - -import com.google.common.truth.Truth -import ftl.test.util.FlankTestRunner -import ftl.test.util.TestHelper.normalizeLineEnding -import org.junit.Rule -import org.junit.Test -import org.junit.contrib.java.lang.system.SystemOutRule -import org.junit.runner.RunWith - -@RunWith(FlankTestRunner::class) -class AndroidCommandTest { - @Rule - @JvmField - val systemOutRule: SystemOutRule = SystemOutRule().enableLog().muteForSuccessfulTests() - - @Test - fun androidCommandPrintsHelp() { - AndroidCommand().run() - val output = systemOutRule.log.normalizeLineEnding() - Truth.assertThat(output).startsWith( - "android [COMMAND]\n" + - "Commands:\n" + - " run Run tests on Firebase Test Lab\n" + - " doctor Verifies flank firebase is setup correctly\n" - ) - } -} diff --git a/test_runner/src/test/kotlin/ftl/cli/firebase/test/android/models/AndroidModelsListCommandTest.kt b/test_runner/src/test/kotlin/ftl/cli/firebase/test/android/models/AndroidModelsListCommandTest.kt new file mode 100644 index 0000000000..959301174e --- /dev/null +++ b/test_runner/src/test/kotlin/ftl/cli/firebase/test/android/models/AndroidModelsListCommandTest.kt @@ -0,0 +1,29 @@ +package ftl.cli.firebase.test.android.models + +import com.google.common.truth.Truth.assertThat +import ftl.config.FtlConstants +import org.junit.Test +import picocli.CommandLine + +class AndroidModelsListCommandTest { + + @Test + fun androidModelsListCommandOptions() { + val cmd = AndroidModelsListCommand() + assertThat(cmd.configPath).isEqualTo(FtlConstants.defaultAndroidConfig) + cmd.configPath = "tmp" + assertThat(cmd.configPath).isEqualTo("tmp") + + assertThat(cmd.usageHelpRequested).isFalse() + cmd.usageHelpRequested = true + assertThat(cmd.usageHelpRequested).isTrue() + } + + @Test + fun androidModelsListCommandShouldParseConfig() { + val cmd = AndroidModelsListCommand() + CommandLine(cmd).parseArgs("--config=a") + + assertThat(cmd.configPath).isEqualTo("a") + } +} diff --git a/test_runner/src/test/kotlin/ftl/environment/TestEnvironmentInfoTest.kt b/test_runner/src/test/kotlin/ftl/environment/TestEnvironmentInfoTest.kt new file mode 100644 index 0000000000..202f720142 --- /dev/null +++ b/test_runner/src/test/kotlin/ftl/environment/TestEnvironmentInfoTest.kt @@ -0,0 +1,28 @@ +package ftl.environment + +import com.google.common.truth.Truth.assertThat +import ftl.util.SystemOutColor +import org.junit.Test + +class TestEnvironmentInfoTest { + + @Test + fun `should properly map tag values to colors`() { + // given + val testData = listOf( + "deprecated=11" to SystemOutColor.RED, + "default" to SystemOutColor.GREEN, + "beta" to SystemOutColor.YELLOW, + "" to SystemOutColor.DEFAULT + ) + val expectedColors = testData.map { (_, color) -> color } + + // when + val actualColors = testData.map { (data, _) -> data }.map(tagToSystemOutColorMapper) + + // then + actualColors.forEachIndexed { index, systemOutColor -> + assertThat(systemOutColor).isEqualTo(expectedColors[index]) + } + } +} diff --git a/test_runner/src/test/kotlin/ftl/util/LogTableBuilderTest.kt b/test_runner/src/test/kotlin/ftl/util/LogTableBuilderTest.kt index 52b388fd19..4ffcbe082c 100644 --- a/test_runner/src/test/kotlin/ftl/util/LogTableBuilderTest.kt +++ b/test_runner/src/test/kotlin/ftl/util/LogTableBuilderTest.kt @@ -6,10 +6,10 @@ import org.junit.Test internal class LogTableBuilderTest { private val sampleColumns = arrayOf( - TableColumn("header1", listOf("value1"), 10), - TableColumn("header2", listOf("value2"), 15), - TableColumn("header3", listOf("value3"), 20), - TableColumn("header4", listOf("value4"), 21) + TableColumn("header1", listOf("value1"), columnSize = 10), + TableColumn("header2", listOf("value2"), columnSize = 15), + TableColumn("header3", listOf("value3"), columnSize = 20), + TableColumn("header4", listOf("value4"), columnSize = 21) ) @Test @@ -111,7 +111,7 @@ internal class LogTableBuilderTest { } @Test - fun `Should not contains middle separator when having just 1 column`() { + fun `should not contains middle separator when having just 1 column`() { // when val table = buildTable(sampleColumns.first()) @@ -120,4 +120,16 @@ internal class LogTableBuilderTest { table.contains(START_TABLE_MIDDLE_CHAR) || table.contains(MIDDLE_TABLE_MIDDLE_CHAR) || table.contains(END_TABLE_MIDDLE_CHAR) ).isFalse() } + + @Test + fun `should apply colors`() { + // given + val expectedColor = SystemOutColor.GREEN + + // when + val actual = sampleColumns.map { it.applyColorsUsing { expectedColor } } + + // then + actual.forEach { tableColumn -> assertThat(tableColumn.dataColor.all { it == expectedColor }).isTrue() } + } }