### Question:
JpaWidgetRatingConverter { public JpaWidgetRating convert(WidgetRating source, String widgetId) { return source instanceof JpaWidgetRating ? (JpaWidgetRating) source : createEntity(source, widgetId); }  Class<WidgetRating> getSourceType(); JpaWidgetRating convert(WidgetRating source, String widgetId);  }### Answer:
@Test public void testNoConversion() { JpaWidgetRating template = new JpaWidgetRating(); assertThat(converter.convert(template, "1"), is(sameInstance(template))); }
@Test public void nullConversion() { WidgetRating template = null; assertThat(converter.convert(template, "1"), is(nullValue())); }
@Test public void convertValid() { WidgetRating template = new WidgetRatingImpl("1"); template.setScore(1); template.setUserId("42"); JpaWidgetRating jpaTemplate = converter.convert(template, "24"); assertThat(jpaTemplate, is(not(sameInstance(template)))); assertThat(jpaTemplate, is(instanceOf(JpaWidgetRating.class))); assertThat(jpaTemplate.getScore(), is(equalTo(template.getScore()))); assertThat(jpaTemplate.getUserId(), is(equalTo(template.getUserId()))); }