From 1a36e4c793288c12709d4969c0aee07fbb76edf9 Mon Sep 17 00:00:00 2001 From: Andreas Stahlbauer Date: Tue, 5 Nov 2024 09:51:32 +0100 Subject: [PATCH] TS-31571 Test fixed --- .../agent/options/AgentOptionsParserTest.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/agent/src/test/java/com/teamscale/jacoco/agent/options/AgentOptionsParserTest.java b/agent/src/test/java/com/teamscale/jacoco/agent/options/AgentOptionsParserTest.java index 27a0676a8..2b74cb0e8 100644 --- a/agent/src/test/java/com/teamscale/jacoco/agent/options/AgentOptionsParserTest.java +++ b/agent/src/test/java/com/teamscale/jacoco/agent/options/AgentOptionsParserTest.java @@ -27,7 +27,6 @@ public class AgentOptionsParserTest { private TeamscaleCredentials teamscaleCredentials; - private final AgentOptionsParser parser = new AgentOptionsParser(new CommandLineLogger(), null, null, null); private Path configFile; /** The mock server to run requests against. */ protected MockWebServer mockWebServer; @@ -104,7 +103,7 @@ public void environmentConfigIdOverridesCommandLineOptions() throws Exception { mockWebServer.enqueue(new MockResponse().setBody(JsonUtils.serialize(registration))); AgentOptionsParser parser = new AgentOptionsParser(new CommandLineLogger(), "my-config", null, teamscaleCredentials); - AgentOptions options = parseAndThrow("teamscale-partition=bar"); + AgentOptions options = parseAndThrow(parser, "teamscale-partition=bar"); assertThat(options.teamscaleServer.partition).isEqualTo("foo"); } @@ -113,7 +112,7 @@ public void environmentConfigIdOverridesCommandLineOptions() throws Exception { public void environmentConfigFileOverridesCommandLineOptions() throws Exception { AgentOptionsParser parser = new AgentOptionsParser(new CommandLineLogger(), null, configFile.toString(), teamscaleCredentials); - AgentOptions options = parseAndThrow("teamscale-partition=from-command-line"); + AgentOptions options = parseAndThrow(parser, "teamscale-partition=from-command-line"); assertThat(options.teamscaleServer.partition).isEqualTo("from-config-file"); } @@ -128,7 +127,7 @@ public void environmentConfigFileOverridesConfigId() throws Exception { mockWebServer.enqueue(new MockResponse().setBody(JsonUtils.serialize(registration))); AgentOptionsParser parser = new AgentOptionsParser(new CommandLineLogger(), "my-config", configFile.toString(), teamscaleCredentials); - AgentOptions options = parseAndThrow("teamscale-partition=from-command-line"); + AgentOptions options = parseAndThrow(parser, "teamscale-partition=from-command-line"); assertThat(options.teamscaleServer.partition).isEqualTo("from-config-file"); } @@ -232,21 +231,24 @@ public void mustPreserveDefaultExcludes() throws Exception { @Test public void teamscalePropertiesCredentialsUsedAsDefaultButOverridable() throws Exception { - AgentOptionsParser parser = new AgentOptionsParser(new CommandLineLogger(), null, null, teamscaleCredentials); - - assertThat(parseAndThrow("teamscale-project=p,teamscale-partition=p").teamscaleServer.userName).isEqualTo( + assertThat(parseAndThrow(new AgentOptionsParser(new CommandLineLogger(), null, null, teamscaleCredentials), "teamscale-project=p,teamscale-partition=p").teamscaleServer.userName).isEqualTo( "user"); - assertThat(parseAndThrow( + assertThat(parseAndThrow(new AgentOptionsParser(new CommandLineLogger(), null, null, teamscaleCredentials), "teamscale-project=p,teamscale-partition=p,teamscale-user=user2").teamscaleServer.userName).isEqualTo( "user2"); } - private AgentOptions parseAndThrow(String options) throws Exception { + private AgentOptions parseAndThrow(AgentOptionsParser parser, String options) throws Exception { AgentOptions result = parser.parse(options); parser.throwOnCollectedErrors(); return result; } + private AgentOptions parseAndThrow(String options) throws Exception { + AgentOptionsParser parser = new AgentOptionsParser(new CommandLineLogger(), null, null, null); + return parseAndThrow(parser, options); + } + /** * Delete created coverage folders */