You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
	
	
		
			62 lines
		
	
	
		
			2.7 KiB
		
	
	
	
		
			Java
		
	
		
		
			
		
	
	
			62 lines
		
	
	
		
			2.7 KiB
		
	
	
	
		
			Java
		
	
| 
											10 years ago
										 | package org.thoughtcrime.securesms.service; | ||
|  | 
 | ||
|  | import org.junit.Before; | ||
|  | import org.junit.Test; | ||
|  | import org.thoughtcrime.securesms.BaseUnitTest; | ||
| 
											7 years ago
										 | import org.whispersystems.libsignal.util.guava.Optional; | ||
| 
											10 years ago
										 | 
 | ||
|  | import java.util.HashMap; | ||
|  | import java.util.Map; | ||
|  | import java.util.Map.Entry; | ||
|  | 
 | ||
|  | import static org.junit.Assert.assertEquals; | ||
| 
											7 years ago
										 | import static org.junit.Assert.assertTrue; | ||
| 
											10 years ago
										 | import static org.mockito.Matchers.anyBoolean; | ||
|  | import static org.mockito.Matchers.contains; | ||
|  | import static org.mockito.Mockito.when; | ||
|  | 
 | ||
| 
											7 years ago
										 | public class VerificationCodeParserTest extends BaseUnitTest { | ||
| 
											10 years ago
										 |   private static Map<String, String> CHALLENGES = new HashMap<String,String>() {{ | ||
|  |       put("Your TextSecure verification code: 337-337",        "337337"); | ||
|  |       put("XXX\nYour TextSecure verification code: 1337-1337", "13371337"); | ||
|  |       put("Your TextSecure verification code: 337-1337",       "3371337"); | ||
|  |       put("Your TextSecure verification code: 1337-337",       "1337337"); | ||
|  |       put("Your TextSecure verification code: 1337-1337",      "13371337"); | ||
|  |       put("XXXYour TextSecure verification code: 1337-1337",   "13371337"); | ||
|  |       put("Your TextSecure verification code: 1337-1337XXX",   "13371337"); | ||
| 
											10 years ago
										 |       put("Your TextSecure verification code 1337-1337",       "13371337"); | ||
| 
											10 years ago
										 | 
 | ||
|  |       put("Your Signal verification code: 337-337",        "337337"); | ||
|  |       put("XXX\nYour Signal verification code: 1337-1337", "13371337"); | ||
|  |       put("Your Signal verification code: 337-1337",       "3371337"); | ||
|  |       put("Your Signal verification code: 1337-337",       "1337337"); | ||
|  |       put("Your Signal verification code: 1337-1337",      "13371337"); | ||
|  |       put("XXXYour Signal verification code: 1337-1337",   "13371337"); | ||
|  |       put("Your Signal verification code: 1337-1337XXX",   "13371337"); | ||
| 
											10 years ago
										 |       put("Your Signal verification code 1337-1337",       "13371337"); | ||
| 
											10 years ago
										 | 
 | ||
| 
											7 years ago
										 |       put("<#>Your Signal verification code: 1337-1337 aAbBcCdDeEf",     "13371337"); | ||
|  |       put("<#> Your Signal verification code: 1337-1337 aAbBcCdDeEf",    "13371337"); | ||
|  |       put("<#>Your Signal verification code: 1337-1337\naAbBcCdDeEf",    "13371337"); | ||
|  |       put("<#> Your Signal verification code: 1337-1337\naAbBcCdDeEf",   "13371337"); | ||
|  |       put("<#> Your Signal verification code: 1337-1337\n\naAbBcCdDeEf", "13371337"); | ||
|  |   }}; | ||
| 
											10 years ago
										 | 
 | ||
|  |   @Before | ||
|  |   @Override | ||
|  |   public void setUp() throws Exception { | ||
|  |     super.setUp(); | ||
|  |     when(sharedPreferences.getBoolean(contains("pref_verifying"), anyBoolean())).thenReturn(true); | ||
|  |   } | ||
|  | 
 | ||
|  |   @Test | ||
| 
											7 years ago
										 |   public void testChallenges() { | ||
| 
											10 years ago
										 |     for (Entry<String,String> challenge : CHALLENGES.entrySet()) { | ||
| 
											7 years ago
										 |       Optional<String> result = VerificationCodeParser.parse(context, challenge.getKey()); | ||
|  | 
 | ||
|  |       assertTrue(result.isPresent()); | ||
|  |       assertEquals(result.get(), challenge.getValue()); | ||
| 
											10 years ago
										 |     } | ||
|  |   } | ||
|  | } |