// Path: library/src/main/java/com/franmontiel/localechanger/matcher/LanguageMatchingAlgorithm.java
// public final class LanguageMatchingAlgorithm implements MatchingAlgorithm {
// 
//     @Override
//     public MatchingLocales findDefaultMatch(List<Locale> supportedLocales, List<Locale> systemLocales) {
//         MatchingLocales matchingPair = null;
//         for (Locale systemLocale : systemLocales) {
//             Locale matchingSupportedLocale = findMatchingLocale(systemLocale, supportedLocales);
//             if (matchingSupportedLocale != null) {
//                 matchingPair = new MatchingLocales(matchingSupportedLocale, systemLocale);
//                 break;
//             }
//         }
//         return matchingPair;
//     }
// 
//     @Override
//     public MatchingLocales findMatch(Locale supportedLocale, List<Locale> systemLocales) {
//         Locale matchingSystemLocale = findMatchingLocale(supportedLocale, systemLocales);
//         return matchingSystemLocale != null ?
//                 new MatchingLocales(supportedLocale, matchingSystemLocale) :
//                 null;
//     }
// 
//     private static Locale findMatchingLocale(Locale localeToMatch, List<Locale> candidates) {
//         Locale matchingLocale = null;
//         for (Locale candidate : candidates) {
//             LocaleMatcher.MatchLevel matchLevel = LocaleMatcher.match(localeToMatch, candidate);
// 
//             if (matchLevel != LocaleMatcher.MatchLevel.NoMatch) {
//                 matchingLocale = candidate;
//                 break;
//             }
//         }
//         return matchingLocale;
//     }
// }
// 
// Path: library/src/main/java/com/franmontiel/localechanger/matcher/MatchingAlgorithm.java
// public interface MatchingAlgorithm {
// 
//     /**
//      * Method that implements the algorithm to find two matching Locales between a list of supported and system Locales.
//      *
//      * @param supportedLocales a list of your app supported locales
//      * @param systemLocales    a list of the configured  locales in system preferences
//      * @return a {@link MatchingLocales} containing the pair of matching locales. If no match is found null is returned
//      */
//     MatchingLocales findDefaultMatch(List<Locale> supportedLocales, List<Locale> systemLocales);
// 
//     /**
//      * Method that implements the algorithm to find a matching Locale between the supported Locale and system Locales.
//      *
//      * @param supportedLocale one of your app supported locales
//      * @param systemLocales   a list of the configured  locales in system preferences
//      * @return a {@link MatchingLocales} containing the pair of matching locales. If no match is found null is returned
//      */
//     MatchingLocales findMatch(Locale supportedLocale, List<Locale> systemLocales);
// }


import com.franmontiel.localechanger.matcher.LanguageMatchingAlgorithm;
import com.franmontiel.localechanger.matcher.MatchingAlgorithm;
import junit.framework.Assert;
import org.junit.Test;
import java.util.Arrays;
import java.util.Locale;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
                ANY_PREFERENCE
        );

        // When
        DefaultResolvedLocalePair defaultResolvedLocalePair = sut.resolveDefault();

        // Then
        Assert.assertEquals(LOCALE_ES_ES, defaultResolvedLocalePair.getResolvedLocale());
    }

    @Test
    public void ShouldResolveGivenSupportedLocaleAsDefault_WhenResolveLocale_GivenNonMatchingLocales() throws UnsupportedLocaleException {
        // Given
        LocaleResolver sut = new LocaleResolver(
                Arrays.asList(LOCALE_ES_ES, LOCALE_IT_IT),
                Arrays.asList(LOCALE_EN_US, LOCALE_FR_FR),
                new LanguageMatchingAlgorithm(),
                ANY_PREFERENCE
        );

        // When
        Locale resolvedLocale = sut.resolve(LOCALE_IT_IT);

        // Then
        Assert.assertEquals(LOCALE_IT_IT, resolvedLocale);
    }

    @Test
    public void ShouldResolveGivenSupportedLocaleDirectly_WhenResolveLocale_PreferringSupportedLocale() throws UnsupportedLocaleException {
        // Given
// Path: library/src/main/java/com/franmontiel/localechanger/matcher/LanguageMatchingAlgorithm.java
// public final class LanguageMatchingAlgorithm implements MatchingAlgorithm {
// 
//     @Override
//     public MatchingLocales findDefaultMatch(List<Locale> supportedLocales, List<Locale> systemLocales) {
//         MatchingLocales matchingPair = null;
//         for (Locale systemLocale : systemLocales) {
//             Locale matchingSupportedLocale = findMatchingLocale(systemLocale, supportedLocales);
//             if (matchingSupportedLocale != null) {
//                 matchingPair = new MatchingLocales(matchingSupportedLocale, systemLocale);
//                 break;
//             }
//         }
//         return matchingPair;
//     }
// 
//     @Override
//     public MatchingLocales findMatch(Locale supportedLocale, List<Locale> systemLocales) {
//         Locale matchingSystemLocale = findMatchingLocale(supportedLocale, systemLocales);
//         return matchingSystemLocale != null ?
//                 new MatchingLocales(supportedLocale, matchingSystemLocale) :
//                 null;
//     }
// 
//     private static Locale findMatchingLocale(Locale localeToMatch, List<Locale> candidates) {
//         Locale matchingLocale = null;
//         for (Locale candidate : candidates) {
//             LocaleMatcher.MatchLevel matchLevel = LocaleMatcher.match(localeToMatch, candidate);
// 
//             if (matchLevel != LocaleMatcher.MatchLevel.NoMatch) {
//                 matchingLocale = candidate;
//                 break;
//             }
//         }
//         return matchingLocale;
//     }
// }
// 
// Path: library/src/main/java/com/franmontiel/localechanger/matcher/MatchingAlgorithm.java
// public interface MatchingAlgorithm {
// 
//     /**
//      * Method that implements the algorithm to find two matching Locales between a list of supported and system Locales.
//      *
//      * @param supportedLocales a list of your app supported locales
//      * @param systemLocales    a list of the configured  locales in system preferences
//      * @return a {@link MatchingLocales} containing the pair of matching locales. If no match is found null is returned
//      */
//     MatchingLocales findDefaultMatch(List<Locale> supportedLocales, List<Locale> systemLocales);
// 
//     /**
//      * Method that implements the algorithm to find a matching Locale between the supported Locale and system Locales.
//      *
//      * @param supportedLocale one of your app supported locales
//      * @param systemLocales   a list of the configured  locales in system preferences
//      * @return a {@link MatchingLocales} containing the pair of matching locales. If no match is found null is returned
//      */
//     MatchingLocales findMatch(Locale supportedLocale, List<Locale> systemLocales);
// }


// Path: library/src/test/java/com/franmontiel/localechanger/LocaleResolverTest.java
import com.franmontiel.localechanger.matcher.LanguageMatchingAlgorithm;
import com.franmontiel.localechanger.matcher.MatchingAlgorithm;
import junit.framework.Assert;
import org.junit.Test;
import java.util.Arrays;
import java.util.Locale;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;

                ANY_PREFERENCE
        );

        // When
        DefaultResolvedLocalePair defaultResolvedLocalePair = sut.resolveDefault();

        // Then
        Assert.assertEquals(LOCALE_ES_ES, defaultResolvedLocalePair.getResolvedLocale());
    }

    @Test
    public void ShouldResolveGivenSupportedLocaleAsDefault_WhenResolveLocale_GivenNonMatchingLocales() throws UnsupportedLocaleException {
        // Given
        LocaleResolver sut = new LocaleResolver(
                Arrays.asList(LOCALE_ES_ES, LOCALE_IT_IT),
                Arrays.asList(LOCALE_EN_US, LOCALE_FR_FR),
                new LanguageMatchingAlgorithm(),
                ANY_PREFERENCE
        );

        // When
        Locale resolvedLocale = sut.resolve(LOCALE_IT_IT);

        // Then
        Assert.assertEquals(LOCALE_IT_IT, resolvedLocale);
    }

    @Test
    public void ShouldResolveGivenSupportedLocaleDirectly_WhenResolveLocale_PreferringSupportedLocale() throws UnsupportedLocaleException {
        // Given
        MatchingAlgorithm matchingAlgorithm = mock(MatchingAlgorithm.class);