davsclaus commented on code in PR #25357: URL: https://github.com/apache/camel/pull/25357#discussion_r3720550405
########## components/camel-google/camel-google-mail/src/test/java/org/apache/camel/component/google/mail/stream/GoogleMailStreamConsumerBodyTest.java: ########## @@ -0,0 +1,125 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.google.mail.stream; + +import java.nio.charset.StandardCharsets; +import java.util.List; + +import com.google.api.client.util.Base64; +import com.google.api.services.gmail.model.Message; +import com.google.api.services.gmail.model.MessagePart; +import com.google.api.services.gmail.model.MessagePartBody; +import com.google.api.services.gmail.model.MessagePartHeader; +import org.apache.camel.Exchange; +import org.apache.camel.ExchangePattern; +import org.apache.camel.impl.DefaultCamelContext; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatCode; + +/** + * Verifies how the stream consumer turns a Gmail message into an exchange: which format it asks the API for, and where + * it picks the body up from. + */ +class GoogleMailStreamConsumerBodyTest { + + private DefaultCamelContext context; + + @AfterEach + void tearDown() { + if (context != null) { + context.stop(); + } + } + + private GoogleMailStreamConsumer consumer(boolean raw) throws Exception { + context = new DefaultCamelContext(); + context.start(); + GoogleMailStreamEndpoint endpoint = context.getEndpoint( + "google-mail-stream://index?clientId=id&clientSecret=secret&raw=" + raw, + GoogleMailStreamEndpoint.class); Review Comment: Minor resource leak: `theRawOptionAsksForTheRawFormat` calls `consumer()` twice — the first call creates and starts a `DefaultCamelContext`, then the second call overwrites `this.context` without stopping the first one. The orphaned context is never cleaned up by `@AfterEach`. Suggestion — stop any previous context before creating a new one: ```suggestion private GoogleMailStreamConsumer consumer(boolean raw) throws Exception { if (context != null) { context.stop(); } context = new DefaultCamelContext(); ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
