Skip to content

Commit

Permalink
LPD-47489 Simplify test and check if the default implementations are …
Browse files Browse the repository at this point in the history
…present also
  • Loading branch information
rafaprax authored and brianchandotcom committed Feb 9, 2025
1 parent a796db0 commit 83ef8bb
Showing 1 changed file with 29 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package com.liferay.captcha.configuration.admin.definition.test;

import com.liferay.arquillian.extension.junit.bridge.junit.Arquillian;
import com.liferay.captcha.recaptcha.ReCaptchaImpl;
import com.liferay.captcha.simplecaptcha.SimpleCaptchaImpl;
import com.liferay.configuration.admin.definition.ConfigurationFieldOptionsProvider;
import com.liferay.portal.kernel.captcha.Captcha;
Expand All @@ -16,6 +17,7 @@
import com.liferay.portal.test.rule.Inject;
import com.liferay.portal.test.rule.LiferayIntegrationTestRule;

import java.util.List;
import java.util.Objects;

import org.junit.AfterClass;
Expand Down Expand Up @@ -60,20 +62,12 @@ public static void tearDownClass() {

@Test
public void testGetOptions() {
Assert.assertTrue(
ListUtil.exists(
_configurationFieldOptionsProvider.getOptions(),
option -> Objects.equals(
TestCaptcha.class.getName(), option.getValue())));
List<ConfigurationFieldOptionsProvider.Option> options =
_configurationFieldOptionsProvider.getOptions();

Captcha testCaptcha = new TestCaptcha();

Assert.assertTrue(
ListUtil.exists(
_configurationFieldOptionsProvider.getOptions(),
option -> Objects.equals(
testCaptcha.getName(),
option.getLabel(LocaleUtil.getDefault()))));
_assertContainsOption(new ReCaptchaImpl(), options);
_assertContainsOption(new SimpleCaptchaImpl(), options);
_assertContainsOption(new TestCaptcha(), options);
}

public static class TestCaptcha extends SimpleCaptchaImpl {
Expand All @@ -85,6 +79,28 @@ public String getName() {

}

private void _assertContainsOption(
Captcha captcha,
List<ConfigurationFieldOptionsProvider.Option> options) {

Assert.assertTrue(
ListUtil.exists(
options,
option -> {
Class<? extends Captcha> clazz = captcha.getClass();

if (Objects.equals(
captcha.getName(),
option.getLabel(LocaleUtil.getDefault())) &&
Objects.equals(clazz.getName(), option.getValue())) {

return true;
}

return false;
}));
}

private static ServiceRegistration<Captcha> _serviceRegistration;

@Inject(
Expand Down

0 comments on commit 83ef8bb

Please sign in to comment.