diff --git a/src/test/kotlin/net/theevilreaper/dartpoet/code/writer/ParameterWriterTest.kt b/src/test/kotlin/net/theevilreaper/dartpoet/code/writer/ParameterWriterTest.kt index 9079490e..d9513404 100644 --- a/src/test/kotlin/net/theevilreaper/dartpoet/code/writer/ParameterWriterTest.kt +++ b/src/test/kotlin/net/theevilreaper/dartpoet/code/writer/ParameterWriterTest.kt @@ -3,6 +3,7 @@ package net.theevilreaper.dartpoet.code.writer import com.google.common.truth.Truth.assertThat import net.theevilreaper.dartpoet.parameter.ParameterSpec import net.theevilreaper.dartpoet.type.ParameterizedTypeName.Companion.parameterizedBy +import net.theevilreaper.dartpoet.util.EMPTY_STRING import org.junit.jupiter.api.Assertions.* import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.Test @@ -51,7 +52,7 @@ class ParameterWriterTest { fun `test invalid parameter definition`() { assertThrows( IllegalStateException::class.java, - { ParameterSpec.builder("").build() }, + { ParameterSpec.builder(EMPTY_STRING).build() }, "The name of a parameter can't be empty" ) } diff --git a/src/test/kotlin/net/theevilreaper/dartpoet/directive/DirectiveFactoryTest.kt b/src/test/kotlin/net/theevilreaper/dartpoet/directive/DirectiveFactoryTest.kt index b8b94f26..06cd69a1 100644 --- a/src/test/kotlin/net/theevilreaper/dartpoet/directive/DirectiveFactoryTest.kt +++ b/src/test/kotlin/net/theevilreaper/dartpoet/directive/DirectiveFactoryTest.kt @@ -1,10 +1,13 @@ package net.theevilreaper.dartpoet.directive +import net.theevilreaper.dartpoet.util.EMPTY_STRING +import net.theevilreaper.dartpoet.util.SPACE_STRING import org.junit.jupiter.api.Assertions.* import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.assertThrows import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.Arguments +import org.junit.jupiter.params.provider.EnumSource import org.junit.jupiter.params.provider.MethodSource import java.util.stream.Stream @@ -16,16 +19,22 @@ class DirectiveFactoryTest { @JvmStatic private fun invalidFactoryUsage() = Stream.of( Arguments.of( - { DirectiveFactory.create(DirectiveType.LIBRARY, "") }, + { DirectiveFactory.create(DirectiveType.LIBRARY, EMPTY_STRING) }, "The library directive doesn't support a cast type or import cast. Please use #createLibDirective method instead" ), Arguments.of( - { DirectiveFactory.create(DirectiveType.LIBRARY, "", castType = CastType.HIDE) }, + { DirectiveFactory.create(DirectiveType.LIBRARY, EMPTY_STRING, castType = CastType.HIDE) }, "The library directive doesn't support a cast type or import cast. Please use #createLibDirective method instead" ), ) } + @ParameterizedTest + @EnumSource(value = DirectiveType::class, mode = EnumSource.Mode.MATCH_ALL) + fun `test invalid import mapping`(directiveType: DirectiveType) { + assertThrows { DirectiveFactory.create(directiveType, SPACE_STRING) } + } + @ParameterizedTest @MethodSource("invalidFactoryUsage") fun `test invalid factory usage`(current: () -> Directive, expectedMessage: String) { diff --git a/src/test/kotlin/net/theevilreaper/dartpoet/directive/DirectiveSortTest.kt b/src/test/kotlin/net/theevilreaper/dartpoet/directive/DirectiveSortTest.kt index fc060200..e64743df 100644 --- a/src/test/kotlin/net/theevilreaper/dartpoet/directive/DirectiveSortTest.kt +++ b/src/test/kotlin/net/theevilreaper/dartpoet/directive/DirectiveSortTest.kt @@ -1,6 +1,7 @@ package net.theevilreaper.dartpoet.directive import net.theevilreaper.dartpoet.util.DirectiveOrdering +import net.theevilreaper.dartpoet.util.EMPTY_STRING import org.junit.jupiter.api.DisplayName import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.Arguments @@ -82,7 +83,7 @@ class DirectiveSortTest { return directives.map { var directive: String = it.asString() for (placeholder in placeholders) { - directive = directive.replace(placeholder, "") + directive = directive.replace(placeholder, EMPTY_STRING) } return@map directive }.toList() diff --git a/src/test/kotlin/net/theevilreaper/dartpoet/directive/DirectiveTest.kt b/src/test/kotlin/net/theevilreaper/dartpoet/directive/DirectiveTest.kt index 5cbd1778..bb2ca356 100644 --- a/src/test/kotlin/net/theevilreaper/dartpoet/directive/DirectiveTest.kt +++ b/src/test/kotlin/net/theevilreaper/dartpoet/directive/DirectiveTest.kt @@ -1,12 +1,14 @@ package net.theevilreaper.dartpoet.directive +import net.theevilreaper.dartpoet.util.EMPTY_STRING +import net.theevilreaper.dartpoet.util.SPACE_STRING import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Assertions.assertThrows import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertThrows import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.Arguments +import org.junit.jupiter.params.provider.EnumSource import org.junit.jupiter.params.provider.MethodSource import java.util.stream.Stream @@ -24,11 +26,11 @@ class DirectiveTest { @JvmStatic private fun directivesWhichThrowsException() = Stream.of( - Arguments.of({ DartDirective(" ") }, EMPTY_NAME_MESSAGE), - Arguments.of({ LibraryDirective("") }, EMPTY_NAME_MESSAGE), - Arguments.of({ PartDirective("") }, EMPTY_NAME_MESSAGE), - Arguments.of({ RelativeDirective("") }, EMPTY_NAME_MESSAGE), - Arguments.of({ LibraryDirective("") }, EMPTY_NAME_MESSAGE), + Arguments.of({ DartDirective(SPACE_STRING) }, EMPTY_NAME_MESSAGE), + Arguments.of({ LibraryDirective(EMPTY_STRING) }, EMPTY_NAME_MESSAGE), + Arguments.of({ PartDirective(EMPTY_STRING) }, EMPTY_NAME_MESSAGE), + Arguments.of({ RelativeDirective(EMPTY_STRING) }, EMPTY_NAME_MESSAGE), + Arguments.of({ LibraryDirective(EMPTY_STRING) }, EMPTY_NAME_MESSAGE), Arguments.of({ DartDirective("flutter/material.dart", CastType.AS, null) }, INVALID_CAST_USAGE), Arguments.of({ DartDirective("flutter/material.dart", null, "test") }, INVALID_CAST_USAGE), Arguments.of({ RelativeDirective("flutter/material.dart", CastType.AS, null) }, INVALID_CAST_USAGE), @@ -134,21 +136,14 @@ class DirectiveTest { assertEquals(expected, current.asString()) } - @Test - fun `test cast import with empty cast`() { - assertThrows( - IllegalStateException::class.java, - { DirectiveFactory.create(DirectiveType.IMPORT, "flutter/material.dart", CastType.AS, " ") }, - "The importCast can't be empty" - ) - assertThrows( - IllegalStateException::class.java, - { DirectiveFactory.create(DirectiveType.IMPORT, "flutter/material.dart", CastType.AS, "") }, - "The importCast can't be empty" - ) + @ParameterizedTest + @EnumSource(value = CastType::class, mode = EnumSource.Mode.MATCH_ALL) + fun `test invalid cast import mapping`(castType: CastType) { + assertThrows { + DirectiveFactory.create(DirectiveType.IMPORT, "flutter/material.dart", castType, SPACE_STRING) + } } - @Test fun `test package import`() { val import = DirectiveFactory.create(DirectiveType.IMPORT, "flutter/material.dart") diff --git a/src/test/kotlin/net/theevilreaper/dartpoet/directive/ExportDirectiveTest.kt b/src/test/kotlin/net/theevilreaper/dartpoet/directive/ExportDirectiveTest.kt index 956d8c7d..a7c968af 100644 --- a/src/test/kotlin/net/theevilreaper/dartpoet/directive/ExportDirectiveTest.kt +++ b/src/test/kotlin/net/theevilreaper/dartpoet/directive/ExportDirectiveTest.kt @@ -15,10 +15,6 @@ class ExportDirectiveTest { @JvmStatic private fun invalidExportDirectives(): Stream = Stream.of( - Arguments.of( - { DirectiveFactory.create(DirectiveType.EXPORT, "") }, - "The path of an directive can't be empty" - ), Arguments.of( { DirectiveFactory.create(DirectiveType.EXPORT, "dart:math", CastType.DEFERRED, "math") }, "The following cast types are not allowed for an export directive: [DEFERRED, AS]" diff --git a/src/test/kotlin/net/theevilreaper/dartpoet/directive/PartDirectiveTest.kt b/src/test/kotlin/net/theevilreaper/dartpoet/directive/PartDirectiveTest.kt index a3d0eade..c2f76160 100644 --- a/src/test/kotlin/net/theevilreaper/dartpoet/directive/PartDirectiveTest.kt +++ b/src/test/kotlin/net/theevilreaper/dartpoet/directive/PartDirectiveTest.kt @@ -3,40 +3,15 @@ package net.theevilreaper.dartpoet.directive import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.Test -import org.junit.jupiter.api.assertThrows -import org.junit.jupiter.params.ParameterizedTest -import org.junit.jupiter.params.provider.Arguments -import org.junit.jupiter.params.provider.MethodSource -import java.util.stream.Stream @DisplayName("Test part directive creation") class PartDirectiveTest { private val expectedImport = "part 'item_model.freezed.dart';" - companion object { - @JvmStatic - private fun invalidPartDirectives(): Stream = Stream.of( - Arguments.of( - { DirectiveFactory.create(DirectiveType.IMPORT, " ") }, - "The path of an Import can't be empty" - ), - Arguments.of( - { DirectiveFactory.create(DirectiveType.RELATIVE, " ") }, - "The path of an Import can't be empty" - ) - ) - } - - @ParameterizedTest(name = "Test invalid directive creation over the DirectiveFactory") - @MethodSource("invalidPartDirectives") - fun `test import with empty path`(current: () -> Directive, expectedMessage: String) { - assertThrows(expectedMessage) { current() } - } - @Test fun `create part import`() { val partImport = DirectiveFactory.create(DirectiveType.PART, "item_model.freezed.dart") assertEquals(expectedImport, partImport.asString()) } -} \ No newline at end of file +} diff --git a/src/test/kotlin/net/theevilreaper/dartpoet/extension/ExtensionSpecTest.kt b/src/test/kotlin/net/theevilreaper/dartpoet/extension/ExtensionSpecTest.kt index bb773f2d..cca6f5e7 100644 --- a/src/test/kotlin/net/theevilreaper/dartpoet/extension/ExtensionSpecTest.kt +++ b/src/test/kotlin/net/theevilreaper/dartpoet/extension/ExtensionSpecTest.kt @@ -2,6 +2,7 @@ package net.theevilreaper.dartpoet.extension import net.theevilreaper.dartpoet.type.ClassName import net.theevilreaper.dartpoet.type.ParameterizedTypeName.Companion.parameterizedBy +import net.theevilreaper.dartpoet.util.EMPTY_STRING import org.junit.jupiter.api.Assertions.* import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.Test @@ -19,12 +20,12 @@ class ExtensionSpecTest { private fun invalidExtensionSpecs() = Stream.of( Arguments.of( IllegalStateException::class.java, - { ExtensionSpec.builder("", String::class).build() }, + { ExtensionSpec.builder(EMPTY_STRING, String::class).build() }, "The name of a extension can't be empty" ), Arguments.of( IllegalArgumentException::class.java, - { ExtensionSpec.builder("StringExt", "").build() }, + { ExtensionSpec.builder("StringExt", EMPTY_STRING).build() }, "The name of a ClassName can't be empty (includes only spaces)" ), Arguments.of( diff --git a/src/test/kotlin/net/theevilreaper/dartpoet/function/factory/FactorySpecTest.kt b/src/test/kotlin/net/theevilreaper/dartpoet/function/factory/FactorySpecTest.kt index 74167503..b3165c70 100644 --- a/src/test/kotlin/net/theevilreaper/dartpoet/function/factory/FactorySpecTest.kt +++ b/src/test/kotlin/net/theevilreaper/dartpoet/function/factory/FactorySpecTest.kt @@ -8,30 +8,15 @@ import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.Test -import org.junit.jupiter.params.ParameterizedTest -import org.junit.jupiter.params.provider.Arguments -import org.junit.jupiter.params.provider.MethodSource -import java.util.stream.Stream @DisplayName("Tests for the factory spec object") class FactorySpecTest { - companion object { - - @JvmStatic - private fun invalidFactoryCalls(): Stream = Stream.of( - Arguments.of( - { FactorySpec.constBuilder(Int::class.asTypeName()).build() }, - "The initializer block must not be empty" - ), - ) - } - - @ParameterizedTest - @MethodSource("invalidFactoryCalls") - fun `test invalid factory calls`(factory: () -> FactorySpec, message: String) { - assertThrows(message, IllegalStateException::class.java) { - factory.invoke() + @Test + fun `test invalid factory creation`() { + assertThrows("The initializer block must not be empty", IllegalStateException::class.java) { + FactorySpec.constBuilder(Int::class.asTypeName()) + .build() } } @@ -51,4 +36,4 @@ class FactorySpecTest { assertTrue(specAsBuilder.const) assertEquals(1, specAsBuilder.parameters.size) } -} \ No newline at end of file +} diff --git a/src/test/kotlin/net/theevilreaper/dartpoet/function/typedef/TypeDefSpecTest.kt b/src/test/kotlin/net/theevilreaper/dartpoet/function/typedef/TypeDefSpecTest.kt index 91f98ecc..49926ad2 100644 --- a/src/test/kotlin/net/theevilreaper/dartpoet/function/typedef/TypeDefSpecTest.kt +++ b/src/test/kotlin/net/theevilreaper/dartpoet/function/typedef/TypeDefSpecTest.kt @@ -1,6 +1,7 @@ package net.theevilreaper.dartpoet.function.typedef import net.theevilreaper.dartpoet.parameter.ParameterSpec +import net.theevilreaper.dartpoet.util.EMPTY_STRING import org.junit.jupiter.api.Assertions.* import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.Test @@ -19,14 +20,14 @@ class TypeDefSpecTest { private fun invalidTypeDefs(): Stream = Stream.of( Arguments.of( "Empty name", - { TypeDefSpec.builder("").build() }, + { TypeDefSpec.builder(EMPTY_STRING).build() }, "The name of a typedef can't be empty" ), Arguments.of( "Empty function name", { TypeDefSpec.builder("Test", Int::class) - .name("") + .name(EMPTY_STRING) .returns(String::class).build() }, "The function name of a typedef can't be empty" diff --git a/src/test/kotlin/net/theevilreaper/dartpoet/property/ConstantPropertySpecTest.kt b/src/test/kotlin/net/theevilreaper/dartpoet/property/ConstantPropertySpecTest.kt index 4a4eb12d..a89872ef 100644 --- a/src/test/kotlin/net/theevilreaper/dartpoet/property/ConstantPropertySpecTest.kt +++ b/src/test/kotlin/net/theevilreaper/dartpoet/property/ConstantPropertySpecTest.kt @@ -1,6 +1,7 @@ package net.theevilreaper.dartpoet.property import net.theevilreaper.dartpoet.property.consts.ConstantPropertySpec +import net.theevilreaper.dartpoet.util.EMPTY_STRING import org.junit.jupiter.api.Assertions.* import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.Test @@ -20,7 +21,7 @@ class ConstantPropertySpecTest { private fun invalidFileConstantSpec() = Stream.of( Arguments.of( "The name of a file constant can't be empty", - { ConstantPropertySpec.classConst("", String::class).build() } + { ConstantPropertySpec.classConst(EMPTY_STRING, String::class).build() } ), Arguments.of( "The initializer can't be empty", diff --git a/src/test/kotlin/net/theevilreaper/dartpoet/property/PropertySpecTest.kt b/src/test/kotlin/net/theevilreaper/dartpoet/property/PropertySpecTest.kt index 5e45d270..dd2ffac6 100644 --- a/src/test/kotlin/net/theevilreaper/dartpoet/property/PropertySpecTest.kt +++ b/src/test/kotlin/net/theevilreaper/dartpoet/property/PropertySpecTest.kt @@ -5,6 +5,7 @@ import net.theevilreaper.dartpoet.DartModifier import net.theevilreaper.dartpoet.type.asTypeName import net.theevilreaper.dartpoet.util.ALLOWED_CONST_MODIFIERS import net.theevilreaper.dartpoet.util.ALLOWED_PROPERTY_MODIFIERS +import net.theevilreaper.dartpoet.util.EMPTY_STRING import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertThrows @@ -57,7 +58,7 @@ class PropertySpecTest { "These modifiers [REQUIRED] are not allowed in a property context. Allowed modifiers: $ALLOWED_PROPERTY_MODIFIERS" ), Arguments.of( - { PropertySpec.builder("", String::class).build() }, + { PropertySpec.builder(EMPTY_STRING, String::class).build() }, "The name of a property can't be empty" ), Arguments.of( diff --git a/src/test/kotlin/net/theevilreaper/dartpoet/type/TypeNameExceptionsTest.kt b/src/test/kotlin/net/theevilreaper/dartpoet/type/TypeNameExceptionsTest.kt index 778e8bd4..8c4e1587 100644 --- a/src/test/kotlin/net/theevilreaper/dartpoet/type/TypeNameExceptionsTest.kt +++ b/src/test/kotlin/net/theevilreaper/dartpoet/type/TypeNameExceptionsTest.kt @@ -1,5 +1,7 @@ package net.theevilreaper.dartpoet.type +import net.theevilreaper.dartpoet.util.EMPTY_STRING +import net.theevilreaper.dartpoet.util.SPACE_STRING import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertThrows @@ -16,8 +18,8 @@ class TypeNameExceptionsTest { @JvmStatic private fun testTypeNameConditions() = Stream.of( - Arguments.of({ ClassName("") }, "The name of a ClassName can't be empty (includes only spaces)"), - Arguments.of({ ClassName(" ") }, "The name of a ClassName can't be empty (includes only spaces)"), + Arguments.of({ ClassName(EMPTY_STRING) }, "The name of a ClassName can't be empty (includes only spaces)"), + Arguments.of({ ClassName(SPACE_STRING) }, "The name of a ClassName can't be empty (includes only spaces)"), Arguments.of( { ParameterizedTypeName( diff --git a/src/test/kotlin/net/theevilreaper/dartpoet/util/FileConventionNamingTest.kt b/src/test/kotlin/net/theevilreaper/dartpoet/util/FileConventionNamingTest.kt index 56a77c5a..12d1a14f 100644 --- a/src/test/kotlin/net/theevilreaper/dartpoet/util/FileConventionNamingTest.kt +++ b/src/test/kotlin/net/theevilreaper/dartpoet/util/FileConventionNamingTest.kt @@ -16,7 +16,7 @@ class FileConventionNamingTest { } @ParameterizedTest(name = "Test invalid name pattern: {arguments}") - @ValueSource(strings = ["hello__world.dart", "_hello__world_.dart", "_test", "model_", "", "Dart_FILE"]) + @ValueSource(strings = ["hello__world.dart", "_hello__world_.dart", "_test", "model_", EMPTY_STRING, "Dart_FILE"]) fun `test invalid file patterns`(pattern: String) { assertFalse { isDartConventionFileName(pattern) } } diff --git a/src/test/kotlin/net/theevilreaper/dartpoet/util/IndentTest.kt b/src/test/kotlin/net/theevilreaper/dartpoet/util/IndentTest.kt index 5589261a..53a501e9 100644 --- a/src/test/kotlin/net/theevilreaper/dartpoet/util/IndentTest.kt +++ b/src/test/kotlin/net/theevilreaper/dartpoet/util/IndentTest.kt @@ -10,13 +10,13 @@ import kotlin.test.assertTrue class IndentTest { @ParameterizedTest(name = "Test valid indent value: {arguments}") - @ValueSource(strings = [" ", " "]) + @ValueSource(strings = [SPACE_STRING, " "]) fun `test valid indent pattern`(indent: String) { assertTrue { isIndent(indent) } } @ParameterizedTest(name = "Test invalid indent value: {arguments}") - @ValueSource(strings = ["", " a", "123"]) + @ValueSource(strings = [EMPTY_STRING, " a", "123"]) fun `test invalid indent patterns`(indent: String) { assertFalse { isIndent(indent) } }