33import static org .junit .Assert .assertEquals ;
44import static org .junit .Assert .assertNotNull ;
55import static org .junit .Assert .assertNull ;
6- import static org .junit .Assert .assertSame ;
76import static org .junit .Assert .assertTrue ;
87
98import java .util .ArrayList ;
109import java .util .Collection ;
1110
12- import org .junit .Ignore ;
1311import org .junit .Test ;
14- import org .junit .runner .RunWith ;
1512
1613import ch .akuhn .fame .FameDescription ;
1714import ch .akuhn .fame .FamePackage ;
2017import ch .akuhn .fame .Repository ;
2118import ch .akuhn .fame .Tower ;
2219import ch .akuhn .fame .fm3 .PropertyDescription ;
23- import ch .unibe .jexample .Given ;
24- import ch .unibe .jexample .Injection ;
25- import ch .unibe .jexample .InjectionPolicy ;
26- import ch .unibe .jexample .JExample ;
2720
28- @ RunWith (JExample .class )
29- @ Injection (InjectionPolicy .NONE )
21+
3022public class CompositeExample {
3123
3224 @ FameDescription
@@ -46,7 +38,7 @@ static abstract class Composite {
4638 static class Container extends Composite {
4739
4840 @ FameProperty (opposite = "parent" )
49- public Collection <Composite > children = new ArrayList ();
41+ public Collection <Composite > children = new ArrayList <> ();
5042
5143 @ Override
5244 public int getTotalCount () {
@@ -72,147 +64,166 @@ public int getTotalCount() {
7264
7365 }
7466
75- @ Test
7667 public Tower createTower () {
7768 Tower t = new Tower ();
69+ return t ;
70+ }
71+
72+ @ Test
73+ public void testCreateTower () {
74+ Tower t = createTower ();
7875 assertNotNull (t .getMetaMetamodel ());
7976 assertNotNull (t .getMetamodel ());
8077 assertNotNull (t .getModel ());
81- return t ;
8278 }
8379
8480 @ Test
85- @ Given ( "#createTower" )
86- public Tower towerHasLayers ( Tower t ) {
81+ public void towerHasLayers () {
82+ Tower t = this . createTower ();
8783 assertEquals (t .getModel ().getMetamodel (), t .getMetamodel ());
8884 assertEquals (t .getMetamodel ().getMetamodel (), t .getMetaMetamodel ());
8985 assertEquals (t .getMetaMetamodel ().getMetamodel (), t .getMetaMetamodel ());
90- return t ;
9186 }
9287
9388 @ Test
94- @ Given ( "#towerHasLayers" )
95- public Tower tower ( Tower t ) {
89+ public void tower () {
90+ Tower t = this . createTower ();
9691 assertEquals (0 , t .getModel ().size ());
9792 assertEquals (0 , t .getMetamodel ().size ());
9893 assertEquals (31 , t .getMetaMetamodel ().size ());
99- return t ;
10094 }
10195
102- @ Test
103- @ Ignore // FIXME
104- @ Given ("model;newParent;newChildA;newChildB" )
105- public Repository createInstances (Repository $ ) {
106- assertEquals (3 , $ .getElements ().size ());
107- return $ ;
108- }
96+ // @Test
97+ // @Ignore // FIXME
98+ // public Repository createInstances(Repository $) {
99+ // assertEquals(3, $.getElements().size());
100+ // return $;
101+ // }
109102
110- @ Test
111- @ Given ( " model;parentWithChildren" )
112- public String exportMSE ( Repository m ) {
103+ public String exportMSE () {
104+ Repository m = model ();
105+ setParentWithChildren ( m );
113106 String mse = m .exportMSE ();
114107 return mse ;
115108 }
116109
117110 @ Test
118- @ Ignore // FIXME
119- @ Given ("tower;exportMSE;metamodel" )
120- public Repository importMSE (Tower t , String mse ) {
121- t .getModel ().importMSE (mse );
122- Repository m = t .getModel ();
123- assertEquals (3 , m .getElements ().size ());
124- return m ;
111+ public void testExportMSE () {
112+ String mse = exportMSE ();
113+ // 165 is the magic number of the size of the string. I wanted to test that the string size is more than 2 char (not empty model)
114+ assertEquals (165 , mse .length ());
115+
125116 }
126117
127118 @ Test
128- @ Ignore // FIXME
129- @ Given ("model;model" )
130- public void jexampleKeepWorksFine (Repository m1 , Repository m2 ) {
131- assertSame (m1 , m2 );
119+ public void importMSE () {
120+ String mse = exportMSE ();
121+ Repository model = model ();
122+ model .importMSE (mse );
123+ assertEquals (3 , model .getElements ().size ());
132124 }
133125
134- @ Test
135- @ Given ("#tower" )
136- public MetaRepository metamodel (Tower t ) {
126+ public MetaRepository metamodel () {
127+ Tower t = new Tower ();
137128 t .getMetamodel ().withAll (Composite .class , Container .class , Leaf .class );
138129 MetaRepository $ = t .getMetamodel ();
130+ return $ ;
131+ }
132+
133+ @ Test
134+ public void testMetamodel () {
135+ MetaRepository $ = metamodel ();
139136 assertEquals (3 , $ .allClassDescriptions ().size ());
140137 assertEquals (4 , $ .all (PropertyDescription .class ).size ());
138+ }
139+
140+ public Repository model () {
141+ MetaRepository metamodel = metamodel ();
142+ Repository $ = new Repository (metamodel );
141143 return $ ;
142144 }
143145
144146 @ Test
145- @ Given ( "metamodelNames" )
146- public Repository model ( MetaRepository metamodel ) {
147+ public void testModel () {
148+ MetaRepository metamodel = metamodel ();
147149 Repository $ = new Repository (metamodel );
148150 assertEquals (metamodel , $ .getMetamodel ());
149- return $ ;
150151 }
151152
153+
152154 @ Test
153- @ Given ("metamodel" )
154- public MetaRepository metamodelNames (MetaRepository mm ) {
155- assertNull (mm .descriptionNamed ("FAME" ));
156- assertNotNull (mm .descriptionNamed ("TEST.Container" ));
157- assertNotNull (mm .descriptionNamed ("TEST.Leaf" ));
158- assertNotNull (mm .descriptionNamed ("TEST.Composite" ));
159- return mm ;
155+ public void testMetamodelNames () {
156+ MetaRepository metamodel = metamodel ();
157+ assertNull (metamodel .descriptionNamed ("FAME" ));
158+ assertNotNull (metamodel .descriptionNamed ("TEST.Container" ));
159+ assertNotNull (metamodel .descriptionNamed ("TEST.Leaf" ));
160+ assertNotNull (metamodel .descriptionNamed ("TEST.Composite" ));
160161 }
161162
162- @ Test
163- @ Given ("model" )
164163 public Leaf newChildA (Repository repo ) {
165164 Object $ = repo .newInstance ("TEST.Leaf" );
166- assertNotNull ($ );
167- assertEquals (Leaf .class , $ .getClass ());
168165 return (Leaf ) $ ;
169166 }
170167
171168 @ Test
172- @ Given ("model" )
173- public Leaf newChildB (Repository repo ) {
174- Object $ = repo .newInstance ("TEST.Leaf" );
169+ public void testNewChildA () {
170+ Object $ = newChildA (model ());
175171 assertNotNull ($ );
176172 assertEquals (Leaf .class , $ .getClass ());
173+ }
174+
175+ public Leaf newChildB (Repository repo ) {
176+ Object $ = repo .newInstance ("TEST.Leaf" );
177177 return (Leaf ) $ ;
178178 }
179179
180180 @ Test
181- @ Given ("model" )
181+ public void testNewChildB () {
182+ Object $ = newChildB (model ());
183+ assertNotNull ($ );
184+ assertEquals (Leaf .class , $ .getClass ());
185+ }
186+
182187 public Container newParent (Repository repo ) {
183188 Object $ = repo .newInstance ("TEST.Container" );
189+ return (Container ) $ ;
190+ }
191+
192+ @ Test
193+ public void testNewParent () {
194+ Object $ = newParent (model ());
184195 assertNotNull ($ );
185196 assertEquals (Container .class , $ .getClass ());
186- return ( Container ) $ ;
197+
187198 }
188199
189200 @ Test
190- @ Given ("model;newChildA" )
191- public Leaf numberPropertyA (Repository m , Leaf a ) {
201+ public void numberPropertyA () {
202+ Repository m = model ();
203+ Leaf a = newChildA (m );
192204 assertEquals ((Integer ) 0 , (Integer ) a .count );
193205 assertEquals ((Integer ) 0 , (Integer ) m .read ("count" , a ));
194206 m .write ("count" , a , 42 );
195207 assertEquals (42 , a .count );
196208 assertEquals ((Integer )42 , (Integer )m .read ("count" , a ));
197- return a ;
198209 }
199210
200211 @ Test
201- @ Given ("model;newChildB" )
202- public Leaf numberPropertyB (Repository m , Leaf b ) {
212+ public void numberPropertyB () {
213+ Repository m = model ();
214+ Leaf b = newChildB (m );
203215 assertEquals (0 , b .count );
204216 assertEquals ((Integer ) 0 , m .read ("count" , b ));
205217 m .write ("count" , b , 23 );
206218 assertEquals (23 , b .count );
207219 assertEquals ((Integer ) 23 , m .read ("count" , b ));
208- return b ;
209220 }
210221
211222 @ Test
212- @ Given ( "metamodel;metamodelNames" )
213- public void parentChildrenAreOpposite ( MetaRepository mm ) {
214- PropertyDescription parent = mm .descriptionNamed ("TEST.Composite" ).attributeNamed ("parent" );
215- PropertyDescription children = mm .descriptionNamed ("TEST.Container" ).attributeNamed ("children" );
223+ public void parentChildrenAreOpposite () {
224+ MetaRepository metamodel = metamodel ();
225+ PropertyDescription parent = metamodel .descriptionNamed ("TEST.Composite" ).attributeNamed ("parent" );
226+ PropertyDescription children = metamodel .descriptionNamed ("TEST.Container" ).attributeNamed ("children" );
216227 assertNotNull (parent );
217228 assertNotNull (children );
218229 assertTrue (parent .hasOpposite ());
@@ -221,16 +232,25 @@ public void parentChildrenAreOpposite(MetaRepository mm) {
221232 assertEquals (children , parent .getOpposite ());
222233 }
223234
235+ public void setParentWithChildren (Repository m ) {
236+ Container p = newParent (m );
237+ Leaf a = newChildA (m );
238+ Leaf b = newChildB (m );
239+ m .write ("children" , p , a , b );
240+ }
241+
224242 @ Test
225- @ Given ("model;newParent;newChildA;newChildB;parentChildrenAreOpposite" )
226- public Container parentWithChildren (Repository m , Container p , Leaf a , Leaf b ) {
243+ public void parentWithChildren () {
244+ Repository m = model ();
245+ Container p = newParent (m );
246+ Leaf a = newChildA (m );
247+ Leaf b = newChildB (m );
227248 assertEquals (0 , p .children .size ());
228249 assertEquals (null , a .parent );
229250 assertEquals (null , b .parent );
230251 m .write ("children" , p , a , b );
231252 assertEquals (2 , p .children .size ());
232253 assertEquals (p , a .parent );
233254 assertEquals (p , b .parent );
234- return p ;
235255 }
236256}
0 commit comments