|  | 
| 19 | 19 | import static com.palantir.logsafe.testing.Assertions.assertThatLoggableExceptionThrownBy; | 
| 20 | 20 | import static org.assertj.core.api.Assertions.assertThat; | 
| 21 | 21 | 
 | 
|  | 22 | +import com.google.common.collect.ImmutableList; | 
|  | 23 | +import com.google.common.collect.Iterables; | 
|  | 24 | +import com.palantir.conjure.java.api.config.service.UserAgent.Agent; | 
| 22 | 25 | import com.palantir.logsafe.SafeArg; | 
|  | 26 | +import java.util.List; | 
| 23 | 27 | import org.junit.jupiter.api.Test; | 
| 24 | 28 | 
 | 
| 25 | 29 | public class UserAgentTest { | 
| @@ -59,6 +63,29 @@ public void testCorrectHeaderFormatWithoutNodeId() { | 
| 59 | 63 |         assertThat(UserAgents.format(derivedAgent)).isEqualTo("service/1.0.0 conjure/2.0.0"); | 
| 60 | 64 |     } | 
| 61 | 65 | 
 | 
|  | 66 | +    @Test | 
|  | 67 | +    void testPrimaryWithInformational() { | 
|  | 68 | +        UserAgent baseUserAgent = UserAgent.of(Agent.of("service", "1.0.0")); | 
|  | 69 | +        List<Agent> info = ImmutableList.of(Agent.of("conjure", "1.2.3"), Agent.of("jdk", "17.0.4.1")); | 
|  | 70 | +        UserAgent first = UserAgent.of(baseUserAgent, info); | 
|  | 71 | +        assertThat(first).satisfies(agent -> { | 
|  | 72 | +            assertThat(agent.primary()).isEqualTo(baseUserAgent.primary()); | 
|  | 73 | +            assertThat(agent.informational()).hasSize(2).isEqualTo(info); | 
|  | 74 | +            assertThat(UserAgents.format(agent)).isEqualTo("service/1.0.0 conjure/1.2.3 jdk/17.0.4.1"); | 
|  | 75 | +            assertThat(UserAgents.parse(UserAgents.format(agent))).isEqualTo(agent); | 
|  | 76 | +            assertThat(UserAgent.of(agent, ImmutableList.of())).isEqualTo(agent); | 
|  | 77 | +        }); | 
|  | 78 | + | 
|  | 79 | +        List<Agent> moreInfo = ImmutableList.of(Agent.of("test", "4.5.6")); | 
|  | 80 | +        assertThat(UserAgent.of(first, moreInfo)).satisfies(agent -> { | 
|  | 81 | +            assertThat(agent.primary()).isEqualTo(baseUserAgent.primary()); | 
|  | 82 | +            assertThat(agent.informational()).hasSize(3).containsExactlyElementsOf(Iterables.concat(info, moreInfo)); | 
|  | 83 | +            assertThat(UserAgents.format(agent)).isEqualTo("service/1.0.0 conjure/1.2.3 jdk/17.0.4.1 test/4.5.6"); | 
|  | 84 | +            assertThat(UserAgents.parse(UserAgents.format(agent))).isEqualTo(agent); | 
|  | 85 | +            assertThat(UserAgent.of(agent, ImmutableList.of())).isEqualTo(agent); | 
|  | 86 | +        }); | 
|  | 87 | +    } | 
|  | 88 | + | 
| 62 | 89 |     @Test | 
| 63 | 90 |     public void testInvalidServiceName() { | 
| 64 | 91 |         assertThatLoggableExceptionThrownBy(() -> UserAgent.Agent.of("invalid service name", "1.0.0")) | 
|  | 
0 commit comments