@Test public void testGetEntity() throws Exception { Smil smil = new SmilImpl(); SmilResponse response = new SmilResponseImpl(smil); try { response.getEntity(); fail("getEntity should fail, if entity count is zero"); } catch (SmilException ex) { } response = new SmilResponseImpl(smil, smil.getBody()); try { assertSame(smil.getBody(), response.getEntity()); assertSame(1, response.getEntities().length); assertSame(smil.getBody(), response.getEntities()[0]); } catch (SmilException ex) { fail("getEntity should return the entity"); } response = new SmilResponseImpl(smil, new SmilObject[]{smil.getHead(), smil.getBody()}); try { response.getEntity(); fail("get entity should fail if there are more then one entities set."); } catch (SmilException ex) { } }
@Override public SmilObject getEntity() throws SmilException { if (entities.length == 0) { throw new SmilException("There is no entity."); } if (entities.length > 1) { throw new SmilException("There is more than one entity."); } return entities[0]; }
SmilResponseImpl implements SmilResponse { @Override public SmilObject getEntity() throws SmilException { if (entities.length == 0) { throw new SmilException("There is no entity."); } if (entities.length > 1) { throw new SmilException("There is more than one entity."); } return entities[0]; } }
SmilResponseImpl implements SmilResponse { @Override public SmilObject getEntity() throws SmilException { if (entities.length == 0) { throw new SmilException("There is no entity."); } if (entities.length > 1) { throw new SmilException("There is more than one entity."); } return entities[0]; } private  SmilResponseImpl();  SmilResponseImpl(Smil smil);  SmilResponseImpl(Smil smil, SmilObject entity);  SmilResponseImpl(Smil smil, SmilObject[] entities); }
SmilResponseImpl implements SmilResponse { @Override public SmilObject getEntity() throws SmilException { if (entities.length == 0) { throw new SmilException("There is no entity."); } if (entities.length > 1) { throw new SmilException("There is more than one entity."); } return entities[0]; } private  SmilResponseImpl();  SmilResponseImpl(Smil smil);  SmilResponseImpl(Smil smil, SmilObject entity);  SmilResponseImpl(Smil smil, SmilObject[] entities); @XmlElement(type = SmilImpl.class, required = true) @Override Smil getSmil(); @Override int getEntitiesCount(); @Override SmilObject getEntity(); @Override SmilObject[] getEntities(); @Override String toXml(); static SmilResponse fromXml(String smilResponseXml); }
SmilResponseImpl implements SmilResponse { @Override public SmilObject getEntity() throws SmilException { if (entities.length == 0) { throw new SmilException("There is no entity."); } if (entities.length > 1) { throw new SmilException("There is more than one entity."); } return entities[0]; } private  SmilResponseImpl();  SmilResponseImpl(Smil smil);  SmilResponseImpl(Smil smil, SmilObject entity);  SmilResponseImpl(Smil smil, SmilObject[] entities); @XmlElement(type = SmilImpl.class, required = true) @Override Smil getSmil(); @Override int getEntitiesCount(); @Override SmilObject getEntity(); @Override SmilObject[] getEntities(); @Override String toXml(); static SmilResponse fromXml(String smilResponseXml);  }