зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1270213 - Add UUIDUtil.isUUID. r=sebastian
MozReview-Commit-ID: S5BbzEVEka --HG-- extra : rebase_source : 6ae0a62d4747cb2fd9df23a0604918461c5359b1
This commit is contained in:
Родитель
ded6c511f3
Коммит
b712f57236
|
@ -0,0 +1,19 @@
|
||||||
|
/*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, you can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.mozilla.gecko.util;
|
||||||
|
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utilities for UUIDs.
|
||||||
|
*/
|
||||||
|
public class UUIDUtil {
|
||||||
|
private UUIDUtil() {}
|
||||||
|
|
||||||
|
public static final String UUID_REGEX = "[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}";
|
||||||
|
public static final Pattern UUID_PATTERN = Pattern.compile(UUID_REGEX);
|
||||||
|
}
|
|
@ -126,6 +126,7 @@ gujar.sources += ['java/org/mozilla/gecko/' + x for x in [
|
||||||
'util/StringUtils.java',
|
'util/StringUtils.java',
|
||||||
'util/ThreadUtils.java',
|
'util/ThreadUtils.java',
|
||||||
'util/UIAsyncTask.java',
|
'util/UIAsyncTask.java',
|
||||||
|
'util/UUIDUtil.java',
|
||||||
'util/WeakReferenceHandler.java',
|
'util/WeakReferenceHandler.java',
|
||||||
'util/WebActivityMapper.java',
|
'util/WebActivityMapper.java',
|
||||||
'util/WindowUtils.java',
|
'util/WindowUtils.java',
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
/*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, you can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.mozilla.gecko.util;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mozilla.gecko.background.testhelpers.TestRunner;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for uuid utils.
|
||||||
|
*/
|
||||||
|
@RunWith(TestRunner.class)
|
||||||
|
public class TestUUIDUtil {
|
||||||
|
private static final String[] validUUIDs = {
|
||||||
|
"904cd9f8-af63-4525-8ce0-b9127e5364fa",
|
||||||
|
"8d584bd2-00ea-4043-a617-ed4ce7018ed0",
|
||||||
|
"3abad327-2669-4f68-b9ef-7ace8c5314d6",
|
||||||
|
};
|
||||||
|
|
||||||
|
private static final String[] invalidUUIDs = {
|
||||||
|
"its-not-a-uuid-mate",
|
||||||
|
"904cd9f8-af63-4525-8ce0-b9127e5364falol",
|
||||||
|
"904cd9f8-af63-4525-8ce0-b9127e5364f",
|
||||||
|
};
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUUIDRegex() {
|
||||||
|
for (final String uuid : validUUIDs) {
|
||||||
|
assertTrue("Valid UUID matches UUID-regex", uuid.matches(UUIDUtil.UUID_REGEX));
|
||||||
|
}
|
||||||
|
for (final String uuid : invalidUUIDs) {
|
||||||
|
assertFalse("Invalid UUID does not match UUID-regex", uuid.matches(UUIDUtil.UUID_REGEX));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUUIDPattern() {
|
||||||
|
for (final String uuid : validUUIDs) {
|
||||||
|
assertTrue("Valid UUID matches UUID-regex", UUIDUtil.UUID_PATTERN.matcher(uuid).matches());
|
||||||
|
}
|
||||||
|
for (final String uuid : invalidUUIDs) {
|
||||||
|
assertFalse("Invalid UUID does not match UUID-regex", UUIDUtil.UUID_PATTERN.matcher(uuid).matches());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Загрузка…
Ссылка в новой задаче