gnodet-bot commented on code in PR #31283: URL: https://github.com/apache/camel/pull/31283#discussion_r4772593256
########## components/camel-twilio/src/test/java/org/apache/camel/component/twilio/TwilioComponentTest.java: ########## @@ -0,0 +1,109 @@ +/* + * 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.twilio; + +import org.apache.camel.FailedToStartComponentException; +import org.apache.camel.impl.DefaultCamelContext; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +/** + * Unit tests for CAMEL-27976: component configuration shadowing and credential check bugs. + */ +class TwilioComponentTest { + + /** + * Bug 1: TwilioComponent declared a private {@code configuration} field that shadowed + * {@code AbstractApiComponent.configuration}. As a result, {@code setConfiguration()} only updated the subclass + * field, while {@code createEndpointConfiguration()} (in the superclass) always saw {@code null} and never copied + * component-level options to endpoints. + * <p> + * After the fix, {@code getConfiguration()}/{@code setConfiguration()} delegate to the superclass, so the + * superclass field is kept in sync. + */ + @Test + void testSetConfigurationIsVisibleToSuperclass() { + TwilioComponent component = new TwilioComponent(); + TwilioConfiguration cfg = new TwilioConfiguration(); + component.setConfiguration(cfg); + + Assertions.assertSame(cfg, component.getConfiguration(), + "getConfiguration() must return the instance set via setConfiguration()"); + } Review Comment: ⚠️ **Tautological test — passes with the buggy code too.** With the bug, both `setConfiguration()` and `getConfiguration()` operated on the same shadowed subclass field — this `assertSame` roundtrip would have succeeded. The actual defect was that `createEndpointConfiguration()` reads the parent's `protected configuration` field (not via `getConfiguration()`), which was always `null`. Add a reflective check on the parent field to actually validate the fix: ```suggestion @Test void testSetConfigurationIsVisibleToSuperclass() throws Exception { TwilioComponent component = new TwilioComponent(); TwilioConfiguration cfg = new TwilioConfiguration(); component.setConfiguration(cfg); Assertions.assertSame(cfg, component.getConfiguration(), "getConfiguration() must return the instance set via setConfiguration()"); // Verify the parent's protected field is populated — that is the actual bug being fixed. // createEndpointConfiguration() reads this.configuration (the parent field), not getConfiguration(). java.lang.reflect.Field parentField = org.apache.camel.support.component.AbstractApiComponent.class .getDeclaredField("configuration"); parentField.setAccessible(true); Assertions.assertSame(cfg, parentField.get(component), "super.configuration must hold the same instance — this was null with the bug"); } ``` -- 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]
