### Question:
RestletRealmRouter extends Router { public static String getRealmFromRequest(Request request) { ConcurrentMap<String, Object> attributes = request.getAttributes(); if (attributes == null || attributes.get(REALM) == null) { return null; } return attributes.get(REALM).toString(); } RestletRealmRouter(RestRealmValidator realmValidator, CoreWrapper coreWrapper); @Override void setDefaultRoute(Route defaultRoute); static String getRealmFromRequest(Request request); static final String REALM; static final String REALM_INFO; static final String REALM_URL; }### Answer:
@Test public void shouldExtractRealmFromRequest() { String key = "badger"; Request mockRequest = generateRequest(); mockRequest.getAttributes().put(RestletRealmRouter.REALM, key); String result = RestletRealmRouter.getRealmFromRequest(mockRequest); assertThat(result).isEqualTo(key); }
@Test public void shouldReturnNullWhenMissing() { Request mockRequest = generateRequest(); String result = RestletRealmRouter.getRealmFromRequest(mockRequest); assertThat(result).isNull(); }