Skip to content

Commit c1cc5e7

Browse files
committed
added attribute test
1 parent 2ebc6a7 commit c1cc5e7

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

annot/src/test/java/com/predic8/membrane/annot/YAMLParsingTest.java

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,39 @@ public class DemoElement {
2929
);
3030
}
3131

32+
@Test
33+
public void attribute() {
34+
var sources = splitSources(MC_MAIN_DEMO + """
35+
package com.predic8.membrane.demo;
36+
import com.predic8.membrane.annot.*;
37+
import java.util.List;
38+
@MCElement(name="demo")
39+
public class DemoElement {
40+
public String attr;
41+
42+
public String getAttr() {
43+
return attr;
44+
}
45+
46+
@MCAttribute
47+
public void setAttr(String attr) {
48+
this.attr = attr;
49+
}
50+
}
51+
""");
52+
var result = CompilerHelper.compile(sources, false);
53+
assertCompilerResult(true, result);
54+
55+
assertStructure(
56+
parseYAML(result, """
57+
demo:
58+
attr: here
59+
"""),
60+
clazz("DemoElement",
61+
property("attr", value("here")))
62+
);
63+
}
64+
3265
@Test
3366
public void singleChild() {
3467
var sources = splitSources(MC_MAIN_DEMO + """
@@ -37,14 +70,14 @@ public void singleChild() {
3770
import java.util.List;
3871
@MCElement(name="demo")
3972
public class DemoElement {
40-
ChildElement child;
73+
Child1Element child;
4174
42-
public ChildElement getChild() {
75+
public Child1Element getChild() {
4376
return child;
4477
}
4578
4679
@MCChildElement
47-
public void setChild(ChildElement child) {
80+
public void setChild(Child1Element child) {
4881
this.child = child;
4982
}
5083
}

annot/src/test/java/com/predic8/membrane/annot/util/StructureAssertionUtil.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ public void assertStructure(Object bean) {
3535
};
3636
}
3737

38+
public static Asserter value(Object value) {
39+
return new Asserter() {
40+
@Override
41+
public void assertStructure(Object bean) {
42+
assertEquals(value, bean);
43+
}
44+
};
45+
}
46+
3847
public static Property property(String name, Asserter asserter) {
3948
return new Property() {
4049
@Override

0 commit comments

Comments
 (0)