@Test public void should_throw_error_if_file_not_found() { try { parser.parse("abc.txt"); failWhenExpectingException(); } catch (ParsingException e) { assertThat(e.getMessage()).isEqualTo("Unable to open file abc.txt"); } }
@Test public void should_parse_file_in_classpath() { KeyStrokeMappingProvider mappingProvider = parser.parse("keyboard-mapping.txt"); assertThatContainsDefaultMappings(mappingProvider); Collection<KeyStrokeMapping> mappings = mappingProvider.keyStrokeMappings(); assertThat(mappings) .contains( mapping('a', VK_A, NO_MASK), mapping('A', VK_A, SHIFT_MASK), mapping(',', VK_COMMA, NO_MASK)); }
@Test public void should_parse_file() throws Exception { File f = null; try { f = createMappingFile("a, A, NO_MASK"); KeyStrokeMappingProvider mappingProvider = parser.parse(f); assertThatContainsDefaultMappings(mappingProvider); Collection<KeyStrokeMapping> mappings = mappingProvider.keyStrokeMappings(); assertThat(mappings).contains(mapping('a', VK_A, NO_MASK)); } finally { if (f != null) { f.delete(); } } }
@Test(expected = IllegalArgumentException.class) public void should_throw_error_if_file_does_not_exist() { parser.parse(new File("abc.xyz")); }
@Test(expected = NullPointerException.class) public void should_throw_error_if_file_is_null() { File file = null; parser.parse(file); }
@Test(expected = IllegalArgumentException.class) public void should_throw_error_if_file_name_is_empty() { parser.parse(""); }