Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve test package #112

Merged
merged 7 commits into from
Apr 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import net.theevilreaper.dartpoet.directive.DirectiveType
import net.theevilreaper.dartpoet.function.FunctionSpec
import net.theevilreaper.dartpoet.type.ClassName
import net.theevilreaper.dartpoet.type.ParameterizedTypeName.Companion.parameterizedBy
import org.junit.jupiter.api.DisplayName
import kotlin.test.Test

@DisplayName("Test some file generations with directive usage")
class DartFileImportTest {

@Test
Expand Down
16 changes: 2 additions & 14 deletions src/test/kotlin/net/theevilreaper/dartpoet/DartFileTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,13 @@ import net.theevilreaper.dartpoet.type.ParameterizedTypeName.Companion.parameter
import net.theevilreaper.dartpoet.type.asTypeName
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 kotlin.test.assertContentEquals

@DisplayName("Test somme cases from a DartFile object")
class DartFileTest {

@Test
fun `test indent set`() {
assertThrows(
IllegalStateException::class.java,
{ DartFile.builder("Test").indent("") },
"The indent can't be empty"
)
assertThrows(
IllegalStateException::class.java,
{ DartFile.builder("Test").indent { " 123AB" } },
"The indent can't be empty"
)
}

@Test
fun `test spec to builder conversation`() {
val dartFileSpec = DartFile.builder("TestClass")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package net.theevilreaper.dartpoet

import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
import kotlin.test.assertFalse
import kotlin.test.assertTrue

@DisplayName("Test some operations on the DartModifier enum")
class DartModifierTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import net.theevilreaper.dartpoet.type.ClassName
import net.theevilreaper.dartpoet.type.DEPRECATED
import net.theevilreaper.dartpoet.type.OVERRIDE
import net.theevilreaper.dartpoet.type.PRAGMA
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
Expand All @@ -12,22 +13,23 @@ import java.util.stream.Stream
import kotlin.test.assertContentEquals
import kotlin.test.assertEquals

@DisplayName("Test AnnotationSpec creation")
class AnnotationSpecTest {

companion object {

@JvmStatic
private fun testSimpleAnnotations() = Stream.of(
Arguments.of(OVERRIDE, "@override"),
Arguments.of(DEPRECATED, "@deprecated"),
Arguments.of(PRAGMA, "@pragma"),
Arguments.of(AnnotationSpec.builder(Override::class).build(), "@Override")
Arguments.of("@override", OVERRIDE),
Arguments.of("@deprecated", DEPRECATED),
Arguments.of("@pragma", PRAGMA),
Arguments.of("@Override", AnnotationSpec.builder(Override::class).build())
)
}

@ParameterizedTest
@ParameterizedTest(name = "Test annotation creation for case: {0}")
@MethodSource("testSimpleAnnotations")
fun `test simple annotations`(annotation: AnnotationSpec, expected: String) {
fun `test simple annotations`(expected: String, annotation: AnnotationSpec) {
assertEquals(expected, annotation.toString())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import net.theevilreaper.dartpoet.clazz.ClassSpec
import net.theevilreaper.dartpoet.function.FunctionSpec
import net.theevilreaper.dartpoet.parameter.ParameterSpec
import net.theevilreaper.dartpoet.type.ClassName
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test

@DisplayName("Test some AbstractClass creations")
class AbstractClassTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import net.theevilreaper.dartpoet.enum.EnumPropertySpec
import net.theevilreaper.dartpoet.function.constructor.ConstructorSpec
import net.theevilreaper.dartpoet.parameter.ParameterSpec
import net.theevilreaper.dartpoet.property.PropertySpec
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import org.junit.jupiter.params.ParameterizedTest
Expand All @@ -16,6 +17,7 @@ import org.junit.jupiter.params.provider.MethodSource
import java.util.stream.Stream
import kotlin.test.assertEquals

@DisplayName("Test some EnumClass creations")
class EnumClassTest {

companion object {
Expand Down Expand Up @@ -54,7 +56,7 @@ class EnumClassTest {
)
}

@ParameterizedTest
@ParameterizedTest(name = "Test cases for invalid enum definitions")
@MethodSource("invalidEnums")
fun `test invalid enum creation`(classSpec: () -> Unit, message: String) {
val exception = assertThrows<IllegalStateException> { classSpec() }
Expand Down Expand Up @@ -126,29 +128,4 @@ class EnumClassTest {
""".trimIndent()
)
}

@Test
fun d() {
val enumClass = ClassSpec.enumClass("TestEnum")
.enumProperties(
EnumPropertySpec.builder("test")
.parameter("%C", "Test")
.build()
)
.properties(
PropertySpec.builder("name", String::class).build()
)
.constructor(
ConstructorSpec.builder("TestEnum")
.parameter(ParameterSpec.builder("name").build())
.build()
)
.build()
val file = DartFile.builder("test")
.type(enumClass)
.build()
file.write(System.out)
}
}


Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package net.theevilreaper.dartpoet.code

import com.google.common.truth.Truth.assertThat
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test

//TODO: Add tests
@DisplayName("Test code block usage")
class CodeBlockTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package net.theevilreaper.dartpoet.code
import com.google.common.truth.Truth.assertThat
import net.theevilreaper.dartpoet.util.DEFAULT_INDENT
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test

@DisplayName("Test line wrapper")
class LineWrapperTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package net.theevilreaper.dartpoet.code.writer

import net.theevilreaper.dartpoet.annotation.AnnotationSpec
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test

@DisplayName("Test annotation writer")
class AnnotationWriterTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ package net.theevilreaper.dartpoet.code.writer
import com.google.common.truth.Truth.assertThat
import net.theevilreaper.dartpoet.clazz.ClassSpec
import net.theevilreaper.dartpoet.property.consts.ConstantPropertySpec
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("Test class writer")
class ClassWriterTest {

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import net.theevilreaper.dartpoet.type.ClassName
import net.theevilreaper.dartpoet.type.ParameterizedTypeName.Companion.parameterizedBy
import net.theevilreaper.dartpoet.type.asClassName
import net.theevilreaper.dartpoet.type.asTypeName
import org.junit.jupiter.api.DisplayName
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 constant property writer")
class ConstantPropertyWriterTest {

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import net.theevilreaper.dartpoet.DartModifier
import net.theevilreaper.dartpoet.code.CodeBlock
import net.theevilreaper.dartpoet.function.constructor.ConstructorSpec
import net.theevilreaper.dartpoet.parameter.ParameterSpec
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test

@DisplayName("Test constructor writer")
class ConstructorWriterTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package net.theevilreaper.dartpoet.code.writer
import net.theevilreaper.dartpoet.annotation.AnnotationSpec
import net.theevilreaper.dartpoet.enum.EnumPropertySpec
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.DisplayName
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 enum property writer")
class EnumPropertyWriterTest {

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import net.theevilreaper.dartpoet.extension.ExtensionSpec
import net.theevilreaper.dartpoet.function.FunctionSpec
import net.theevilreaper.dartpoet.type.ClassName
import net.theevilreaper.dartpoet.type.ParameterizedTypeName.Companion.parameterizedBy
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("Test extension writer")
class ExtensionWriterTest {

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import net.theevilreaper.dartpoet.parameter.ParameterSpec
import net.theevilreaper.dartpoet.type.ClassName
import net.theevilreaper.dartpoet.type.ParameterizedTypeName.Companion.parameterizedBy
import net.theevilreaper.dartpoet.type.asTypeName
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test

@DisplayName("Test factory writer")
class FactoryWriterTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import net.theevilreaper.dartpoet.type.ClassName
import net.theevilreaper.dartpoet.type.DYNAMIC
import net.theevilreaper.dartpoet.type.ParameterizedTypeName.Companion.parameterizedBy
import net.theevilreaper.dartpoet.type.asClassName
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("Test function writer")
class FunctionWriterTest {

private companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ 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
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 parameter writer")
class ParameterWriterTest {

companion object {
Expand Down Expand Up @@ -49,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"
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import net.theevilreaper.dartpoet.DartModifier
import net.theevilreaper.dartpoet.annotation.AnnotationSpec
import net.theevilreaper.dartpoet.property.PropertySpec
import net.theevilreaper.dartpoet.type.asTypeName
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
import kotlin.test.assertEquals

@DisplayName("Test property writer")
class PropertyWriterTest {

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import net.theevilreaper.dartpoet.type.ClassName
import net.theevilreaper.dartpoet.type.DYNAMIC
import net.theevilreaper.dartpoet.type.ParameterizedTypeName.Companion.parameterizedBy
import net.theevilreaper.dartpoet.type.asTypeName
import org.junit.jupiter.api.DisplayName
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 typedef writer")
class TypeDefWriterTest {

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import net.theevilreaper.dartpoet.type.ClassName
import net.theevilreaper.dartpoet.type.DYNAMIC
import net.theevilreaper.dartpoet.type.ParameterizedTypeName.Companion.parameterizedBy
import net.theevilreaper.dartpoet.type.asTypeName
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test

/**
Expand All @@ -22,6 +23,7 @@ import org.junit.jupiter.api.Test
* @version 1.0.0
* @since
**/
@DisplayName("Test file generations with factory constructors")
class FactoryFileTest {

private val versionModel = "VersionModel"
Expand Down Expand Up @@ -93,4 +95,4 @@ class FactoryFileTest {
""".trimIndent()
)
}
}
}
Loading
Loading