@org.junit.Test(expected = PropertyLoaderException.class) public void testLoadPropertiesFromBaseNameList_Calls_PropertyFileReader_And_Prevents_StackOverflow() { Stack<String> fileNameStack = new Stack<String>(); when(propertyLoaderFactory.getEmptyProperties()).thenReturn(properties); when(propertyLoaderFactory.getEmptyFileNameStack()).thenReturn(fileNameStack); when(propertyLoaderFactory.getStringBuilder()).thenReturn(new StringBuilder()); List<String> fileNames = Arrays.asList("file1.properties", "file2.properties"); ArrayList<String> suffixes = new ArrayList<String>(); when(propertySuffix.getSuffixes()).thenReturn(suffixes); when(propertyFileNameHelper.getFileNames( Matchers.anyCollection(), Matchers.anyCollection(), Matchers.anyString())) .thenReturn(fileNames); when(propertyLocation.getOpeners()) .thenReturn( Arrays.<PropertyLoaderOpener>asList(propertyLoaderOpener1, propertyLoaderOpener2)); when(propertyFileReader.tryToReadPropertiesFromFile( Matchers.anyString(), Matchers.anyString(), Matchers.any(PropertyLoaderOpener.class))) .thenReturn(properties); propertyLoader.load(); verify(propertyFileReader) .tryToReadPropertiesFromFile("file1.properties", "ISO-8859-1", propertyLoaderOpener1); verify(propertyFileReader) .tryToReadPropertiesFromFile("file2.properties", "ISO-8859-1", propertyLoaderOpener1); verify(propertyFileReader) .tryToReadPropertiesFromFile("file1.properties", "ISO-8859-1", propertyLoaderOpener2); verify(propertyFileReader) .tryToReadPropertiesFromFile("file2.properties", "ISO-8859-1", propertyLoaderOpener2); verify(properties, times(4)).putAll(properties); }
@Test public void testWithDefaultConfig() throws Exception { when(propertyLocation.clear()).thenReturn(propertyLocation); when(propertySuffix.clear()).thenReturn(propertySuffix); when(propertyFilter.clear()).thenReturn(propertyFilter); assertEquals(propertyLoader, propertyLoader.withDefaultConfig()); verify(propertyLocation).clear(); verify(propertySuffix).clear(); verify(propertyFilter).clear(); verify(propertyLocation).atDefaultLocations(); verify(propertySuffix).addDefaultSuffixes(); verify(propertyFilter).withDefaultFilters(); }