ResourceMojoUtil { static Template getSingletonTemplate(KubernetesList resources) { if (resources != null) { List<HasMetadata> items = resources.getItems(); if (items != null && items.size() == 1) { HasMetadata singleEntity = items.get(0); if (singleEntity instanceof Template) { return (Template) singleEntity; } } } return null; } private  ResourceMojoUtil();   }
@Test public void getSingletonTemplateShouldReturnSingleEntry( @Mocked KubernetesList mockList, @Mocked Template mockTemplate) { new Expectations() {{ mockList.getItems(); result = Collections.singletonList(mockTemplate); }}; final Template result = ResourceMojoUtil.getSingletonTemplate(mockList); assertSame(mockTemplate, result); }