NetUtil { public static String getPrimaryDomain() { String requestURL = getRequest().getRequestURL().toString(); if (requestURL.startsWith("http: return "127.0.0.1"; } Matcher m = DOMAIN_PATTERN.matcher(requestURL); return m.find() ? m.group() : ""; }  static String getIpAddr(); static String getCookieValue(String name); static String getCurSessionId(); static String getPrimaryDomain(); static String getAccessUrl(); static String getUserAgent(); static HttpServletRequest getRequest(); final static String SESSION_ID; static final String USER_AGENT; }
@Test public void getPrimaryDomain() throws Exception { when(request.getRequestURL()).thenReturn(new StringBuffer("http: assertThat(NetUtil.getPrimaryDomain()).isEqualTo("chukai.pro"); when(request.getRequestURL()).thenReturn(new StringBuffer("http: assertThat(NetUtil.getPrimaryDomain()).isEqualTo("chukai.pro"); when(request.getRequestURL()).thenReturn(new StringBuffer("http: assertThat(NetUtil.getPrimaryDomain()).isEqualTo("chukai.pro"); when(request.getRequestURL()).thenReturn(new StringBuffer("http: assertThat(NetUtil.getPrimaryDomain()).isEqualTo("chukai.pro"); }