Skip to content

Commit a6dcb4f

Browse files
committed
Formatting
1 parent c1dd909 commit a6dcb4f

File tree

3 files changed

+62
-45
lines changed

3 files changed

+62
-45
lines changed

log4j-mongodb/src/main/java/org/apache/logging/log4j/mongodb/MongoDbConnection.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
*/
1717
package org.apache.logging.log4j.mongodb;
1818

19-
import com.mongodb.ConnectionString;
2019
import com.mongodb.MongoException;
2120
import com.mongodb.client.MongoClient;
2221
import com.mongodb.client.MongoCollection;
@@ -59,7 +58,6 @@ private static MongoCollection<Document> getOrCreateMongoCollection(
5958
}
6059
}
6160

62-
6361
private final MongoCollection<Document> collection;
6462
private final MongoClient mongoClient;
6563

@@ -70,8 +68,7 @@ public MongoDbConnection(
7068
final boolean isCapped,
7169
final Long sizeInBytes) {
7270
this.mongoClient = mongoClient;
73-
this.collection =
74-
getOrCreateMongoCollection(mongoDatabase, collectionName, isCapped, sizeInBytes);
71+
this.collection = getOrCreateMongoCollection(mongoDatabase, collectionName, isCapped, sizeInBytes);
7572
}
7673

7774
@Override
@@ -105,16 +102,14 @@ public void insertObject(final NoSqlObject<Document> object) {
105102

106103
@Override
107104
public String toString() {
108-
return String.format(
109-
"Mongo4Connection [collection=%s, mongoClient=%s]", collection, mongoClient);
105+
return String.format("Mongo4Connection [collection=%s, mongoClient=%s]", collection, mongoClient);
110106
}
111107

112108
/*
113109
* This method is exposed to help support unit tests for the MongoDbProvider class.
114110
*
115111
*/
116-
public MongoCollection<Document> getCollection(){
112+
public MongoCollection<Document> getCollection() {
117113
return this.collection;
118114
}
119-
120115
}

log4j-mongodb/src/main/java/org/apache/logging/log4j/mongodb/MongoDbProvider.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public MongoDbProvider build() {
7373
}
7474

7575
String effectiveDatabaseName = databaseName != null ? databaseName : connectionString.getDatabase();
76-
String effectiveCollectionName = collectionName != null ? collectionName: connectionString.getCollection();
76+
String effectiveCollectionName = collectionName != null ? collectionName : connectionString.getCollection();
7777
// Validate the provided databaseName property
7878
try {
7979
MongoNamespace.checkDatabaseNameValidity(effectiveDatabaseName);
@@ -89,7 +89,8 @@ public MongoDbProvider build() {
8989
return null;
9090
}
9191

92-
return new MongoDbProvider(connectionString, capped, collectionSize, effectiveDatabaseName, effectiveCollectionName);
92+
return new MongoDbProvider(
93+
connectionString, capped, collectionSize, effectiveDatabaseName, effectiveCollectionName);
9394
}
9495

9596
public B setConnectionStringSource(final String connectionStringSource) {
@@ -142,7 +143,12 @@ public static <B extends Builder<B>> B newBuilder() {
142143
private final MongoDatabase mongoDatabase;
143144
private final ConnectionString connectionString;
144145

145-
private MongoDbProvider(final ConnectionString connectionString, final boolean isCapped, final Long collectionSize, final String databaseName, final String collectionName) {
146+
private MongoDbProvider(
147+
final ConnectionString connectionString,
148+
final boolean isCapped,
149+
final Long collectionSize,
150+
final String databaseName,
151+
final String collectionName) {
146152

147153
LOGGER.debug("Created ConnectionString {}", connectionString);
148154
this.connectionString = connectionString;
Lines changed: 50 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to you under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
117
package org.apache.logging.log4j.mongodb;
218

3-
import org.junit.jupiter.api.Test;
4-
519
import static org.junit.jupiter.api.Assertions.assertEquals;
620
import static org.junit.jupiter.api.Assertions.assertNotNull;
721
import static org.junit.jupiter.api.Assertions.assertNull;
822

23+
import org.junit.jupiter.api.Test;
924

1025
class MongoDbProviderTest {
1126

@@ -16,9 +31,6 @@ class MongoDbProviderTest {
1631
private String collectionName = "logsTest";
1732
private String databaseName = "loggingTest";
1833

19-
20-
21-
2234
@Test
2335
void createProviderWithDatabaseAndCollectionProvidedViaConfig() {
2436

@@ -29,9 +41,14 @@ void createProviderWithDatabaseAndCollectionProvidedViaConfig() {
2941
.build();
3042

3143
assertNotNull(provider, "Returned provider is null");
32-
assertEquals(this.collectionName, provider.getConnection().getCollection().getNamespace().getCollectionName(), "Collection names do not match");
33-
assertEquals( this.databaseName, provider.getConnection().getCollection().getNamespace().getDatabaseName(), "Database names do not match");
34-
44+
assertEquals(
45+
this.collectionName,
46+
provider.getConnection().getCollection().getNamespace().getCollectionName(),
47+
"Collection names do not match");
48+
assertEquals(
49+
this.databaseName,
50+
provider.getConnection().getCollection().getNamespace().getDatabaseName(),
51+
"Database names do not match");
3552
}
3653

3754
@Test
@@ -41,49 +58,47 @@ void createProviderWithoutDatabaseName() {
4158
.setConnectionStringSource(this.validConnectionStringWithoutDatabase)
4259
.build();
4360

44-
assertNull( provider, "Provider should be null but was not");
45-
46-
61+
assertNull(provider, "Provider should be null but was not");
4762
}
4863

4964
@Test
50-
void createProviderWithoutDatabaseNameWithCollectionName(){
65+
void createProviderWithoutDatabaseNameWithCollectionName() {
5166

5267
MongoDbProvider provider = MongoDbProvider.newBuilder()
5368
.setConnectionStringSource(this.validConnectionStringWithoutDatabase)
5469
.setCollectionName(this.collectionName)
5570
.build();
5671

57-
assertNull(provider,"Provider should be null but was not");
58-
59-
60-
72+
assertNull(provider, "Provider should be null but was not");
6173
}
6274

6375
@Test
64-
void createProviderWithoutCollectionName(){
76+
void createProviderWithoutCollectionName() {
6577

6678
MongoDbProvider provider = MongoDbProvider.newBuilder()
6779
.setConnectionStringSource(this.validConnectionStringWithoutDatabase)
6880
.setDatabaseName(this.databaseName)
6981
.build();
7082

71-
assertNull(provider,"Provider should be null but was not");
72-
73-
83+
assertNull(provider, "Provider should be null but was not");
7484
}
7585

7686
@Test
77-
void createProviderWithDatabaseOnConnectionString(){
87+
void createProviderWithDatabaseOnConnectionString() {
7888
MongoDbProvider provider = MongoDbProvider.newBuilder()
7989
.setConnectionStringSource(this.validConnectionStringWithDatabase)
8090
.setCollectionName(this.collectionName)
8191
.build();
8292

83-
assertNotNull(provider,"Provider should not be null");
84-
assertEquals(this.collectionName, provider.getConnection().getCollection().getNamespace().getCollectionName(), "Provider should be null but was not");
85-
assertEquals( "logging", provider.getConnection().getCollection().getNamespace().getDatabaseName(),"Database names do not match");
86-
93+
assertNotNull(provider, "Provider should not be null");
94+
assertEquals(
95+
this.collectionName,
96+
provider.getConnection().getCollection().getNamespace().getCollectionName(),
97+
"Provider should be null but was not");
98+
assertEquals(
99+
"logging",
100+
provider.getConnection().getCollection().getNamespace().getDatabaseName(),
101+
"Database names do not match");
87102
}
88103

89104
@Test
@@ -95,13 +110,14 @@ void createProviderConfigOverridesConnectionString() {
95110
.setDatabaseName(this.databaseName)
96111
.build();
97112

98-
assertNotNull(provider,"Provider should not be null");
99-
assertEquals(this.collectionName, provider.getConnection().getCollection().getNamespace().getCollectionName(), "Collection name does not match provided configuration");
100-
assertEquals(this.databaseName, provider.getConnection().getCollection().getNamespace().getDatabaseName(), "Database name does not match provided configuration");
101-
113+
assertNotNull(provider, "Provider should not be null");
114+
assertEquals(
115+
this.collectionName,
116+
provider.getConnection().getCollection().getNamespace().getCollectionName(),
117+
"Collection name does not match provided configuration");
118+
assertEquals(
119+
this.databaseName,
120+
provider.getConnection().getCollection().getNamespace().getDatabaseName(),
121+
"Database name does not match provided configuration");
102122
}
103-
104-
105-
106-
107-
}
123+
}

0 commit comments

Comments
 (0)