// 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/main/java/com/franmontiel/localechanger/matcher/MatchingLocales.java
// public final class MatchingLocales {
//     private Locale supportedLocale;
//     private Locale systemLocale;
// 
//     public MatchingLocales(Locale supportedLocale, Locale systemLocale) {
//         this.supportedLocale = supportedLocale;
//         this.systemLocale = systemLocale;
//     }
// 
//     public Locale getSupportedLocale() {
//         return supportedLocale;
//     }
// 
//     public Locale getSystemLocale() {
//         return systemLocale;
//     }
// 
//     public Locale getPreferredLocale(LocalePreference preference) {
//         return preference.equals(LocalePreference.PreferSupportedLocale) ?
//                 supportedLocale :
//                 systemLocale;
//     }
// 
//     @Override
//     public boolean equals(Object o) {
//         if (this == o) return true;
//         if (o == null || getClass() != o.getClass()) return false;
// 
//         MatchingLocales that = (MatchingLocales) o;
// 
//         return supportedLocale.equals(that.supportedLocale)
//                 && systemLocale.equals(that.systemLocale);
//     }
// 
//     @Override
//     public int hashCode() {
//         int result = supportedLocale.hashCode();
//         result = 31 * result + systemLocale.hashCode();
//         return result;
//     }
// 
//     @Override
//     public String toString() {
//         return supportedLocale.toString() + ", " + systemLocale.toString();
//     }
// }


import com.franmontiel.localechanger.matcher.LanguageMatchingAlgorithm;
import com.franmontiel.localechanger.matcher.MatchingAlgorithm;
import com.franmontiel.localechanger.matcher.MatchingLocales;
import junit.framework.Assert;
import org.junit.Before;
import org.junit.Test;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
/*
 * Copyright (c)  2017  Francisco José Montiel Navarro.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.franmontiel.localechanger;





public class LanguageMatchingAlgorithmTest {

    private static final Locale LOCALE_ES_ES = new Locale("es", "ES");
    private static final Locale LOCALE_IT_IT = new Locale("it", "IT");
    private static final Locale LOCALE_FR_CA = new Locale("fr", "CA");
    private static final Locale LOCALE_EN_GB = new Locale("en", "GB");

    private static final Locale LOCALE_EN_US = new Locale("en", "US");
    private static final Locale LOCALE_FR_FR = new Locale("fr", "FR");

    private static final List<Locale> SYSTEM_LOCALES = Arrays.asList(LOCALE_EN_US, LOCALE_FR_FR);

    private MatchingAlgorithm sut;

    @Before
    public void setUp() throws Exception {
        sut = new LanguageMatchingAlgorithm();
    }

    @Test
    public void ShouldNotFindMatchingLocales_WhenFindDefaultMatch_GivenNonMatchingLocales() {
        // Given
        List<Locale> supportedLocalesNotMatching = Arrays.asList(LOCALE_ES_ES, LOCALE_IT_IT);

        // When
// 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/main/java/com/franmontiel/localechanger/matcher/MatchingLocales.java
// public final class MatchingLocales {
//     private Locale supportedLocale;
//     private Locale systemLocale;
// 
//     public MatchingLocales(Locale supportedLocale, Locale systemLocale) {
//         this.supportedLocale = supportedLocale;
//         this.systemLocale = systemLocale;
//     }
// 
//     public Locale getSupportedLocale() {
//         return supportedLocale;
//     }
// 
//     public Locale getSystemLocale() {
//         return systemLocale;
//     }
// 
//     public Locale getPreferredLocale(LocalePreference preference) {
//         return preference.equals(LocalePreference.PreferSupportedLocale) ?
//                 supportedLocale :
//                 systemLocale;
//     }
// 
//     @Override
//     public boolean equals(Object o) {
//         if (this == o) return true;
//         if (o == null || getClass() != o.getClass()) return false;
// 
//         MatchingLocales that = (MatchingLocales) o;
// 
//         return supportedLocale.equals(that.supportedLocale)
//                 && systemLocale.equals(that.systemLocale);
//     }
// 
//     @Override
//     public int hashCode() {
//         int result = supportedLocale.hashCode();
//         result = 31 * result + systemLocale.hashCode();
//         return result;
//     }
// 
//     @Override
//     public String toString() {
//         return supportedLocale.toString() + ", " + systemLocale.toString();
//     }
// }


// Path: library/src/test/java/com/franmontiel/localechanger/LanguageMatchingAlgorithmTest.java
import com.franmontiel.localechanger.matcher.LanguageMatchingAlgorithm;
import com.franmontiel.localechanger.matcher.MatchingAlgorithm;
import com.franmontiel.localechanger.matcher.MatchingLocales;
import junit.framework.Assert;
import org.junit.Before;
import org.junit.Test;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;

/*
 * Copyright (c)  2017  Francisco José Montiel Navarro.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.franmontiel.localechanger;





public class LanguageMatchingAlgorithmTest {

    private static final Locale LOCALE_ES_ES = new Locale("es", "ES");
    private static final Locale LOCALE_IT_IT = new Locale("it", "IT");
    private static final Locale LOCALE_FR_CA = new Locale("fr", "CA");
    private static final Locale LOCALE_EN_GB = new Locale("en", "GB");

    private static final Locale LOCALE_EN_US = new Locale("en", "US");
    private static final Locale LOCALE_FR_FR = new Locale("fr", "FR");

    private static final List<Locale> SYSTEM_LOCALES = Arrays.asList(LOCALE_EN_US, LOCALE_FR_FR);

    private MatchingAlgorithm sut;

    @Before
    public void setUp() throws Exception {
        sut = new LanguageMatchingAlgorithm();
    }

    @Test
    public void ShouldNotFindMatchingLocales_WhenFindDefaultMatch_GivenNonMatchingLocales() {
        // Given
        List<Locale> supportedLocalesNotMatching = Arrays.asList(LOCALE_ES_ES, LOCALE_IT_IT);

        // When
        MatchingLocales matchingLocales = sut.findDefaultMatch(supportedLocalesNotMatching, SYSTEM_LOCALES);