@Test public void fail_to_parse_file_contents() { String badFileFormat = "{\"hello\": \"world\"}"; FileHandle fileHandle = mockery.mock(FileHandle.class); mockery.checking(new Expectations() { { oneOf(fileHandleResolver).resolve(filename); try { oneOf(fileHandle).reader(); will(returnValue(new StringReader(badFileFormat))); } catch (IOException e) { throw new RuntimeException(e); } } }); try { loader.load(filename); fail(); } catch (Exception e) { assertEquals("Failed to load UI file: " + filename, e.getMessage()); assertNotNull(e.getCause()); } }
public <T extends UiElement> T load(String filename) { try { Reader reader = fileHandleResolver.resolve(filename).reader(); XmlReader xmlReader = new XmlReader(); XmlReader.Element root = xmlReader.parse(reader); return (T) processXmlTag(root); } catch (Exception e) { throw new MdxException("Failed to load UI file: " + filename, e); } }
UiXmlLoader { public <T extends UiElement> T load(String filename) { try { Reader reader = fileHandleResolver.resolve(filename).reader(); XmlReader xmlReader = new XmlReader(); XmlReader.Element root = xmlReader.parse(reader); return (T) processXmlTag(root); } catch (Exception e) { throw new MdxException("Failed to load UI file: " + filename, e); } } }
UiXmlLoader { public <T extends UiElement> T load(String filename) { try { Reader reader = fileHandleResolver.resolve(filename).reader(); XmlReader xmlReader = new XmlReader(); XmlReader.Element root = xmlReader.parse(reader); return (T) processXmlTag(root); } catch (Exception e) { throw new MdxException("Failed to load UI file: " + filename, e); } } UiXmlLoader(FileHandleResolver fileHandleResolver); }
UiXmlLoader { public <T extends UiElement> T load(String filename) { try { Reader reader = fileHandleResolver.resolve(filename).reader(); XmlReader xmlReader = new XmlReader(); XmlReader.Element root = xmlReader.parse(reader); return (T) processXmlTag(root); } catch (Exception e) { throw new MdxException("Failed to load UI file: " + filename, e); } } UiXmlLoader(FileHandleResolver fileHandleResolver); void addTagHandler(String tagName, UiElementFactory factory, UiElementPopulator... populators); T load(String filename); T load(String filename, Class<T> model); T load(String filename, T model); }
UiXmlLoader { public <T extends UiElement> T load(String filename) { try { Reader reader = fileHandleResolver.resolve(filename).reader(); XmlReader xmlReader = new XmlReader(); XmlReader.Element root = xmlReader.parse(reader); return (T) processXmlTag(root); } catch (Exception e) { throw new MdxException("Failed to load UI file: " + filename, e); } } UiXmlLoader(FileHandleResolver fileHandleResolver); void addTagHandler(String tagName, UiElementFactory factory, UiElementPopulator... populators); T load(String filename); T load(String filename, Class<T> model); T load(String filename, T model);  }