### Question:
DubboUtils { public static String getApplication(Invocation invocation, String defaultValue) { if (invocation == null || invocation.getAttachments() == null) { throw new IllegalArgumentException("Bad invocation instance"); } return invocation.getAttachment(SENTINEL_DUBBO_APPLICATION_KEY, defaultValue); } private  DubboUtils(); static String getApplication(Invocation invocation, String defaultValue); static String getResourceName(Invoker<?> invoker, Invocation invocation); static final String SENTINEL_DUBBO_APPLICATION_KEY; }### Answer:
@Test public void testGetApplication() { Invocation invocation = mock(Invocation.class); when(invocation.getAttachments()).thenReturn(new HashMap<>()); when(invocation.getAttachment(DubboUtils.SENTINEL_DUBBO_APPLICATION_KEY, "")) .thenReturn("consumerA"); String application = DubboUtils.getApplication(invocation, ""); verify(invocation).getAttachment(DubboUtils.SENTINEL_DUBBO_APPLICATION_KEY, ""); assertEquals("consumerA", application); }
@Test(expected = IllegalArgumentException.class) public void testGetApplicationNoAttachments() { Invocation invocation = mock(Invocation.class); when(invocation.getAttachments()).thenReturn(null); when(invocation.getAttachment(DubboUtils.SENTINEL_DUBBO_APPLICATION_KEY, "")) .thenReturn("consumerA"); DubboUtils.getApplication(invocation, ""); fail("No attachments in invocation, IllegalArgumentException should be thrown!"); }