### Question:
Dag implements Serializable { protected String removeSource() { if (sources.isEmpty()) { return null; } String source = sources.iterator().next(); removeNode(source); return source; } Dag(Collection<Connection> connections); protected  Dag(SetMultimap<String, String> outgoingConnections, SetMultimap<String, String> incomingConnections); protected  Dag(Dag other); Set<Dag> splitByControlNodes(Set<String> conditionNodes, Set<String> actionNodes); Set<String> getNodes(); Set<String> getSources(); Set<String> getSinks(); Set<String> getNodeOutputs(String node); Set<String> getNodeInputs(String node); Set<String> accessibleFrom(String stage); Set<String> accessibleFrom(String stage, Set<String> stopNodes); Set<String> accessibleFrom(Set<String> stages, Set<String> stopNodes); Set<String> parentsOf(String stage); Set<String> parentsOf(String stage, final Set<String> stopNodes); Dag subsetFrom(String stage); Dag subsetFrom(String stage, Set<String> stopNodes); Dag subsetFrom(Set<String> stages); Dag subsetFrom(Set<String> stages, Set<String> stopNodes); Dag subsetAround(String stage, Set<String> childStopNodes, Set<String> parentStopNodes); Dag createSubDag(Set<String> nodes); List<String> getTopologicalOrder(); List<String> getBranch(final String node, final Set<String> stopNodes); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }### Answer:
@Test public void testRemoveSource() { Dag dag = new Dag(ImmutableSet.of( new Connection("n1", "n2"), new Connection("n1", "n3"), new Connection("n2", "n4"), new Connection("n3", "n4"))); Assert.assertEquals("n1", dag.removeSource()); Assert.assertEquals(ImmutableSet.of("n2", "n3"), dag.getSources()); Set<String> removed = ImmutableSet.of(dag.removeSource(), dag.removeSource()); Assert.assertEquals(ImmutableSet.of("n2", "n3"), removed); Assert.assertEquals(ImmutableSet.of("n4"), dag.getSources()); Assert.assertEquals("n4", dag.removeSource()); Assert.assertTrue(dag.getSources().isEmpty()); Assert.assertTrue(dag.getSinks().isEmpty()); Assert.assertNull(dag.removeSource()); }