BasicConfiguration { public String[] getBasePackages() { String packages = servletContext.getInitParameter(BasicConfiguration.BASE_PACKAGES_PARAMETER_NAME); if (packages == null) { throw new MissingConfigurationException(BasicConfiguration.BASE_PACKAGES_PARAMETER_NAME + " context-param not found in web.xml. Set this parameter with your base package"); } return packages.trim().split(",\\s*"); } BasicConfiguration(ServletContext servletContext); ContainerProvider getProvider(); boolean hasBasePackages(); String[] getBasePackages(); String getEncoding(); String getWebinfClassesDirectory(); ServletContext getServletContext(); boolean isClasspathScanningEnabled(); static final String CONTAINER_PROVIDER; static final String ENCODING; static final String BASE_PACKAGES_PARAMETER_NAME; static final String SCANNING_PARAM; }
@Test(expected = MissingConfigurationException.class) public void shouldThrowMissingConfigurationExceptionIfHasNoBasePackages() { when(context.getInitParameter(BasicConfiguration.CONTAINER_PROVIDER)).thenReturn(null); config.getBasePackages(); }
@Test public void shouldReturnBasePackagesWhenInitParamNotNull() throws ServletException { when(context.getInitParameter(BasicConfiguration.BASE_PACKAGES_PARAMETER_NAME)).thenReturn("some.packages"); assertThat(config.getBasePackages(), is(new String[] {"some.packages"})); }
@Test public void shouldReturnBasePackagesArrayWhenInitParamNotNullAndHasComas() throws ServletException { when(context.getInitParameter(BasicConfiguration.BASE_PACKAGES_PARAMETER_NAME)).thenReturn("some.packages,other.packages"); assertThat(config.getBasePackages(), is(new String[] {"some.packages", "other.packages"})); }
@Test public void shouldReturnBasePackagesArrayWhenInitParamNotNullAndHasComasAndSpaces() throws ServletException { when(context.getInitParameter(BasicConfiguration.BASE_PACKAGES_PARAMETER_NAME)).thenReturn("some.packages, \n other.packages"); assertThat(config.getBasePackages(), is(new String[] {"some.packages", "other.packages"})); }
@Test public void shouldReturnBasePackagesArrayWhenInitParamHasLeadingAndTrailingSpaces() throws ServletException { when(context.getInitParameter(BasicConfiguration.BASE_PACKAGES_PARAMETER_NAME)).thenReturn(" \nsome.package\n "); assertThat(config.getBasePackages(), is(new String[] {"some.package"})); }