During testing, there may be occasional failures and occasional successes. The code is as follows:
@Test
void testGetLoggingConsumers() {
LoggingHandler loggingHandler = new LoggingHandler();
SyncMcpLoggingConsumerProvider provider = new SyncMcpLoggingConsumerProvider(List.of(loggingHandler));
// Hava a bug: bean. getClass(). getDeclaredMethods() in the doGetClassMethods method called in provider. getLoggingConsumers(), the order of the returned method list is not fixed, so values cannot be obtained through index
List<Consumer<LoggingMessageNotification>> consumers = provider.getLoggingConsumers();
// Sort consumers by method name to ensure stable ordering
// Should find 2 annotated methods
assertThat(consumers).hasSize(2);
// Test the first consumer
LoggingMessageNotification notification = new LoggingMessageNotification(LoggingLevel.INFO, "test-logger", "This is a test message");
consumers.get(0).accept(notification);
// Verify that the method was called
assertThat(loggingHandler.lastNotification).isEqualTo(notification);
// Test the second consumer
consumers.get(1).accept(notification);
// Verify that the method was called
assertThat(loggingHandler.lastLevel).isEqualTo(notification.level());
assertThat(loggingHandler.lastLogger).isEqualTo(notification.logger());
assertThat(loggingHandler.lastData).isEqualTo(notification.data());
}
Reason for bug: bean. getClass(). getDeclaredMethods() in the doGetClassMethods method called in provider. getLoggingConsumers(), the order of the returned method list is not fixed, so values cannot be obtained through index