package com.google.gdata.data; import static org.junit.Assert.*; import java.io.File; import java.io.FileWriter; import java.io.IOException; import org.junit.Test; import com.google.gdata.util.common.xml.XmlWriter; public class TestSource { @Test public void getLinkTest() { Source src = new Source(); Link l = src.getLink("bla", "blah"); assertNull(l); Link link = new Link(); link.setRel("blah"); link.setType("blah"); link.setTitle("test"); src.addLink(link); l = src.getLink("blah", "blah"); assertEquals(l, link); } @Test public void removeLinksTest() { Source src = new Source(); Link link = new Link(); link.setRel("blah"); link.setType("blah"); link.setTitle("test"); src.addLink(link); src.removeLinks("blah", "blah"); Link l = src.getLink("blah", "blah"); assertNull(l); } @Test public void addHtmlLinkTest() { Source src = new Source(); src.addHtmlLink("l1", null, null); Link l = src.getLink(Link.Rel.ALTERNATE, Link.Type.HTML); assertNotNull(l); assertEquals("l1", l.getHref()); } @Test public void generateAtomTest() { Source src = new Source(); XmlWriter w = null; FileWriter fw = null; boolean exception = false; try { fw = new FileWriter(new File("dummy")); w = new XmlWriter(fw); } catch (IOException e) { exception = true; } finally { if(exception) { if(fw != null) { try { fw.close(); } catch (IOException e) { } } } } assertFalse(exception); ExtensionProfile extProfile = new ExtensionProfile(); try { src.generateAtom(w, extProfile); } catch (IOException e) { exception = true; } finally { if(fw != null) { try { fw.close(); } catch (IOException e) { } } if(w != null) { try { w.close(); } catch (IOException e) { } } } assertFalse(exception); } }