Skip to content
This repository has been archived by the owner on Aug 2, 2024. It is now read-only.

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeWang1127 committed Oct 18, 2023
1 parent e92eae9 commit 53b3c4f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>4.7.3.5</version>
<version>4.7.3.6</version>
<configuration>
<excludeFilterFile>spotbugs-exclude.xml</excludeFilterFile>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class CloudSdkAppEngineFactory {
private final CloudSdkMojo mojo;

public CloudSdkAppEngineFactory(CloudSdkMojo mojo) {
this.mojo = mojo;
this.mojo = mojo.clone();
}

/** Constructs an object used for auth. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.codehaus.plexus.util.xml.Xpp3Dom;

/** Abstract Mojo from which all goals inherit. */
public abstract class CloudSdkMojo extends AbstractMojo {
public abstract class CloudSdkMojo extends AbstractMojo implements Cloneable {

/** Optional parameter to configure the location of the Google Cloud SDK. */
@Parameter(property = "cloudSdkHome", required = false)
Expand Down Expand Up @@ -126,12 +126,35 @@ public MavenProject getMavenProject() {
}

public MavenSession getMavenSession() {
return mavenSession;
return mavenSession.clone();
}

@VisibleForTesting
/* For use with tests only. */
public void setSkip(boolean skip) {
this.skip = skip;
}

@Override
public CloudSdkMojo clone() {
CloudSdkMojo clone;
try {
clone = (CloudSdkMojo) super.clone();
} catch (CloneNotSupportedException e) {
throw new AssertionError();
}

clone.deepCopy(this);
return clone;
}

private void deepCopy(CloudSdkMojo mojo) {
this.cloudSdkHome = mojo.cloudSdkHome;
this.cloudSdkVersion = mojo.cloudSdkVersion;
this.serviceAccountKeyFile = mojo.serviceAccountKeyFile;
this.verbosity = mojo.verbosity;
this.pluginDescriptor = mojo.pluginDescriptor;
this.mavenProject = mojo.mavenProject;
this.mavenSession = mojo.mavenSession;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
Expand All @@ -56,11 +55,11 @@ public class CloudSdkAppEngineFactoryTest {

@Mock private CloudSdkDownloader cloudSdkDownloader;
@Mock private CloudSdkChecker cloudSdkChecker;

@InjectMocks private CloudSdkAppEngineFactory factory;
private CloudSdkAppEngineFactory factory;

@Before
public void wireUp() {
when(mojoMock.clone()).thenReturn(mojoMock);
when(mojoMock.getCloudSdkHome()).thenReturn(CLOUD_SDK_HOME);
when(mojoMock.getCloudSdkVersion()).thenReturn(null);
when(mojoMock.getArtifactId()).thenReturn(ARTIFACT_ID);
Expand All @@ -83,6 +82,7 @@ public void wireUp() {
Mockito.eq(logMock),
Mockito.<SdkComponent>anyList(),
Mockito.anyBoolean());
factory = new CloudSdkAppEngineFactory(mojoMock);
}

@Test
Expand Down

0 comments on commit 53b3c4f

Please sign in to comment.