|
1 | 1 | package j2html.tags; |
2 | 2 |
|
| 3 | +import j2html.Config; |
| 4 | +import j2html.model.DynamicHrefAttribute; |
| 5 | +import org.junit.Test; |
| 6 | +import static j2html.TagCreator.a; |
3 | 7 | import static j2html.TagCreator.body; |
4 | 8 | import static j2html.TagCreator.div; |
5 | 9 | import static j2html.TagCreator.footer; |
| 10 | +import static j2html.TagCreator.form; |
6 | 11 | import static j2html.TagCreator.header; |
7 | 12 | import static j2html.TagCreator.html; |
8 | 13 | import static j2html.TagCreator.iff; |
|
13 | 18 | import static j2html.TagCreator.tag; |
14 | 19 | import static org.hamcrest.MatcherAssert.assertThat; |
15 | 20 | import static org.hamcrest.Matchers.is; |
16 | | -import j2html.Config; |
17 | | -import j2html.model.DynamicHrefAttribute; |
18 | | -import org.junit.Test; |
19 | 21 |
|
20 | 22 | public class TagTest { |
21 | 23 |
|
@@ -98,11 +100,24 @@ public void testDynamicAttribute() throws Exception { |
98 | 100 | ContainerTag testTagWithAttrValueNull = new ContainerTag("a").attr(new DynamicHrefAttribute()); |
99 | 101 | assertThat(testTagWithAttrValueNull.render(), is("<a href=\"/\"></a>")); |
100 | 102 | } |
101 | | - |
| 103 | + |
102 | 104 | @Test |
103 | 105 | public void testDynamicAttributeReplacement() throws Exception { |
104 | 106 | ContainerTag testTagWithAttrValueNull = new ContainerTag("a").attr("href", "/link").attr(new DynamicHrefAttribute()); |
105 | 107 | assertThat(testTagWithAttrValueNull.render(), is("<a href=\"/\"></a>")); |
106 | 108 | } |
107 | 109 |
|
| 110 | + @Test |
| 111 | + public void testParameterNameReflectionAttributes() throws Exception { |
| 112 | + String expectedAnchor = "<a href=\"http://example.com\">example.com</a>"; |
| 113 | + String actualAnchor = a("example.com").withAttrs(href -> "http://example.com").render(); |
| 114 | + assertThat(actualAnchor, is(expectedAnchor)); |
| 115 | + String expectedForm = "<form method=\"post\" action=\"/form-path\"><input name=\"email\" type=\"email\"><input name=\"password\" type=\"password\"></form>"; |
| 116 | + String actualForm = form().withAttrs(method -> "post", action -> "/form-path").with( |
| 117 | + input().withAttrs(name -> "email", type -> "email"), |
| 118 | + input().withAttrs(name -> "password", type -> "password") |
| 119 | + ).render(); |
| 120 | + assertThat(actualForm, is(expectedForm)); |
| 121 | + } |
| 122 | + |
108 | 123 | } |
0 commit comments