vy commented on code in PR #3467:
URL: https://github.com/apache/logging-log4j2/pull/3467#discussion_r1959503982


##########
log4j-mongodb4/src/main/java/org/apache/logging/log4j/mongodb4/MongoDb4Connection.java:
##########
@@ -119,4 +121,12 @@ public String toString() {
                 "Mongo4Connection [connectionString=%s, collection=%s, 
mongoClient=%s]",
                 connectionString, collection, mongoClient);
     }
+
+    /*
+     * This method is exposed to help support unit tests for the 
MongoDbProvider class.
+     *
+     */
+    public MongoCollection<Document> getCollection() {

Review Comment:
   This method is only used by `MongoDb4ProviderTest` to get the collection 
name from a `MongoDb4Provider`. You can use `MongoDb4Provider::getConnection` 
to obtain the `MongoDb4Connection` instance, and use reflection on that 
instance to get the value of its `collection` field:
   
   ```java
   private static MongoNamespace findProviderNamespace(final MongoDb4Provider 
provider) {
       MongoDb4Connection connection = provider.getConnection();
       try {
           Field collectionField = 
connection.getClass().getDeclaredField("collection");
           collectionField.setAccessible(true);
           MongoCollection<?> collection = (MongoCollection<?>) 
collectionField.get(connection);
           return collection.getNamespace();
       } catch (Exception exception) {
           throw new RuntimeException(exception);
       }
   }
   ```
   
   Then you can replace
   
   ```java
   assertEquals(
           collectionName,
           
provider.getConnection().getCollection().getNamespace().getCollectionName());
   ```
   
   with
   
   ```java
   MongoNamespace namespace = findProviderNamespace(provider);
   assertThat(namespace.getCollectionName()).isEqualTo(collectionName);
   ```



-- 
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: notifications-unsubscr...@logging.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to