1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.creadur.whisker.fromxml;
20
21 import org.apache.creadur.whisker.model.Organisation;
22
23 import junit.framework.TestCase;
24 import org.jdom2.Element;
25
26
27
28
29 public class JDomBuilderOrganisationTest extends TestCase {
30 private JDomBuilder subject;
31
32 @Override
33 protected void setUp() throws Exception {
34 super.setUp();
35 subject = new JDomBuilder();
36 }
37
38 @Override
39 protected void tearDown() throws Exception {
40 super.tearDown();
41 }
42
43 public void testOrganisationSetsIdNameUrl() throws Exception {
44 final Organisation result = subject.organisation(
45 new Element("organisation")
46 .setAttribute("name", "a name")
47 .setAttribute("url", "an url")
48 .setAttribute("id", "an id"));
49 assertNotNull("Builder should build an organisation", result);
50
51 }
52
53 public void testThrowIllegalArgumentWhenResourceIsNotOrganisation() throws Exception {
54 try {
55 subject.organisation(
56 new Element("bogus")
57 .setAttribute("name", "name")
58 .setAttribute("url", "url")
59 .setAttribute("id", "id"));
60 fail("Expected IllegalArgument throw when elements is not named 'organisation'");
61 } catch (UnexpectedElementException e) {
62
63 } catch (Throwable t) {
64 fail("Expected IllegalArgument throw when elements is not named 'organisation' but " + t + " was instead");
65 }
66 }
67 }