Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(maven-plugin): log informative message when maven jkube goals ar…
…e skipped #1142 Signed-off-by: Sun Tan <sutan@redhat.com>
- Loading branch information
Showing
5 changed files
with
169 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
...-plugin/plugin/src/test/java/org/eclipse/jkube/maven/plugin/mojo/build/SkipGoalsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/** | ||
* Copyright (c) 2019 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at: | ||
* | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.jkube.maven.plugin.mojo.build; | ||
|
||
import static org.mockito.Mockito.doNothing; | ||
import static org.mockito.Mockito.never; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
import org.apache.maven.plugin.MojoExecution; | ||
import org.eclipse.jkube.kit.common.KitLogger; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Answers; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.Spy; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class SkipGoalsTest { | ||
|
||
@Mock | ||
private KitLogger log; | ||
|
||
@Mock(answer = Answers.RETURNS_DEEP_STUBS) | ||
private MojoExecution mojoExecution; | ||
|
||
@Spy | ||
@InjectMocks | ||
BuildMojo buildMojo; | ||
|
||
public void setupBuildGoal() throws Exception { | ||
doNothing().when(buildMojo).init(); | ||
doNothing().when(buildMojo).doExecute(); | ||
when(mojoExecution.getMojoDescriptor().getFullGoalName()).thenReturn("k8s:build"); | ||
} | ||
|
||
@Test | ||
public void should_execute_build_goal_if_skip_false() throws Exception { | ||
setupBuildGoal(); | ||
// given | ||
buildMojo.skip = false; | ||
// when | ||
buildMojo.execute(); | ||
// then | ||
verify(buildMojo).doExecute(); | ||
} | ||
|
||
@Test | ||
public void should_log_informative_message_when_build_goal_is_skipped() throws Exception { | ||
setupBuildGoal(); | ||
// given | ||
buildMojo.skip = true; | ||
// when | ||
buildMojo.execute(); | ||
// then | ||
verify(buildMojo, never()).doExecute(); | ||
verify(log).info("`%s` goal is skipped.", "k8s:build"); | ||
} | ||
|
||
@Spy | ||
@InjectMocks | ||
ApplyMojo applyMojo; | ||
|
||
public void setupApplyGoal() throws Exception { | ||
doNothing().when(applyMojo).init(); | ||
doNothing().when(applyMojo).executeInternal(); | ||
when(mojoExecution.getMojoDescriptor().getFullGoalName()).thenReturn("k8s:apply"); | ||
} | ||
|
||
@Test | ||
public void should_execute_apply_goal_if_skip_false() throws Exception { | ||
setupApplyGoal(); | ||
// given | ||
applyMojo.skip = false; | ||
// when | ||
applyMojo.execute(); | ||
// then | ||
verify(applyMojo).executeInternal(); | ||
} | ||
|
||
@Test | ||
public void should_log_informative_message_when_apply_goal_is_skipped() throws Exception { | ||
setupApplyGoal(); | ||
// given | ||
applyMojo.skip = true; | ||
// when | ||
applyMojo.execute(); | ||
// then | ||
verify(applyMojo, never()).executeInternal(); | ||
verify(log).info("`%s` goal is skipped.", "k8s:apply"); | ||
} | ||
|
||
} |