Package org.strecks.lifecycle.impl

Source Code of org.strecks.lifecycle.impl.TestInitMethodReader

package org.strecks.lifecycle.impl;

import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.isA;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
import static org.testng.Assert.*;

import java.lang.reflect.Method;

import org.strecks.exceptions.ApplicationConfigurationException;
import org.strecks.lifecycle.LifecycleMethodAware;
import org.strecks.lifecycle.impl.LifecycleMethodReader;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

public class TestInitMethodReader
{

  private LifecycleMethodReader reader;

  @BeforeMethod
  public void setUp()
  {
    reader = new LifecycleMethodReader();
  }

  @Test
  public void testInitMethodReader()
  {
    final boolean readAnnotations = reader.readAnnotations(ActionWithLifecycleMethods.class);
    assert readAnnotations;

    final LifecycleMethodAware initMethodAware = createMock(LifecycleMethodAware.class);
    initMethodAware.setInitMethod(isA(Method.class));
    initMethodAware.setCloseMethod(isA(Method.class));

    replay(initMethodAware);
    reader.populateController(initMethodAware);
    verify(initMethodAware);
  }

  @Test
  public void testWithArgs()
  {
    try
    {
      reader.readAnnotations(ActionWithInitMethodWithArgs.class);
      fail();
    }
    catch (ApplicationConfigurationException e)
    {
      assertEquals(
          e.getMessage(),
          "InitMethod annotation used with method public void org.strecks.lifecycle.impl.ActionWithInitMethodWithArgs.initMethod(java.lang.String) cannot have parameters");
    }
  }
 
  @Test
  public void testWithMultiMethods()
  {
    try
    {
      reader.readAnnotations(ActionWithMultiInitMethods.class);
      fail();
    }
    catch (ApplicationConfigurationException e)
    {
      assertEquals(
          e.getMessage(),
          "InitMethod annotation used with method public void org.strecks.lifecycle.impl.ActionWithMultiInitMethods.initMethod1(java.lang.String) cannot have parameters");
    }
  }

  @Test
  public void testWithReturnType()
  {
    try
    {
      reader.readAnnotations(ActionWithInitMethodWithReturnType.class);
      fail();
    }
    catch (ApplicationConfigurationException e)
    {
      assertEquals(
          e.getMessage(),
          "InitMethod annotation used with method public java.lang.String org.strecks.lifecycle.impl.ActionWithInitMethodWithReturnType.initMethod() cannot have a return type");
    }
  }

}
TOP

Related Classes of org.strecks.lifecycle.impl.TestInitMethodReader

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.