Skip to content

Commit

Permalink
Update buildFinished action tests to test against objects instead o…
Browse files Browse the repository at this point in the history
…f mocks
  • Loading branch information
pshevche committed Apr 15, 2024
1 parent 2e220f9 commit 6a927d9
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.mockito.junit.jupiter.MockitoExtension;

import java.util.Collections;
import java.util.List;

import static com.gradle.develocity.agent.gradle.adapters.ActionMockFixtures.doExecuteActionWith;
import static com.gradle.develocity.agent.gradle.adapters.PropertyMockFixtures.mockProperty;
Expand Down Expand Up @@ -163,11 +164,16 @@ void testBackgroundAction() {

@Test
@DisplayName("build finished action can be configured via an adapter using the new build result model")
@SuppressWarnings("Convert2Lambda")
void testBuildFinishedAction() {
// given
Throwable failure = new RuntimeException("New build failure!");
BuildResult buildResult = mock();
when(buildResult.getFailures()).thenReturn(Collections.singletonList(failure));
BuildResult buildResult = new BuildResult() {
@Override
public List<Throwable> getFailures() {
return Collections.singletonList(failure);
}
};

// and
doExecuteActionWith(buildResult).when(configuration).buildFinished(any());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.gradle.develocity.agent.gradle.adapters.enterprise;

import com.gradle.develocity.agent.gradle.adapters.ActionMockFixtures;
import com.gradle.develocity.agent.gradle.adapters.ActionMockFixtures.ArgCapturingAction;
import com.gradle.develocity.agent.gradle.adapters.BuildResultAdapter;
import com.gradle.develocity.agent.gradle.adapters.BuildScanAdapter;
Expand All @@ -17,6 +16,7 @@
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;

import java.net.URI;
import java.util.Collections;

import static com.gradle.develocity.agent.gradle.adapters.ActionMockFixtures.doExecuteActionWith;
Expand Down Expand Up @@ -158,11 +158,16 @@ void testBackgroundAction() {

@Test
@DisplayName("can run the build finished action using the proxy")
@SuppressWarnings("Convert2Lambda")
void testBuildFinishedAction() {
// given
Throwable failure = new RuntimeException("Boom!");
BuildResult buildResult = mock();
when(buildResult.getFailure()).thenReturn(failure);
BuildResult buildResult = new BuildResult() {
@Override
public Throwable getFailure() {
return failure;
}
};
doExecuteActionWith(buildResult).when(extension).buildFinished(any());

// when
Expand All @@ -177,8 +182,17 @@ void testBuildFinishedAction() {
@DisplayName("can run the build scan published action using the proxy")
void testBuildScanPublishedAction() {
// given
PublishedBuildScan scan = mock();
when(scan.getBuildScanId()).thenReturn("scanId");
PublishedBuildScan scan = new PublishedBuildScan() {
@Override
public String getBuildScanId() {
return "scanId";
}

@Override
public URI getBuildScanUri() {
return null;
}
};
doExecuteActionWith(scan).when(extension).buildScanPublished(any());

// when
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package com.gradle.develocity.agent.gradle.adapters.enterprise;

import com.gradle.develocity.agent.gradle.adapters.ActionMockFixtures;
import com.gradle.develocity.agent.gradle.adapters.ActionMockFixtures.ArgCapturingAction;
import com.gradle.develocity.agent.gradle.adapters.BuildResultAdapter;
import com.gradle.develocity.agent.gradle.adapters.DevelocityAdapter;
import com.gradle.develocity.agent.gradle.adapters.PublishedBuildScanAdapter;
import com.gradle.enterprise.gradleplugin.GradleEnterpriseExtension;
import com.gradle.scan.plugin.BuildResult;
import com.gradle.scan.plugin.BuildScanExtension;
import com.gradle.scan.plugin.PublishedBuildScan;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;

import java.net.URI;
import java.util.Collections;

import static com.gradle.develocity.agent.gradle.adapters.ActionMockFixtures.doExecuteActionWith;
Expand All @@ -25,7 +27,6 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
public class BuildScanExtension_1_X_AdapterTest {
Expand Down Expand Up @@ -221,11 +222,16 @@ void testBackgroundAction() {

@Test
@DisplayName("build finished action can be configured via an adapter using the new build result model")
@SuppressWarnings("Convert2Lambda")
void testBuildFinishedAction() {
// given
Throwable failure = new RuntimeException("Old build failure!");
com.gradle.scan.plugin.BuildResult buildResult = mock();
when(buildResult.getFailure()).thenReturn(failure);
BuildResult buildResult = new BuildResult() {
@Override
public Throwable getFailure() {
return failure;
}
};

// and
doExecuteActionWith(buildResult).when(extension).buildFinished(any());
Expand All @@ -242,8 +248,17 @@ void testBuildFinishedAction() {
@DisplayName("build scan published action can be configured via an adapter using the new scan model")
void testBuildScanPublishedAction() {
// given
com.gradle.scan.plugin.PublishedBuildScan publishedScan = mock();
when(publishedScan.getBuildScanId()).thenReturn("scanId");
PublishedBuildScan publishedScan = new PublishedBuildScan() {
@Override
public String getBuildScanId() {
return "scanId";
}

@Override
public URI getBuildScanUri() {
return null;
}
};
doExecuteActionWith(publishedScan).when(extension).buildScanPublished(any());

// when
Expand Down

0 comments on commit 6a927d9

Please sign in to comment.