Skip to content

Commit

Permalink
Reduce some unnecessary Guava usage
Browse files Browse the repository at this point in the history
  • Loading branch information
chadlwilson committed Jan 19, 2024
1 parent 5cc08ca commit 43e3615
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package com.thoughtworks.go.server.service;

import com.google.common.collect.ImmutableMap;
import com.thoughtworks.go.config.*;
import com.thoughtworks.go.config.elastic.ClusterProfile;
import com.thoughtworks.go.config.elastic.ElasticProfile;
Expand All @@ -30,10 +29,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import java.util.*;

import static com.thoughtworks.go.domain.JobResult.Passed;
import static com.thoughtworks.go.domain.JobResult.Unknown;
Expand Down Expand Up @@ -321,7 +317,7 @@ void shouldCreateJobPlan() {
@Test
void shouldAddElasticProfileOnJobPlan() {
ElasticProfile elasticProfile = new ElasticProfile("id", "prod-cluster");
DefaultSchedulingContext context = new DefaultSchedulingContext("foo", new Agents(), ImmutableMap.of("id", elasticProfile));
DefaultSchedulingContext context = new DefaultSchedulingContext("foo", new Agents(), Map.of("id", elasticProfile));

ArtifactTypeConfigs artifactTypeConfigs = new ArtifactTypeConfigs();
JobConfig jobConfig = new JobConfig(new CaseInsensitiveString("test"), null, artifactTypeConfigs);
Expand All @@ -336,7 +332,7 @@ void shouldAddElasticProfileOnJobPlan() {
void shouldAddElasticProfileAndClusterProfileOnJobPlan() {
ElasticProfile elasticProfile = new ElasticProfile("id", "clusterId");
ClusterProfile clusterProfile = new ClusterProfile("clusterId", "pluginId");
DefaultSchedulingContext context = new DefaultSchedulingContext("foo", new Agents(), ImmutableMap.of("id", elasticProfile), ImmutableMap.of("clusterId", clusterProfile));
DefaultSchedulingContext context = new DefaultSchedulingContext("foo", new Agents(), Map.of("id", elasticProfile), Map.of("clusterId", clusterProfile));

ArtifactTypeConfigs artifactTypeConfigs = new ArtifactTypeConfigs();
JobConfig jobConfig = new JobConfig(new CaseInsensitiveString("test"), null, artifactTypeConfigs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
*/
package com.thoughtworks.go.plugin.access.secrets.v1;

import com.google.common.collect.Sets;
import net.javacrumbs.jsonunit.fluent.JsonFluentAssert;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;

import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;

Expand All @@ -29,7 +29,7 @@ class SecretsMessageConverterV1Test {
class lookupSecretsRequestBody {
@Test
void shouldSendLookupKeysWithSecretConfiguration() {
final String requestBody = new SecretsMessageConverterV1().lookupSecretsRequestBody(Sets.newLinkedHashSet(List.of("username", "password")), Map.of("FilePath", "/var/lib/secret.config"));
final String requestBody = new SecretsMessageConverterV1().lookupSecretsRequestBody(new LinkedHashSet<>(List.of("username", "password")), Map.of("FilePath", "/var/lib/secret.config"));

JsonFluentAssert.assertThatJson(requestBody)
.isEqualTo("""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,15 @@
import org.springframework.security.core.GrantedAuthority;
import org.springframework.util.Assert;

import java.util.HashSet;
import java.util.Set;

public class AuthorityVerifier {
private final HashSet<GrantedAuthority> grantedAuthorities;
private final Set<GrantedAuthority> grantedAuthorities;

public AuthorityVerifier(Set<GrantedAuthority> grantedAuthorities) {
Assert.notEmpty(grantedAuthorities, "granted authority must not be empty");
Assert.noNullElements(grantedAuthorities.toArray(), "granted authority must not contain null elements");
this.grantedAuthorities = new HashSet<>(grantedAuthorities);
this.grantedAuthorities = Set.copyOf(grantedAuthorities);
}

public boolean hasAnyAuthorityMatching(Set<GrantedAuthority> userAuthorities) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package com.thoughtworks.go.server.security.userdetail;

import com.google.common.collect.Sets;
import com.thoughtworks.go.server.domain.Username;
import org.springframework.security.core.GrantedAuthority;

Expand All @@ -28,7 +27,7 @@ public class GoUserPrincipal {
private final Username username;

public GoUserPrincipal(String username, String displayName, GrantedAuthority... authorities) {
this(username, displayName, Sets.newHashSet(authorities));
this(username, displayName, Set.of(authorities));
}

public GoUserPrincipal(String username, String displayName, Set<GrantedAuthority> authorities) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package com.thoughtworks.go.server.service;

import com.google.common.collect.ImmutableMap;
import com.thoughtworks.go.config.*;
import com.thoughtworks.go.config.commands.EntityConfigUpdateCommand;
import com.thoughtworks.go.config.exceptions.RecordNotFoundException;
Expand Down Expand Up @@ -536,7 +535,7 @@ class EnvironmentConfigSyncTest {

@Test
void shouldSyncEnvironmentsFromAgentAssociationInDB1() {
shouldSyncEnvironmentsFromAgentAssociationInDB(ImmutableMap.of(
shouldSyncEnvironmentsFromAgentAssociationInDB(Map.of(
"dev", "uuid1",
"test", "uuid1",
"stage", "uuid2",
Expand All @@ -546,15 +545,15 @@ void shouldSyncEnvironmentsFromAgentAssociationInDB1() {

@Test
void shouldSyncEnvironmentsFromAgentAssociationInDB2() {
shouldSyncEnvironmentsFromAgentAssociationInDB(ImmutableMap.of(
shouldSyncEnvironmentsFromAgentAssociationInDB(Map.of(
"dev", "uuid1",
"stage", "uuid2"
));
}

@Test
void shouldSyncEnvironmentsFromAgentAssociationInDB5() {
shouldSyncEnvironmentsFromAgentAssociationInDB(ImmutableMap.of(
shouldSyncEnvironmentsFromAgentAssociationInDB(Map.of(
"dev", "uuid3",
"test", "uuid3",
"stage", "uuid3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package com.thoughtworks.go.spark.spa;

import com.google.common.collect.ImmutableMap;
import com.thoughtworks.go.server.newsecurity.utils.SessionUtils;
import com.thoughtworks.go.server.service.SecurityService;
import com.thoughtworks.go.spark.Routes;
Expand Down Expand Up @@ -64,14 +63,7 @@ public ModelAndView show(Request request, Response response) {
return null;
}

Map<String, Object> meta = loginLogoutHelper.buildMeta(request);

Map<String, Object> object = ImmutableMap.<String, Object>builder()
.put("viewTitle", "Login")
.put("meta", meta)
.build();

return new ModelAndView(object, null);
return new ModelAndView(Map.of("viewTitle", "Login", "meta", loginLogoutHelper.buildMeta(request)), null);
}

private boolean securityIsDisabledOrAlreadyLoggedIn(HttpServletRequest request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package com.thoughtworks.go.spark.spa;

import com.google.common.collect.ImmutableMap;
import com.thoughtworks.go.server.newsecurity.utils.SessionUtils;
import com.thoughtworks.go.spark.Routes;
import com.thoughtworks.go.spark.SparkController;
Expand Down Expand Up @@ -50,13 +49,6 @@ public void setupRoutes() {
public ModelAndView show(Request request, Response response) {
SessionUtils.recreateSessionWithoutCopyingOverSessionState(request.raw());

Map<String, Object> meta = loginLogoutHelper.buildMeta(request);

Map<String, Object> object = ImmutableMap.<String, Object>builder()
.put("viewTitle", "Logout")
.put("meta", meta)
.build();

return new ModelAndView(object, null);
return new ModelAndView(Map.of("viewTitle", "Logout", "meta", loginLogoutHelper.buildMeta(request)), null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.thoughtworks.go.spark.spa;

import com.google.common.collect.ImmutableMap;
import com.thoughtworks.go.server.service.GoConfigService;
import com.thoughtworks.go.spark.Routes;
import com.thoughtworks.go.spark.SparkController;
Expand Down Expand Up @@ -55,12 +54,9 @@ public void setupRoutes() {
}

public ModelAndView index(Request request, Response response) {
Map<String, Object> meta = ImmutableMap.<String, Object>builder()
.put("smtp_configured", goConfigService.isSmtpEnabled())
.build();
Map<String, Object> object = Map.of(
"viewTitle", "Preferences",
"meta", meta
"meta", Map.of("smtp_configured", goConfigService.isSmtpEnabled())
);
return new ModelAndView(object, null);
}
Expand Down

0 comments on commit 43e3615

Please sign in to comment.