Skip to content

Add validation to the usage service #54617

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 2, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,17 @@

public class UsageServiceTests extends ESTestCase {

public void testNullHandler() {
/**
* Test that we can not add a null reference to a {@link org.elasticsearch.rest.RestHandler} to the {@link UsageService}.
*/
public void testHandlerCanNotBeNull() {
final UsageService service = new UsageService();
expectThrows(NullPointerException.class, () -> service.addRestHandler(null));
}

/**
* Test that we can not add an instance of a {@link org.elasticsearch.rest.RestHandler} with no name to the {@link UsageService}.
*/
public void testAHandlerWithNoName() {
final UsageService service = new UsageService();
final BaseRestHandler horse = new MockRestHandler(null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quality variable name! 👍🐴

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Little slice of American pie right there. 😉

Expand All @@ -56,15 +62,22 @@ public void testAHandlerWithNoName() {
equalTo("handler of type [org.elasticsearch.usage.UsageServiceTests$MockRestHandler] does not have a name"));
}

/**
* Test that we can add the same instance of a {@link org.elasticsearch.rest.RestHandler} to the {@link UsageService} multiple times.
*/
public void testHandlerWithConflictingNamesButSameInstance() {
final UsageService service = new UsageService();
final String name = randomAlphaOfLength(8);
final BaseRestHandler first = new MockRestHandler(name);
service.addRestHandler(first);
// nothing bad should happen
// nothing bad ever happens to me
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤣

service.addRestHandler(first);
}

/**
* Test that we can not add different instances of {@link org.elasticsearch.rest.RestHandler} with the same name to the
* {@link UsageService}.
*/
public void testHandlersWithConflictingNamesButDifferentInstances() {
final UsageService service = new UsageService();
final String name = randomAlphaOfLength(8);
Expand Down