예제 #1
0
  @Test
  public void givenCloseTag_WhenParse_ThenNameOfTheTagEqualsNameOfTheInputTag() {
    String inputString = "<name></name>";

    handler =
        new Handler() {
          @Override
          public void handle(Element element) {
            myElement = element;
          }
        };
    builder.onCloseTag(handler);
    parser = builder.build();
    parser.parse(inputString);

    assertEquals("name", myElement.getName());
  }
예제 #2
0
  @Test
  public void givenTagWithSingleTagElement_WhenParseWholeTag_ThenOnSingleTagInvokedAndCheckName() {
    String inputString = "<? xml ?><tagname param = \"param 'value'\"/>";

    handler =
        new Handler() {
          @Override
          public void handle(Element element) {
            myElement = element;
          }
        };
    builder.onSingleTag(handler);
    parser = builder.build();
    parser.parse(inputString);

    assertEquals("tagname", myElement.getName());
  }
예제 #3
0
  @Test
  public void givenErrorSingleTag_WhenParse_ThenOnErrorTagInvoked() {
    String inputString = "<? xml ?><tagname param = \"param 'value'\"/6>";

    handler =
        new Handler() {
          @Override
          public void handle(Element element) {
            myElement = element;
          }
        };
    builder.onError(handler);
    parser = builder.build();
    parser.parse(inputString);
    String actual = myElement.getValue();

    assertEquals("XML Syntax Error", actual);
  }
예제 #4
0
  @Test
  public void givenOpenTag_WhenParse_ThenTypeOfTheTagEqualsOPEN() {
    String inputString = "<name>";

    handler =
        new Handler() {
          @Override
          public void handle(Element element) {
            myElement = element;
          }
        };
    builder.onOpenTag(handler);
    parser = builder.build();
    parser.parse(inputString);
    TagElementType actual = myElement.getType();
    TagElementType expected = TagElementType.OPEN;

    assertEquals(expected, actual);
  }
예제 #5
0
  @Test
  public void givenCommentInsideTextValue() {
    String inputString = "<? xml ?><tagname>Text<!--comment_text-->Value</tagname>";

    handler =
        new Handler() {
          @Override
          public void handle(Element element) {
            myElement = element;
          }
        };
    builder.onTextValue(handler);
    parser = builder.build();
    parser.parse(inputString);
    String expected = "TextValue";
    String actual = myElement.getValue();

    assertEquals(expected, actual);
  }
예제 #6
0
  @Test
  public void givenValidTagWithTextValue_WhenParseWholeTag_ThenOnTextValueInvoked() {
    String inputString = "<? xml ?><tagname>TextValue</tagname>";

    handler =
        new Handler() {
          @Override
          public void handle(Element element) {
            myElement = element;
          }
        };
    builder.onTextValue(handler);
    parser = builder.build();
    parser.parse(inputString);
    String expected = "TextValue";
    String actual = myElement.getValue();

    assertEquals(expected, actual);
  }
예제 #7
0
  @Test
  public void givenHeader_WhenParse_ThenTypeOfTheTagEqualsHEADER() {
    String inputString = "<? xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?>";

    handler =
        new Handler() {
          @Override
          public void handle(Element element) {
            myElement = element;
          }
        };
    builder.onStart(handler);
    parser = builder.build();
    parser.parse(inputString);
    TagElementType actual = myElement.getType();
    TagElementType expected = TagElementType.HEADER;

    assertEquals(expected, actual);
  }
예제 #8
0
  @Test
  public void givenCloseTag_WhenHandleSetsTypeOfTag_ThenTypeOfTheTagEqualsCLOSE() {

    String inputString = "<name></name>";

    handler =
        new Handler() {
          @Override
          public void handle(Element element) {
            myElement = element;
          }
        };
    builder.onCloseTag(handler);
    parser = builder.build();
    parser.parse(inputString);
    TagElementType actual = myElement.getType();
    TagElementType expected = TagElementType.CLOSE;

    assertEquals(expected, actual);
  }
예제 #9
0
  @Test
  public void givenTagWithAttributes_WhenParseWholeTag_ThenOnOpenTagInvokedAndCheckAttributes() {
    String inputString = "<? xml ?><tagname param = \"param value\">TextValue</tagname>";

    handler =
        new Handler() {
          @Override
          public void handle(Element element) {
            myElement = element;
          }
        };
    builder.onOpenTag(handler);
    parser = builder.build();
    parser.parse(inputString);
    String expected = "param value";
    Map<String, String> params = myElement.getParams();
    String actual = params.get("param");

    assertEquals(expected, actual);
  }