Skip to content

Commit

Permalink
Move assertions to test class and minor changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
jzuriaga committed Sep 30, 2020
1 parent b33b286 commit 7715e92
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
package io.quarkus.mongodb;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.notNullValue;
import java.util.ArrayList;
import java.util.List;

import com.mongodb.event.CommandListener;
import com.mongodb.event.CommandStartedEvent;

public class MockCommandListener implements CommandListener {

private CommandStartedEvent commandStartedEvent;
public static final List<String> events = new ArrayList<>();

@Override
public void commandStarted(CommandStartedEvent startedEvent) {
this.commandStartedEvent = startedEvent;
assertThat(startedEvent, notNullValue());
assertThat(startedEvent.getCommandName(), anyOf(equalTo("listDatabases"), equalTo("endSessions")));
}

public CommandStartedEvent getCommandStartedEvent() {
return commandStartedEvent;
events.add(startedEvent.getCommandName());
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package io.quarkus.mongodb;

import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.Matchers.hasSize;

import javax.inject.Inject;

Expand Down Expand Up @@ -35,6 +39,8 @@ void cleanup() {
@Test
void testClientInitialization() {
assertThat(client.listDatabaseNames().first()).isNotEmpty();
assertThat(MockCommandListener.events, hasSize(1));
assertThat(MockCommandListener.events, hasItems(equalTo("listDatabases")));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,7 @@ private MongoClientSettings createMongoConfiguration(MongoClientConfig config) {
CodecRegistries.fromProviders(providers));
settings.codecRegistry(registry);

List<CommandListener> listeners = new ArrayList<>();
if (!mongoClientSupport.getCommandListeners().isEmpty()) {
listeners.addAll(getCommandListeners(mongoClientSupport.getCommandListeners()));
}
settings.commandListenerList(listeners);
settings.commandListenerList(getCommandListeners(mongoClientSupport.getCommandListeners()));

config.applicationName.ifPresent(settings::applicationName);

Expand Down

0 comments on commit 7715e92

Please sign in to comment.