marți, 23 mai 2017

RabbitMQ Server Installation on Windows - Steps

RabbitMQ runs on the Erlang virtual runtime.
Install Eralng (8.3)
  • Check for environment variable (ERLANG_HOME)
RABBITMQ WEB MANAGEMENT PLUGIN INSTALLATION
  • Cmd to C:\Program Files\RabbitMQ Server\rabbitmq_server-3.6.9\sbin
    • Run rabbitmq-plugins.bat enable rabbitmq_management
    • Restart rabbitmq service
rabbitmq-service.bat stop 
rabbitmq-service.bat install 
rabbitmq-service.bat start

  • Username: guest
  • Password: guest

vineri, 19 mai 2017

PowerMockito: Verify if a static method is called

import static org.junit.Assert.assertEquals; 

import org.junit.Test; 
import org.junit.runner.RunWith; 
import org.mockito.Mockito; 
import org.mockito.invocation.InvocationOnMock; 
import org.mockito.stubbing.Answer; 
import org.powermock.api.mockito.PowerMockito; 
import org.powermock.core.classloader.annotations.PrepareForTest; 
import org.powermock.modules.junit4.PowerMockRunner; 



@RunWith(PowerMockRunner.class
@PrepareForTest({GlobalUtil.class}) 
public class Test_StaticMethodCall { 
     
    public static boolean called = false
     
    @Test 
    public void test_check_static_error_method_is_called() throws Exception { 
         
        //arrange 
        called = false
        // mock static GlobalUtil 
        PowerMockito.mockStatic(GlobalUtil.class); 
         
        //set called on true if error method is called 
        PowerMockito.doAnswer(new Answer<Void>() { 

            @Override 
            public Void answer(InvocationOnMock invocation) throws Throwable { 
                Test_StaticMethodCall.called = true
                return null
            } 
        }).when(GlobalUtil.class"error", Mockito.anyObject(), Mockito.any(Throwable.class));
         
        //act 
        new ClassToBeTested().testMethod(); 
         
        assertEquals(true, called); 
    } 
     


class GlobalUtil { 
    public static void error(Object msg, Throwable t) { 
        //do something 
    } 


class ClassToBeTested { 
    public void testMethod() { 
        Boolean nullBollean = null
        try { 
            if (nullBollean) { 
                //do something 
            } 
        } catch (Exception ex) { 
            GlobalUtil.error("Somthing is wrong", ex); 
        } 
    } 
}