ConsumerAuthUtil { 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); } } ConsumerAuthUtil(final ConsumerService consumerService); Long getConsumerId(String token); void storeConsumerId(HttpServletRequest request, Long consumerId); long retrieveConsumerId(HttpServletRequest request);  }
@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); }
@Test(expected = IllegalStateException.class) public void testRetrieveConsumerIdWithConsumerIdNotSet() throws Exception { consumerAuthUtil.retrieveConsumerId(request); }
@Test(expected = IllegalStateException.class) public void testRetrieveConsumerIdWithConsumerIdInvalid() throws Exception { String someInvalidConsumerId = "abc"; when(request.getAttribute(ConsumerAuthUtil.CONSUMER_ID)).thenReturn(someInvalidConsumerId); consumerAuthUtil.retrieveConsumerId(request); }