@Test public void formatFailsFastWhenKeysAreMissing() { try { gender.format(); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException e) { } }
@Test public void putFailsFastWhenPuttingUnknownKey() { try { gender.put("bogusKey", "whatever"); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException e) { } }
@Test public void loneCurlyBraceIsAMistake() { try { from("hi { {age}."); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException e) { } }
@Test public void emptyTokenFailsFast() { try { from("illegal {} pattern"); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException e) { } }
@Test public void keysCannotStartWithUnderscore() { try { from("{_foo}"); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException e) { } }
@Test public void singleCurlyBraceIsAMistake() { try { from("{"); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException e) { } }
@Test public void illegalStartOfTokenCharactersFailFast() { try { from("blah {NoUppercaseAllowed}"); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException e) { assertThat(e.getMessage()).isEqualTo("Unexpected first character 'N'; must be lower case a-z."); } }
@Test public void putFailUppercaseNotAllowedMiddle() { try{ from("Hello {aName}").putOptional("Name", "Eric").format(); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException e) { assertThat(e.getMessage()) // .isEqualTo("Unexpected character 'N'; expecting lower case a-z, '_', or '}'"); } }
@Test public void puttingNullValueThrowsException() { try { from("hi {name}").put("name", null); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException e) { assertThat(e).hasMessage("Null value for 'name'"); } }
@Test(expected = NoSuchElementException.class) public void invalidElementFromFStoreIterator() { final Iterator<FileStore> iterator = new SimpleUnixFileSystem( fsProvider, "/" ).getFileStores().iterator(); try { iterator.next(); } catch ( Exception e ) { fail( "first is valid" ); } iterator.next(); }
@Test(expected = NoSuchElementException.class) public void invalidElementFromRootIterator() { final Iterator<Path> iterator = new SimpleWindowsFileSystem( fsProvider, "c:\\" ).getRootDirectories().iterator(); try { iterator.next(); } catch ( Exception e ) { fail( "first is valid" ); } iterator.next(); }
@Test(expected = NoSuchElementException.class) public void invalidElementFromFStoreIterator() { final Iterator<FileStore> iterator = new SimpleWindowsFileSystem( fsProvider, "c:\\" ).getFileStores().iterator(); try { iterator.next(); } catch ( Exception e ) { fail( "first is valid" ); } iterator.next(); }
@Test(expected = NoSuchElementException.class) public void invalidElementFromRootIterator() { final Iterator<Path> iterator = new SimpleUnixFileSystem( fsProvider, "/" ).getRootDirectories().iterator(); try { iterator.next(); } catch ( Exception e ) { fail( "first is valid" ); } iterator.next(); }
@Test public void testFixedIntervalsSupported() throws Exception { for (DateIntervalType type : DateIntervalType.values()) { try { DataSetLookupFactory.newDataSetLookupBuilder().group(COLUMN_DATE).fixed(type, true); if (!DateIntervalType.FIXED_INTERVALS_SUPPORTED.contains(type)) { fail("Missing exception on a not supported fixed interval: " + type); } } catch (Exception e) { if (DateIntervalType.FIXED_INTERVALS_SUPPORTED.contains(type)) { fail("Exception on a supported fixed interval: " + type); } } } }
@Test public void shouldHaveCorrectConfiguration() { if ("debug".equals(BuildConfig.BUILD_TYPE)) { assertThat(BuildConfig.DEBUG).isTrue(); } else if ("release".equals(BuildConfig.BUILD_TYPE)) { assertThat(BuildConfig.DEBUG).isFalse(); } else { fail("build type configuration not tested or supported?"); } } }
@Test public void testFirstDayOfMonthNok() throws Exception { try { DataSetLookupFactory.newDataSetLookupBuilder() .group(COLUMN_DATE) .fixed(QUARTER, true) .firstMonth(Month.APRIL); fail("firstDayOfWeek required a DAY_OF_WEEK fixed domain."); } catch (Exception e) { // Expected. } }
@Test public void testFirstDayOfWeekNok() throws Exception { try { DataSetLookupFactory.newDataSetLookupBuilder() .group(COLUMN_DATE) .fixed(QUARTER, true) .firstDay(DayOfWeek.MONDAY); fail("firstDayOfWeek required a DAY_OF_WEEK fixed domain."); } catch (Exception e) { // Expected. } }
/** * Check if some data set rows match a given result. * @param dataSet The data set to validate. * @param x The x position of the cell to check (starting at 0). * @param y The y position of the cell to check (starting at 0). * @param expected The expected value in the given cell. */ public static void assertDataSetValue(DataSet dataSet, int x, int y, String expected) { Locale locale = Locale.ENGLISH; DataFormatterRegistry dataFormatterRegistry = DataFormatterRegistry.lookup(); Object value = dataSet.getValueAt(x,y); DataProperty prop = dataSet.getPropertyByColumn(y); DataPropertyFormatter propFormatter = dataFormatterRegistry.getPropertyFormatter(prop.getPropertyId()); String displayedValue = propFormatter.formatValue(prop, value, locale); if (!displayedValue.equals(expected)) { fail("Data set value [" + x + "," + y + "] is different. " + "Column=\"" + prop.getPropertyId() + "\" " + "Actual=\"" + displayedValue + "\" Expected=\"" + expected + "\""); } }
@Test public void simpleTests() { final FileSystem fileSystem = new SimpleUnixFileSystem( fsProvider, "/" ); assertThat( fileSystem.isOpen() ).isTrue(); assertThat( fileSystem.isReadOnly() ).isFalse(); assertThat( fileSystem.getSeparator() ).isEqualTo( System.getProperty( "file.separator" ) ); assertThat( fileSystem.provider() ).isEqualTo( fsProvider ); assertThat( fileSystem.supportedFileAttributeViews() ).isNotEmpty().hasSize( 1 ).contains( "basic" ); assertThat( fileSystem.getPath( "/path/to/file.txt" ) ).isNotNull().isEqualTo( GeneralPathImpl.create( fileSystem, "/path/to/file.txt", false ) ); assertThat( fileSystem.getPath( "/path/to/file.txt", null ) ).isNotNull().isEqualTo( GeneralPathImpl.create( fileSystem, "/path/to/file.txt", false ) ); assertThat( fileSystem.getPath( "/path", "to", "file.txt" ) ).isNotNull().isEqualTo( GeneralPathImpl.create( fileSystem, "/path/to/file.txt", false ) ); try { fileSystem.close(); fail( "can't close this fileSystem" ); } catch ( UnsupportedOperationException ex ) { } assertThat( fileSystem.getFileStores() ).isNotNull().hasSize( 1 ); assertThat( fileSystem.getFileStores().iterator().next().name() ).isEqualTo( "/" ); assertThat( fileSystem.getRootDirectories() ).isNotNull().hasSize( 1 ); assertThat( fileSystem.getRootDirectories().iterator().next().toString() ).isEqualTo( "/" ); assertThat( fileSystem.getRootDirectories().iterator().next().isAbsolute() ).isTrue(); }
@Test public void simpleTests() { final FileSystem fileSystem = new SimpleWindowsFileSystem( roots, fsProvider, "c:\\" ); assertThat( fileSystem.isOpen() ).isTrue(); assertThat( fileSystem.isReadOnly() ).isFalse(); assertThat( fileSystem.getSeparator() ).isEqualTo( "\\" ); assertThat( fileSystem.provider() ).isEqualTo( fsProvider ); assertThat( fileSystem.supportedFileAttributeViews() ).isNotEmpty().hasSize( 1 ).contains( "basic" ); assertThat( fileSystem.getPath( "c:\\path\\to\\file.txt" ) ).isNotNull().isEqualTo( GeneralPathImpl.create( fileSystem, "c:\\path\\to\\file.txt", false ) ); assertThat( fileSystem.getPath( "c:\\path\\to\\file.txt", null ) ).isNotNull().isEqualTo( GeneralPathImpl.create( fileSystem, "c:\\path\\to\\file.txt", false ) ); assertThat( fileSystem.getPath( "c:\\path", "to", "file.txt" ) ).isNotNull().isEqualTo( GeneralPathImpl.create( fileSystem, "c:\\path\\to\\file.txt", false ) ); try { fileSystem.close(); fail( "can't close this fileSystem" ); } catch ( UnsupportedOperationException ex ) { } assertThat( fileSystem.getFileStores() ).isNotNull().hasSize( 2 ); assertThat( fileSystem.getFileStores().iterator().next().name() ).isEqualTo( "c:\\" ); assertThat( fileSystem.getRootDirectories() ).isNotNull().hasSize( 2 ); assertThat( fileSystem.getRootDirectories().iterator().next().toString() ).isEqualTo( "c:\\" ); assertThat( fileSystem.getRootDirectories().iterator().next().isAbsolute() ).isTrue(); }