### Question:
CdhPackageLocationFilter implements PackageLocationFilter { @Override public boolean filterImage(Image image, Image currentImage) { if (isRelevantFieldNull(image, currentImage)) { LOGGER.debug("Image or some part of it is null: {}", image); return false; } else { String repoUrl = image.getStackDetails().getRepo().getStack().getOrDefault(currentImage.getOsType(), ""); LOGGER.debug("Matching URL: [{}]", repoUrl); return URL_PATTERN.matcher(repoUrl).find(); } }  @Override boolean filterImage(Image image, Image currentImage);  }### Answer:
@Test public void testImageNull() { boolean result = underTest.filterImage(null, mock(Image.class)); assertFalse(result); }
@Test public void testStackDetailIsNull() { boolean result = underTest.filterImage(mock(Image.class), mock(Image.class)); assertFalse(result); }
@Test public void testRepoIsNull() { Image image = mock(Image.class); when(image.getStackDetails()).thenReturn(new StackDetails("1", null, "1")); boolean result = underTest.filterImage(image, mock(Image.class)); assertFalse(result); }
@Test public void testStackIsNull() { Image image = mock(Image.class); when(image.getStackDetails()).thenReturn(new StackDetails("1", new StackRepoDetails(null, null), "1")); boolean result = underTest.filterImage(image, mock(Image.class)); assertFalse(result); }
@Test public void testCurrentImageNull() { Image image = mock(Image.class); when(image.getStackDetails()).thenReturn(new StackDetails("1", new StackRepoDetails(Map.of(), Map.of()), "1")); boolean result = underTest.filterImage(image, null); assertFalse(result); }
@Test public void testCurrentImageOsTypeEmpty() { Image image = mock(Image.class); when(image.getStackDetails()).thenReturn(new StackDetails("1", new StackRepoDetails(Map.of(), Map.of()), "1")); Image currentImage = mock(Image.class); when(currentImage.getOsType()).thenReturn(" "); boolean result = underTest.filterImage(image, currentImage); assertFalse(result); }
@Test public void testOsTypeMissing() { Image image = mock(Image.class); when(image.getStackDetails()).thenReturn(new StackDetails("1", new StackRepoDetails(Map.of(), Map.of()), "1")); Image currentImage = mock(Image.class); when(currentImage.getOsType()).thenReturn("redhat7"); boolean result = underTest.filterImage(image, currentImage); assertFalse(result); }
@Test public void testNotMatching() { Image image = mock(Image.class); when(image.getStackDetails()).thenReturn(new StackDetails("1", new StackRepoDetails(Map.of("redhat7", "http: Image currentImage = mock(Image.class); when(currentImage.getOsType()).thenReturn("redhat7"); boolean result = underTest.filterImage(image, currentImage); assertFalse(result); }
@Test public void testMatching() { Image image = mock(Image.class); when(image.getStackDetails()).thenReturn(new StackDetails("1", new StackRepoDetails(Map.of("redhat7", "http: Map.of()), "1")); Image currentImage = mock(Image.class); when(currentImage.getOsType()).thenReturn("redhat7"); boolean result = underTest.filterImage(image, currentImage); assertTrue(result); }