### Question:
Heaplets { public static Heaplet getHeaplet(Class<?> c) { Heaplet heaplet; for (HeapletFactory factory : SERVICES) { heaplet = factory.newInstance(c); if (heaplet != null) { return heaplet; } } heaplet = Loader.newInstance(c.getName() + "$Heaplet", Heaplet.class); if (heaplet == null) { heaplet = Loader.newInstance(c.getName() + "Heaplet", Heaplet.class); } return heaplet; } private  Heaplets(); static Heaplet getHeaplet(Class<?> c);  }### Answer:
@Test public void shouldUseInnerClassHeaplet() throws Exception { Heaplet heaplet = Heaplets.getHeaplet(Book.class); assertThat(heaplet) .isNotNull() .isInstanceOf(Book.Heaplet.class); assertThat(heaplet.create(Name.of("Book"), json(object()), heap)) .isInstanceOf(Book.class); }
@Test public void shouldUsePrefixedClassHeaplet() throws Exception { Heaplet heaplet = Heaplets.getHeaplet(Author.class); assertThat(heaplet) .isNotNull() .isInstanceOf(AuthorHeaplet.class); assertThat(heaplet.create(Name.of("Author"), json(object()), heap)) .isInstanceOf(Author.class); }
@Test public void shouldUseHeapletFactory() throws Exception { Heaplet heaplet = Heaplets.getHeaplet(Editor.class); assertThat(heaplet) .isNotNull() .isInstanceOf(EditorHeapletFactory.EditorHeaplet.class); assertThat(heaplet.create(Name.of("Editor"), json(object()), heap)) .isInstanceOf(Editor.class); }
@Test public void shouldFailToFindAnyCompatibleHeaplet() throws Exception { assertThat(Heaplets.getHeaplet(Publisher.class)).isNull(); assertThat(Heaplets.getHeaplet(Book2.class)).isNull(); assertThat(Heaplets.getHeaplet(Book3.class)).isNull(); assertThat(Heaplets.getHeaplet(Book4.class)).isNull(); }