So I solved this by “cutting out the middle person” and bypassing applyTemplate() , and directly going to the method that executes the logic. This is not entirely ideal for two reasons: 1) I do not claim that the property tag is connected using renderField, but hopefully my other tests, which still use applyTemplate() , guarantee this. 2) In the real world, out in TagLib is the creator of the output, and in my test I created it as a list (I can do this, since all you can do is left shift will suffice).
What I like about using the list is that it helps to maintain order.
@Test void renderFieldShouldRenderAddress() { def address = new Address(line1: "Line 1", line2: "Line 2", line3: "Line 3", city: "City", state: "ST", zipCode: "12345", country: "USA", buildingNumber: null, buildingName: null, roomNumber: null ) def tagLib = new PropertyTagLib() def results = [] tagLib.metaClass.getOut = { results } tagLib.renderField(address) assert "Line 1" == results[0] assert "<br />" == results[1] assert "Line 2" == results[2] assert "<br />" == results[3] assert "Line 3" == results[4] assert "<br />" == results[5] assert "City, ST 12345" == results[6] assert "<br />" == results[7] assert "USA" == results[8] assert "<br />" == results[9] assert 10 == results.size() }
Any thoughts?
source share