/* * Kontalk Android client * Copyright (C) 2017 Kontalk Devteam <devteam@kontalk.org> * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package org.kontalk.client; import org.junit.Test; import static org.junit.Assert.assertEquals; public class NumberValidatorTest { @Test public void testFixNumber() throws Exception { // see https://github.com/kontalk/androidclient/issues/917 assertEquals("+5491112345678", NumberValidator.fixNumber("+54 9 11 1234 5678", "+5491112345678", "AR", 0)); assertEquals("+5491112345678", NumberValidator.fixNumber("+54 11 1234 5678", "+5491112345678", "AR", 0)); // invalid case: NumberValidator.fixNumber("15 1234 5678", "+5491112345678", "AR", 0); assertEquals("+5491112345678", NumberValidator.fixNumber("0 11 15 1234 5678", "+5491112345678", "AR", 0)); assertEquals("+393351234567", NumberValidator.fixNumber("+39 335 123 4567", "+393321213456", "IT", 0)); assertEquals("+393351234567", NumberValidator.fixNumber("335 123 4567", "+393321213456", "IT", 0)); } @Test public void testAddSignificantDigits() { assertEquals(91112345678L, NumberValidator.addSignificantDigits(1112345678L, 9)); assertEquals(341112345678L, NumberValidator.addSignificantDigits(1112345678L, 34)); } }