### Question:
MediaDescription implements Cloneable { @Override public String toString() { StringBuilder bldr = new StringBuilder("m="); bldr.append(media).append(" "); bldr.append(port); if (numOfPorts > 1) bldr.append("/").append(numOfPorts); bldr.append(" ").append(transport).append(" "); for (String fmt : formats) bldr.append(fmt).append(" "); bldr.delete(bldr.length() - 1, bldr.length()); bldr.append("\r\n"); if (mediaTitle != null) bldr.append("i=").append(mediaTitle).append("\r\n"); if (connection != null) bldr.append(connection); for (String bw : bandwidth.keySet()) bldr.append("b=").append(bw).append(":").append(bandwidth.get(bw)).append("\r\n"); if (key != null) bldr.append(key); for (Attribute attr : attributes.values()) bldr.append(attr); return bldr.toString(); } MediaDescription(String media, int port, String transport, String defaultFormat); String getMedia(); void setMedia(String media); int getNumOfPorts(); void setNumOfPorts(int numOfPorts); int getPort(); void setPort(int port); String getTransport(); void setTransport(String transport); List<String> getFormats(); Connection getConnection(); void setConnection(Connection connection); Key getKey(); void setKey(Key key); String getMediaTitle(); void setMediaTitle(String mediaTitle); void addBandwidth(String name, long value); void removeBandwidth(String name); Long getBandwidth(String name); void addAttribute(Attribute attribute); void removeAttribute(String name); Attribute getAttribute(String name); @Override String toString(); @Override MediaDescription clone(); static int parse(SessionDescription out, String[] lines, int offset); static final String MEDIA_AUDIO; static final String MEDIA_VIDEO; static final String MEDIA_APPLICATION; static final String MEDIA_DATA; static final String MEDIA_CONTROL; }### Answer:
@Test public void testToString() throws UnknownHostException { System.out.println("SDP media description toString test..."); MediaDescription md = new MediaDescription(MediaDescription.MEDIA_VIDEO, 8000, "RTP/AVP", "96"); md.setMediaTitle("No Title"); md.setNumOfPorts(5); md.getFormats().add("98"); Connection c = new Connection(InetAddress.getByName("127.0.0.1")); md.setConnection(c); md.addBandwidth("sb", 800); Key k = new Key("method", "key"); md.setKey(k); Attribute a1 = new Attribute("attr1", "val"); md.addAttribute(a1); String ref = "m=video 8000/5 RTP/AVP 96 98\r\n" + "i=No Title\r\n" + c.toString() + "b=sb:800\r\n" + k.toString() + a1.toString(); String tmp = md.toString(); assertEquals(ref, tmp); }