title: How can I unit-test javanica @HystrixCommand annotated methods?
body: <p>I am using javanica and annotating my hystrix command methods like this:</p>
  
  <pre><code>@HystrixCommand(groupKey="MY_GROUP", commandKey="MY_COMMAND" fallbackMethod="fallbackMethod")
  public Object getSomething(Object request) {
  ....
  </code></pre>
  
  <p>And I am trying to unit tests my fallback methods, without having to call them directly, i.e. I would like to call the <code>@HystrixCommand</code> annotated method and let it flow naturally into the fallback after throwing a 500 error. This all works outside of unit tests.</p>
  
  <p>In my unit tests I am using springs <code>MockRestServiceServer</code> to return 500 errors, this part is working, but Hystrix is not being initialized correctly on my unit tests. At the beginning of my test method I have:</p>
  
  <pre><code>HystrixRequestContext context = HystrixRequestContext.initializeContext();
  myService.myHystrixCommandAnnotatedMethod();
  </code></pre>
  
  <p>After this I am trying to get any hystrix command by key and checking if there are any executed commands but the list is always empty, I am using this method:</p>
  
  <pre><code>public static HystrixInvokableInfo&lt;?&gt; getHystrixCommandByKey(String key) {
      HystrixInvokableInfo&lt;?&gt; hystrixCommand = null;
      System.out.println("Current request is " + HystrixRequestLog.getCurrentRequest());
      Collection&lt;HystrixInvokableInfo&lt;?&gt;&gt; executedCommands = HystrixRequestLog.getCurrentRequest()
              .getAllExecutedCommands();
      for (HystrixInvokableInfo&lt;?&gt; command : executedCommands) {
          System.out.println("executed command is " + command.getCommandGroup().name());
          if (command.getCommandKey().name().equals(key)) {
              hystrixCommand = command;
              break;
          }
      }
      return hystrixCommand;
  }
  </code></pre>
  
  <p>I realize I am missing something in my unit tests initialization, can anyone point me in the right direction on how I can properly unit-test this?</p>