### Question:
JpaWidgetConverter implements ModelConverter<Widget, JpaWidget> { @Override public JpaWidget convert(Widget source) { return source instanceof JpaWidget ? (JpaWidget) source : createEntity(source); }  @Override JpaWidget convert(Widget source); @Override Class<Widget> getSourceType();  }### Answer:
@Test public void testNoConversion() { JpaWidget template = new JpaWidget(); assertThat(converter.convert(template), is(sameInstance(template))); }
@Test public void nullConversion() { Widget template = null; assertThat(converter.convert(template), is(nullValue())); }
@Test public void convertValid() { WidgetImpl template = new WidgetImpl("42"); template.setUrl("TEST_A"); template.setType("TEST_B"); template.setTitle("TEST_C"); template.setTitleUrl("TEST_D"); template.setUrl("TEST_E"); template.setThumbnailUrl("TEST_F"); template.setScreenshotUrl("TEST_G"); template.setAuthor("TEST_H"); template.setAuthorEmail("TEST_I"); template.setDescription("TEST_J"); template.setWidgetStatus(WidgetStatus.PUBLISHED); template.setComments(new ArrayList<WidgetComment>()); template.setOwnerId("24"); template.setDisableRendering(true); template.setRatings(new ArrayList<WidgetRating>()); template.setTags(new ArrayList<WidgetTag>()); template.setCategories(new ArrayList<Category>()); template.setFeatured(true); template.setProperties(Maps.<String,Object>newHashMap()); Widget jpaTemplate = converter.convert(template); assertThat(jpaTemplate, is(not(sameInstance((Widget)template)))); assertThat(jpaTemplate, is(instanceOf(JpaWidget.class))); assertThat(jpaTemplate.getId(), is(equalTo(template.getId()))); assertThat(jpaTemplate.getUrl(), is(equalTo(template.getUrl()))); assertThat(jpaTemplate.getType(), is(equalTo(template.getType()))); assertThat(jpaTemplate.getTitle(), is(equalTo(template.getTitle()))); assertThat(jpaTemplate.getTitleUrl(), is(equalTo(template.getTitleUrl()))); assertThat(jpaTemplate.getUrl(), is(equalTo(template.getUrl()))); assertThat(jpaTemplate.getThumbnailUrl(), is(equalTo(template.getThumbnailUrl()))); assertThat(jpaTemplate.getScreenshotUrl(), is(equalTo(template.getScreenshotUrl()))); assertThat(jpaTemplate.getAuthor(), is(equalTo(template.getAuthor()))); assertThat(jpaTemplate.getAuthorEmail(), is(equalTo(template.getAuthorEmail()))); assertThat(jpaTemplate.getDescription(), is(equalTo(template.getDescription()))); assertThat(jpaTemplate.getWidgetStatus(), is(equalTo(template.getWidgetStatus()))); assertThat(jpaTemplate.getComments(), is(equalTo(template.getComments()))); assertThat(jpaTemplate.getOwnerId(), is(equalTo(template.getOwnerId()))); assertThat(jpaTemplate.isDisableRendering(), is(equalTo(template.isDisableRendering()))); assertThat(jpaTemplate.getRatings(), is(equalTo(template.getRatings()))); assertThat(jpaTemplate.getTags(), is(equalTo(template.getTags()))); assertThat(jpaTemplate.getCategories(), is(equalTo(template.getCategories()))); assertThat(jpaTemplate.isFeatured(), is(equalTo(template.isFeatured()))); assertThat(jpaTemplate.getProperties(), is(equalTo(template.getProperties()))); }