### Question:
Publisher extends AbstractMojo { public void execute() throws MojoExecutionException { getLog().info("Starting Axway Publisher"); AxwayPublishingAdapter adapter = getAxwayPublishingAdapter(); PublicationReader publicationReader = getPublicationReader(); try { final Publication publication = publicationReader.read(getStageConfigurationFile(), Publication.class); initApis(publication.getApis()); adapter.initOptionsAndArgs(publication); getLog().info(publication.toString()); publish(publication.getApis(), publication.getStage()); } catch (AbstractPublishingPluginException e) { throw e; } }  void execute(); PublicationReader getPublicationReader(); String getStageConfigurationFile(); void setStageConfigurationFile(final String stageConfiguationFile); MavenProject getProject(); void setProject(final MavenProject project);  }### Answer:
@Test public void testProcessApiGetExceptionWithWarnSeverityShouldNotThrowException() throws AppException, MojoExecutionException { final Publication publication = createPublication() .setApis(Arrays.asList(new Api().setApiSpecification("api1").setApiConfig("config1"))); when(publicationReader.read(any(String.class), any())).thenReturn(publication); doThrow(new AppException("", ErrorCode.NO_CHANGE)).when(axwayPublishingAdapter).processApi(any(), anyString()); sut.execute(); }
@Test(expected = BreakingChangeException.class) public void testProcessApiGetExceptionWithErrorSeverityShouldThrowException() throws AppException, MojoExecutionException { final Publication publication = createPublication() .setApis(Arrays.asList(new Api().setApiSpecification("api1").setApiConfig("config1"))); when(publicationReader.read(any(String.class), any())).thenReturn(publication); doThrow(new AppException("", ErrorCode.BREAKING_CHANGE_DETECTED)).when(axwayPublishingAdapter) .processApi(any(), anyString()); sut.execute(); }
@Test public void testProcessApiWithNoApisShouldNotCallMethodProcessApi() throws MojoExecutionException, AppException { when(publicationReader.read(anyString(), any())).thenReturn(createPublication()); sut.execute(); verify(axwayPublishingAdapter, Mockito.never()).processApi(any(), anyString()); }
@Test public void testPublisherWithNApisShouldCallNtimesMethodProcessApi() throws MojoExecutionException, AppException { final Publication publication = createPublication().setApis( Arrays.asList(new Api().setApiSpecification("api1").setApiConfig("config1"), new Api().setApiSpecification("spec2").setApiConfig("config2"), new Api().setApiSpecification("spec3").setApiConfig("config3"))); when(publicationReader.read(any(String.class), any())).thenReturn(publication); sut.execute(); verify(axwayPublishingAdapter, times(publication.getApis().size())).processApi(any(), anyString()); }
@Test public void testPublisherShouldCorrectApisWithAbsolutPath() throws MojoExecutionException, AppException { final Publication publication = createPublication() .setApis(Arrays.asList(new Api().setApiSpecification("api1").setApiConfig("config1"))); when(publicationReader.read(any(String.class), any())).thenReturn(publication); sut.execute(); assertThat(publication.getApis().size(), is(1)); assertThat(publication.getApis().get(0).getApiSpecification(), CoreMatchers.not("api1")); assertThat(publication.getApis().get(0).getApiConfig(), CoreMatchers.not("config1")); }