Skip to content

Commit

Permalink
Fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
marchermans committed May 13, 2024
1 parent 222d308 commit 08aa5c6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentMatchers;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;

import java.util.*;
import java.util.function.Consumer;
Expand All @@ -21,6 +23,7 @@ public class ConfigurationUtilsTest {
@Test
public void findCompileClasspathSourceSetHandlesImplementationAndCompileClasspath() {
final Configuration compileClasspath = mock(Configuration.class);
final Configuration compileOnly = mock(Configuration.class);
final Configuration implementation = mock(Configuration.class);

final ConfigurationContainer configurations = mock(ConfigurationContainer.class);
Expand All @@ -30,6 +33,7 @@ public void findCompileClasspathSourceSetHandlesImplementationAndCompileClasspat
final SourceSetContainer sourceSets = mock(SourceSetContainer.class);
final SourceSet mainSourceSet = mock(SourceSet.class);

when(configurations.findByName("compileOnly")).thenReturn(compileOnly);
when(configurations.findByName("compileClasspath")).thenReturn(compileClasspath);
when(configurations.findByName("implementation")).thenReturn(implementation);

Expand All @@ -41,20 +45,22 @@ public void findCompileClasspathSourceSetHandlesImplementationAndCompileClasspat
when(sourceSets.getByName("main")).thenReturn(mainSourceSet);
when(mainSourceSet.getCompileClasspathConfigurationName()).thenReturn("compileClasspath");
when(mainSourceSet.getImplementationConfigurationName()).thenReturn("implementation");
when(mainSourceSet.getCompileOnlyConfigurationName()).thenReturn("compileOnly");
doAnswer(invocationOnMock -> {
final Consumer<SourceSet> argument = invocationOnMock.getArgument(0);
argument.accept(mainSourceSet);
return null;
}).when(sourceSets).forEach(ArgumentMatchers.any());

when(compileOnly.getName()).thenReturn("compileOnly");
when(compileClasspath.getName()).thenReturn("compileClasspath");
when(implementation.getName()).thenReturn("implementation");

when(compileClasspath.getExtendsFrom()).thenReturn(buildConfigurationSet(implementation));
when(compileClasspath.getExtendsFrom()).thenReturn(buildConfigurationSet(implementation, compileOnly));

final List<Configuration> result = ConfigurationUtils.findCompileOnlyConfigurationForSourceSetReplacement(project, implementation);

Assertions.assertEquals(buildConfigurationList(compileClasspath), result);
Assertions.assertEquals(buildConfigurationList(compileOnly), result);
}

@Test
Expand All @@ -72,6 +78,17 @@ public void findRuntimeClasspathSourceSetHandlesImplementationAndRuntimeClasspat
when(configurations.findByName("runtimeClasspath")).thenReturn(runtimeClasspath);
when(configurations.findByName("implementation")).thenReturn(implementation);

final List<Configuration> newConfigurations = new ArrayList<>();
when(configurations.maybeCreate(any())).thenAnswer((Answer<Configuration>) invocationOnMock -> {
final String name = invocationOnMock.getArgument(0);
final Configuration configuration = mock(Configuration.class);
when(configuration.getName()).thenReturn(name);

newConfigurations.add(configuration);

return configuration;
});

when(project.getConfigurations()).thenReturn(configurations);

when(project.getExtensions()).thenReturn(extensions);
Expand All @@ -80,6 +97,7 @@ public void findRuntimeClasspathSourceSetHandlesImplementationAndRuntimeClasspat
when(sourceSets.getByName("main")).thenReturn(mainSourceSet);
when(mainSourceSet.getRuntimeClasspathConfigurationName()).thenReturn("runtimeClasspath");
when(mainSourceSet.getImplementationConfigurationName()).thenReturn("implementation");

doAnswer(invocationOnMock -> {
final Consumer<SourceSet> argument = invocationOnMock.getArgument(0);
argument.accept(mainSourceSet);
Expand All @@ -93,7 +111,7 @@ public void findRuntimeClasspathSourceSetHandlesImplementationAndRuntimeClasspat

final List<Configuration> result = ConfigurationUtils.findRuntimeOnlyConfigurationFromSourceSetReplacement(project, implementation);

Assertions.assertEquals(buildConfigurationList(runtimeClasspath), result);
Assertions.assertEquals(newConfigurations, result);
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ spock_version=2.1
spock_groovy_version=3.0
mockito_version=4.11.0
jimfs_version=1.2
trainingwheels_version=1.0.44
trainingwheels_version=1.0.45

0 comments on commit 08aa5c6

Please sign in to comment.