### Question:
StagingDeployMojo extends StagingMojo { @Override public void execute() throws MojoExecutionException, MojoFailureException { if (skipNexusStagingDeployMojo) { getLog().info("Skipping NXRM Staging Deploy Mojo at user's demand."); return; } maybeWarnAboutDeprecatedStagingModeProperty(); doExecute(); }  @Override void execute();  }### Answer:
@Test(expected = MojoFailureException.class) public void executeFailsWhenOffline() throws Exception { underTest.setOffline(true); underTest.execute(); }
@Test(expected = IllegalArgumentException.class) public void executeFailsWhenSecDispatcherThrowsException() throws Exception { when(secDispatcher.decrypt(anyString())).thenThrow(new SecDispatcherException()); underTest.setSecDispatcher(secDispatcher); underTest.execute(); }
@Test public void createTagWhenSetAndDoesNotExist() throws Exception { when(client.getTag(TAG)).thenReturn(Optional.empty()); underTest.execute(); verify(client).createTag(TAG); }
@Test public void skipCreateTagWhenTagExists() throws Exception { underTest.execute(); verify(client, never()).createTag(TAG); }
@Test public void saveTagToPropertiesFile() throws Exception { underTest.execute(); File directory = underTest.getWorkDirectoryRoot(); String props = readFileToString(new File(directory, "staging/staging.properties")); assertThat(props, containsString("staging.tag=" + TAG)); }
@Test public void upload() throws Exception { underTest.execute(); ArgumentCaptor<Component> componentArgumentCaptor = ArgumentCaptor.forClass(Component.class); verify(client).upload(eq(REPOSITORY), componentArgumentCaptor.capture(), eq(TAG)); Component component = componentArgumentCaptor.getValue(); Map<String, String> attributes = component.getAttributes(); assertThat(attributes.get(ARTIFACT_ID_KEY), is(equalTo(ARTIFACT_ID))); assertThat(attributes.get(GROUP_ID_KEY), is(equalTo(GROUP_ID))); assertThat(attributes.get(VERSION_KEY), is(equalTo(VERSION))); Collection<Asset> assets = component.getAssets(); assertThat(assets.size(), is(equalTo(3))); List<Asset> pomAssets = assets.stream().filter(this::isPomAsset).collect(toList()); assertThat(pomAssets.size(), is(equalTo(1))); assertThat(pomAssets.get(0).getFilename(), is(equalTo(getPom().getName()))); assertThat(pomAssets.get(0).getData(), notNullValue()); for (Asset asset : assets.stream().filter(asset -> !isPomAsset(asset)).collect(toList())) { Map<String, String> assetAttributes = asset.getAttributes(); assertThat(assetAttributes.get(EXTENSION_KEY), is(equalTo(EXTENSION))); assertThat(assetAttributes.get(CLASSIFIER_KEY), is(equalTo(CLASSIFIER))); } }
@Test(expected = MojoFailureException.class) public void mojoFailureExceptionOnUploadFail() throws Exception { doThrow(new RuntimeException()).when(client).upload(any(), any(), any()); underTest.execute(); }
@Test public void deployOnlyAttachedArtifactsAndPomWhenNoMainArtifact() throws Exception { when(artifact.getFile()).thenReturn(null); underTest.execute(); ArgumentCaptor<Component> componentArgumentCaptor = ArgumentCaptor.forClass(Component.class); verify(client).upload(eq(REPOSITORY), componentArgumentCaptor.capture(), eq(TAG)); Component component = componentArgumentCaptor.getValue(); assertThat(component.getAssets().size(), is(equalTo(2))); Map<String, String> firstAssetAttributes = component.getAssets().iterator().next().getAttributes(); assertThat(firstAssetAttributes.get(EXTENSION_KEY), is(equalTo("pom"))); assertThat(firstAssetAttributes.size(), is(equalTo(1))); }
@Test(expected = IllegalArgumentException.class) public void throwIllegalArgumentExceptionWhenIncorrectServerId() throws Exception { when(settings.getServer(anyString())).thenReturn(null); underTest.execute(); }