Package samples.junit4.easymock

Source Code of samples.junit4.easymock.EasyMockAndPowerMockMixTest

package samples.junit4.easymock;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
import org.powermock.modules.junit4.PowerMockRunner;
import samples.Service;
import samples.privatefield.SimplePrivateFieldServiceClass;

import static org.easymock.EasyMock.*;
import static org.junit.Assert.assertEquals;
import static org.powermock.reflect.Whitebox.setInternalState;

/**
* This test verifies that you can mix EasyMock and PowerMock.
*/
@RunWith(PowerMockRunner.class)
@SuppressStaticInitializationFor("samples.privatefield.SimplePrivateFieldServiceClass")
public class EasyMockAndPowerMockMixTest {

  @Test
  public void testSimplePrivateFieldServiceClass() throws Exception {
    SimplePrivateFieldServiceClass tested = new SimplePrivateFieldServiceClass();
    Service serviceMock = createMock(Service.class);
    setInternalState(tested, "service", serviceMock, SimplePrivateFieldServiceClass.class);

    final String expected = "Hello world!";
    expect(serviceMock.getServiceMessage()).andReturn(expected);

    replay(serviceMock);
    final String actual = tested.useService();

    verify(serviceMock);

    assertEquals(expected, actual);
  }

}
TOP

Related Classes of samples.junit4.easymock.EasyMockAndPowerMockMixTest

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.