Esempio n. 1
0
  public void testExceptions() {
    boolean thrown;

    // 1. Verify NullPointer exception which occurs when attempting
    //    to set a null ActionListener
    //
    thrown = false;
    try {
      application.setActionListener(null);
    } catch (NullPointerException e) {
      thrown = true;
    }
    assertTrue(thrown);

    // 3. Verify NullPointer exception which occurs when attempting
    //    to set a null NavigationHandler
    //
    thrown = false;
    try {
      application.setNavigationHandler(null);
    } catch (NullPointerException e) {
      thrown = true;
    }
    assertTrue(thrown);

    // 4. Verify NPE occurs when attempting to set
    // a null PropertyResolver
    thrown = false;
    try {
      application.setPropertyResolver(null);
    } catch (NullPointerException npe) {
      thrown = true;
    }
    assertTrue(thrown);

    // 5. Verify NPE occurs when attempting to set
    // a null VariableResolver
    thrown = false;
    try {
      application.setVariableResolver(null);
    } catch (NullPointerException npe) {
      thrown = true;
    }
    assertTrue(thrown);

    // 5. Verify ISE occurs when attempting to set
    // a VariableResolver after a request has been processed
    ApplicationAssociate associate =
        ApplicationAssociate.getInstance(getFacesContext().getExternalContext());
    associate.setRequestServiced();
    thrown = false;
    try {
      application.setVariableResolver(application.getVariableResolver());
    } catch (IllegalStateException e) {
      thrown = true;
    }
    assertTrue(thrown);

    // 6. Verify ISE occurs when attempting to set
    // a PropertyResolver after a request has been processed
    thrown = false;
    try {
      application.setPropertyResolver(application.getPropertyResolver());
    } catch (IllegalStateException e) {
      thrown = true;
    }
    assertTrue(thrown);

    // 7. Verify NullPointer exception which occurs when attempting
    //    to get a ValueBinding with a null ref
    //
    thrown = false;
    try {
      application.createValueBinding(null);
    } catch (Exception e) {
      thrown = true;
    }
    assertTrue(thrown);

    // 8.Verify NullPointerException occurs when attempting to pass a
    // null VariableResolver
    //
    thrown = false;
    try {
      application.setVariableResolver(null);
    } catch (NullPointerException e) {
      thrown = true;
    }
    assertTrue(thrown);

    // 9. Verify NullPointer exception which occurs when attempting
    //    to set a null StateManager
    //
    thrown = false;
    try {
      application.setStateManager(null);
    } catch (NullPointerException e) {
      thrown = true;
    }
    assertTrue(thrown);

    thrown = false;
    try {
      application.createValueBinding("improperexpression");
    } catch (ReferenceSyntaxException e) {
      thrown = true;
    }
    assertFalse(thrown);

    thrown = false;
    try {
      application.createValueBinding("improper expression");
    } catch (ReferenceSyntaxException e) {
      thrown = true;
    }
    assertFalse(thrown);

    thrown = false;
    try {
      application.createValueBinding("improper\texpression");
    } catch (ReferenceSyntaxException e) {
      thrown = true;
    }
    assertFalse(thrown);

    thrown = false;
    try {
      application.createValueBinding("improper\rexpression");
    } catch (ReferenceSyntaxException e) {
      thrown = true;
    }
    assertFalse(thrown);

    thrown = false;
    try {
      application.createValueBinding("improper\nexpression");
    } catch (ReferenceSyntaxException e) {
      thrown = true;
    }
    assertFalse(thrown);

    thrown = false;
    try {
      application.createValueBinding("#improperexpression");
    } catch (ReferenceSyntaxException e) {
      thrown = true;
    }
    assertFalse(thrown);

    thrown = false;
    try {
      application.createValueBinding("#{improperexpression");
    } catch (ReferenceSyntaxException e) {
      thrown = true;
    }
    assertTrue(thrown);

    thrown = false;
    try {
      application.createValueBinding("improperexpression}");
    } catch (ReferenceSyntaxException e) {
      thrown = true;
    }
    assertFalse(thrown);

    thrown = false;
    try {
      application.createValueBinding("{improperexpression}");
    } catch (ReferenceSyntaxException e) {
      thrown = true;
    }
    assertFalse(thrown);

    thrown = false;
    try {
      application.createValueBinding("improperexpression}#");
    } catch (ReferenceSyntaxException e) {
      thrown = true;
    }
    assertFalse(thrown);

    thrown = false;
    try {
      application.createValueBinding("#{proper[\"a key\"]}");
    } catch (ReferenceSyntaxException e) {
      thrown = true;
    }
    assertFalse(thrown);

    try {
      application.createValueBinding("#{proper[\"a { } key\"]}");
    } catch (ReferenceSyntaxException e) {
      thrown = true;
    }
    assertFalse(thrown);

    try {
      application.createValueBinding("bean.a{indentifer");
    } catch (ReferenceSyntaxException e) {
      thrown = true;
    }
    assertFalse(thrown);

    thrown = false;
    try {
      application.createValueBinding("bean['invalid'");
    } catch (ReferenceSyntaxException e) {
      thrown = true;
    }
    assertFalse(thrown);

    thrown = false;
    try {
      application.createValueBinding("bean[[\"invalid\"]].foo");
    } catch (ReferenceSyntaxException e) {
      thrown = true;
    }
    assertFalse(thrown);

    thrown = false;
    try {
      application.createValueBinding("#{bean[\"[a\"]}");
    } catch (ReferenceSyntaxException e) {
      thrown = true;
    }
    assertFalse(thrown);

    try {
      application.createValueBinding("#{bean[\".a\"]}");
    } catch (ReferenceSyntaxException e) {
      thrown = true;
    }
    assertFalse(thrown);
  }