Skip to content

Commit

Permalink
GH-175 Remove description resolver for Descriptions annotation. Fix A…
Browse files Browse the repository at this point in the history
…nnotatedMember#getAnnotationsByType implementations. (#176) (#176)

* Remove description resolver for Descriptions annotation. Fix AnnotatedMember#getAnnotationsByType implementations. Add junit tests for multiline comments for java and kotlin platform. (#175)

* Move MultiDescriptionJavaTest to kotlin package.
  • Loading branch information
Rollczi authored Jan 19, 2023
1 parent 199df63 commit 22d0c21
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ internal class KFunctionMember(

override fun <A : Annotation> getAnnotationsByType(annotation: Class<A>): List<A> =
PandaStream.of(getter.annotations)
.concat(getter.javaMethod?.getAnnotationsByType(annotation)?.toList())
.`is`(annotation)
.toList()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ internal class KPropertyMember(
?: false

override fun <A : Annotation?> getAnnotationsByType(annotation: Class<A>): MutableList<A> =
PandaStream.of(property.javaGetter?.annotations, property.javaField?.annotations)
.flatMapStream { Arrays.stream(it ?: emptyArray()) }
PandaStream.of(property.javaGetter?.annotations, property.javaField?.getAnnotationsByType(annotation))
.flatMap { array -> (array ?: emptyArray()).toList() }
.`is`(annotation)
.toList()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package net.dzikoysk.cdn.feature;

import net.dzikoysk.cdn.Cdn;
import net.dzikoysk.cdn.CdnException;
import net.dzikoysk.cdn.CdnFactory;
import net.dzikoysk.cdn.entity.Description;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import panda.std.Result;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static panda.std.ResultAssertions.assertOk;

class MultiDescriptionJavaTest {

public static class ConfigurationWithMultiDescription {

@Description("#")
@Description("# Test multi line banner")
@Description("#")
@Description(" ")
public String value = "test";
}

@Test
@DisplayName("should render multiline banner with empty descriptions on java implementation")
void test() {
Cdn standardJava = CdnFactory.createStandard();
Result<String, CdnException> renderResult = standardJava.render(new ConfigurationWithMultiDescription());
String render = assertOk(renderResult);

assertEquals(
"#\n" +
"# Test multi line banner\n" +
"#\n" +
" \n" +
"value: test",
render
);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package net.dzikoysk.cdn.feature

import net.dzikoysk.cdn.CdnSpec
import net.dzikoysk.cdn.entity.Description
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import panda.std.ResultAssertions

internal class MultiDescriptionTest : CdnSpec() {

internal inner class ConfigurationWithMultiDescription {

@Description("#")
@Description("# Test multi line banner")
@Description("#")
@Description(" ")
var value = "test"

}

@Test
fun `should render multiline banner with empty descriptions`() {
val renderResult = standard.render(ConfigurationWithMultiDescription())
val render = ResultAssertions.assertOk(renderResult)

assertEquals("""
#
# Test multi line banner
#
value: test
""".trimIndent(), render)
}

}
1 change: 0 additions & 1 deletion cdn/src/main/java/net/dzikoysk/cdn/CdnSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ public final class CdnSettings {

withDynamicComposer(Class::isEnum, new EnumComposer());
withDescriptionResolver(Description.class, description -> Arrays.asList(description.value()));
withDescriptionResolver(Descriptions.class, descriptions -> PandaStream.of(descriptions.value()).flatMap(description -> Arrays.asList(description.value())).toList());
}

/**
Expand Down
3 changes: 3 additions & 0 deletions cdn/src/main/java/net/dzikoysk/cdn/reflect/ReflectUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

public final class ReflectUtils {

private ReflectUtils() {
}

public static List<Field> getAllFields(Class<?> type) {
List<Field> fields = new ArrayList<>(Arrays.asList(type.getDeclaredFields()));
Class<?> superclass = type.getSuperclass();
Expand Down

0 comments on commit 22d0c21

Please sign in to comment.