public long retrieveConsumerId(HttpServletRequest request) {
    Object value = request.getAttribute(CONSUMER_ID);

    try {
      return Long.parseLong(value.toString());
    } catch (Throwable ex) {
      throw new IllegalStateException("No consumer id!", ex);
    }
  }
@Test
  public void testRetrieveConsumerId() throws Exception {
    long someConsumerId = 1;

    when(request.getAttribute(ConsumerAuthUtil.CONSUMER_ID)).thenReturn(someConsumerId);

    assertEquals(someConsumerId, consumerAuthUtil.retrieveConsumerId(request));
    verify(request, times(1)).getAttribute(ConsumerAuthUtil.CONSUMER_ID);
  }