Skip to content

Commit

Permalink
rename mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
mpeddada1 committed May 28, 2024
1 parent d941895 commit bb7c98d
Showing 1 changed file with 39 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ protected ExecutorService delegate() {
@Mock private ProgressEventDispatcher progressDispatcher;
@Mock private ExecutorService executorService;

@Mock private Image builtArm64AndLinuxImage;
@Mock private Image builtAmd64AndWindowsImage;

@Mock private Image baseImage1;
@Mock private Image baseImage2;

private StepsRunner stepsRunner;

@Before
Expand Down Expand Up @@ -186,102 +192,88 @@ public void testIsImagePushed_skipExistingImageEnabledAndManifestNotPresent() {
@Test
public void testFetchBuildImageForLocalBuild_matchingOsAndArch()
throws ExecutionException, InterruptedException {
Image mockImage1 = Mockito.mock(Image.class);
Image mockImage2 = Mockito.mock(Image.class);
Image baseImage1 = Mockito.mock(Image.class);
Image baseImage2 = Mockito.mock(Image.class);
when(mockImage1.getArchitecture()).thenReturn("arch1");
when(mockImage1.getOs()).thenReturn("os1");
when(mockImage1.getArchitecture()).thenReturn("arch2");
when(mockImage1.getOs()).thenReturn("os2");

when(builtArm64AndLinuxImage.getArchitecture()).thenReturn("arm64");
when(builtArm64AndLinuxImage.getOs()).thenReturn("linux");
when(builtAmd64AndWindowsImage.getArchitecture()).thenReturn("amd64");
when(builtAmd64AndWindowsImage.getOs()).thenReturn("windows");
when(executorService.submit(Mockito.any(Callable.class)))
.thenReturn(
Futures.immediateFuture(
ImmutableMap.of(
baseImage1,
Futures.immediateFuture(mockImage1),
Futures.immediateFuture(builtArm64AndLinuxImage),
baseImage2,
Futures.immediateFuture(mockImage2))));
Futures.immediateFuture(builtAmd64AndWindowsImage))));
stepsRunner.buildImages(progressDispatcherFactory);
Optional<Image> expectedImage = stepsRunner.fetchBuiltImageForLocalBuild("os2", "arch2");

assertThat(expectedImage.get().getOs()).isEqualTo("os2");
assertThat(expectedImage.get().getArchitecture()).isEqualTo("arch2");
Optional<Image> expectedImage = stepsRunner.fetchBuiltImageForLocalBuild("linux", "arm64");

assertThat(expectedImage.get().getOs()).isEqualTo("linux");
assertThat(expectedImage.get().getArchitecture()).isEqualTo("arm64");
}

@Test
public void testFetchBuildImageForLocalBuild_differentOsAndArch()
throws ExecutionException, InterruptedException {
Image builtImage1 = Mockito.mock(Image.class);
Image builtImage2 = Mockito.mock(Image.class);
Image baseImage1 = Mockito.mock(Image.class);
Image baseImage2 = Mockito.mock(Image.class);
when(builtImage1.getArchitecture()).thenReturn("os1");
when(builtImage1.getOs()).thenReturn("arch1");
when(builtImage2.getArchitecture()).thenReturn("os2");
when(builtImage2.getOs()).thenReturn("arch2");
when(builtArm64AndLinuxImage.getArchitecture()).thenReturn("arm64");
when(builtArm64AndLinuxImage.getOs()).thenReturn("linux");
when(builtAmd64AndWindowsImage.getArchitecture()).thenReturn("amd64");
when(builtAmd64AndWindowsImage.getOs()).thenReturn("windows");
when(executorService.submit(Mockito.any(Callable.class)))
.thenReturn(
Futures.immediateFuture(
ImmutableMap.of(
baseImage1,
Futures.immediateFuture(builtImage1),
Futures.immediateFuture(builtArm64AndLinuxImage),
baseImage2,
Futures.immediateFuture(builtImage2))));
Futures.immediateFuture(builtAmd64AndWindowsImage))));
stepsRunner.buildImages(progressDispatcherFactory);
Optional<Image> expectedImage = stepsRunner.fetchBuiltImageForLocalBuild("linux", "arm64");

Optional<Image> expectedImage = stepsRunner.fetchBuiltImageForLocalBuild("os", "arch");

assertThat(expectedImage.isPresent()).isFalse();
}

@Test
public void testFetchBuildImageForLocalBuild_matchingOsDifferentArch()
throws ExecutionException, InterruptedException {
Image builtImage1 = Mockito.mock(Image.class);
Image builtImage2 = Mockito.mock(Image.class);
Image baseImage1 = Mockito.mock(Image.class);
Image baseImage2 = Mockito.mock(Image.class);
when(builtImage1.getArchitecture()).thenReturn("arch1");
when(builtImage1.getOs()).thenReturn("os1");
when(builtImage2.getArchitecture()).thenReturn("arch2");
when(builtImage2.getOs()).thenReturn("os1");
when(builtArm64AndLinuxImage.getArchitecture()).thenReturn("arm64");
when(builtArm64AndLinuxImage.getOs()).thenReturn("linux");
when(builtAmd64AndWindowsImage.getArchitecture()).thenReturn("amd64");
when(builtAmd64AndWindowsImage.getOs()).thenReturn("windows");
when(executorService.submit(Mockito.any(Callable.class)))
.thenReturn(
Futures.immediateFuture(
ImmutableMap.of(
baseImage1,
Futures.immediateFuture(builtImage1),
Futures.immediateFuture(builtArm64AndLinuxImage),
baseImage2,
Futures.immediateFuture(builtImage2))));
Futures.immediateFuture(builtAmd64AndWindowsImage))));
stepsRunner.buildImages(progressDispatcherFactory);
Optional<Image> expectedImage = stepsRunner.fetchBuiltImageForLocalBuild("os1", "arch3");

Optional<Image> expectedImage = stepsRunner.fetchBuiltImageForLocalBuild("linux", "arch");

assertThat(expectedImage.isPresent()).isFalse();
}

@Test
public void testFetchBuildImageForLocalBuild_differentOsMatchingArch()
throws ExecutionException, InterruptedException {
Image builtImage1 = Mockito.mock(Image.class);
Image builtImage2 = Mockito.mock(Image.class);
Image baseImage1 = Mockito.mock(Image.class);
Image baseImage2 = Mockito.mock(Image.class);
when(builtImage1.getArchitecture()).thenReturn("arch1");
when(builtImage1.getOs()).thenReturn("os1");
when(builtImage2.getArchitecture()).thenReturn("arch2");
when(builtImage2.getOs()).thenReturn("os2");
when(builtArm64AndLinuxImage.getArchitecture()).thenReturn("arm64");
when(builtArm64AndLinuxImage.getOs()).thenReturn("linux");
when(builtAmd64AndWindowsImage.getArchitecture()).thenReturn("amd64");
when(builtAmd64AndWindowsImage.getOs()).thenReturn("windows");
when(executorService.submit(Mockito.any(Callable.class)))
.thenReturn(
Futures.immediateFuture(
ImmutableMap.of(
baseImage1,
Futures.immediateFuture(builtImage1),
Futures.immediateFuture(builtArm64AndLinuxImage),
baseImage2,
Futures.immediateFuture(builtImage2))));
Futures.immediateFuture(builtAmd64AndWindowsImage))));
stepsRunner.buildImages(progressDispatcherFactory);

Optional<Image> expectedImage = stepsRunner.fetchBuiltImageForLocalBuild("os3", "arch1");
Optional<Image> expectedImage = stepsRunner.fetchBuiltImageForLocalBuild("os", "arm64");

assertThat(expectedImage.isPresent()).isFalse();
}
Expand Down

0 comments on commit bb7c98d

Please sign in to comment.