JoH { public static boolean validateMacAddress(final String mac) { return mac != null && mac.length() == 17 && mac.matches("([\\da-fA-F]{1,2}(?:\\:|$)){6}"); }  static String qs0(double x, int digits); static String qs(double x); static String qs(double x, int digits); static double ts(); static long tsl(); static long uptime(); static boolean upForAtLeastMins(int mins); static long msSince(long when); static long msTill(long when); static long absMsSince(long when); static String bytesToHex(byte[] bytes); static byte[] tolerantHexStringToByteArray(String str); static byte[] hexStringToByteArray(String str); static String macFormat(final String unformatted); static SortedSet<Map.Entry<K, V>> mapSortedByValue(Map<K, V> map, boolean descending); static String compressString(String source); static byte[] compressStringToBytes(String string); static byte[] compressBytesforPayload(byte[] bytes); static byte[] compressBytesToBytes(byte[] bytes); static byte[] decompressBytesToBytes(byte[] bytes); static String uncompressString(String input); static String base64encode(String input); static String base64decode(String input); static String base64encodeBytes(byte[] input); static byte[] base64decodeBytes(String input); static String ucFirst(String input); static boolean isSamsung(); static void persistentBuggySamsungCheck(); static void setBuggySamsungEnabled(); static String backTrace(); static String backTrace(int depth); static String backTraceShort(int depth); static void benchmark(String name); static void dumpBundle(Bundle bundle, String tag); static synchronized boolean differentBytes(String name, byte[] bytes); static synchronized void clearRatelimit(final String name); static synchronized boolean pratelimit(String name, int seconds); static synchronized boolean ratelimit(String name, int seconds); static synchronized boolean quietratelimit(String name, int seconds); static synchronized boolean ratelimitmilli(String name, int milliseconds); static String getDeviceDetails(); static String getVersionDetails(); static boolean isOldVersion(Context context); static boolean getWifiSleepPolicyNever(); static void benchmark_method_start(); static void benchmark_method_end(); static void fixActionBar(AppCompatActivity context); static HashMap<String, Object> JsonStringtoMap(String json); static Gson defaultGsonInstance(); static String hourMinuteString(); static String hourMinuteString(long timestamp); static String dateTimeText(long timestamp); static String dateText(long timestamp); static long getTimeZoneOffsetMs(); static String niceTimeSince(long t); static String niceTimeTill(long t); static String niceTimeScalar(long t); static String niceTimeScalar(double t, int digits); static String niceTimeScalarNatural(long t); static String niceTimeScalarRedux(long t); static String niceTimeScalarShort(long t); static String niceTimeScalarShortWithDecimalHours(long t); static double tolerantParseDouble(String str); static double tolerantParseDouble(final String str, final double def); static int tolerantParseInt(final String str, final int def); static long tolerantParseLong(final String str, final long def); static String getRFC822String(long timestamp); static PowerManager.WakeLock getWakeLock(final String name, int millis); static void releaseWakeLock(PowerManager.WakeLock wl); static PowerManager.WakeLock fullWakeLock(final String name, long millis); static void fullDatabaseReset(); static void clearCache(); static boolean isLANConnected(); static boolean isMobileDataOrEthernetConnected(); static boolean isAnyNetworkConnected(); static boolean isScreenOn(); static boolean isOngoingCall(); static String getWifiSSID(); static boolean getWifiFuzzyMatch(String local, String remote); static boolean runOnUiThread(Runnable theRunnable); static boolean runOnUiThreadDelayed(Runnable theRunnable, long delay); static void removeUiThreadRunnable(Runnable theRunnable); static void hardReset(); static void static_toast(final Context context, final String msg, final int length); static void static_toast_long(final String msg); static void static_toast_short(final String msg); static void static_toast_long(Context context, final String msg); static void show_ok_dialog(final Activity activity, final String title, final String message, final Runnable runnable); static synchronized void playResourceAudio(int id); static String getResourceURI(int id); static synchronized MediaPlayer playSoundUri(String soundUri); static boolean validateMacAddress(final String mac); static String urlEncode(String source); static Object cloneObject(Object obj); static void stopService(Class c); static void startService(Class c); static void startService(final Class c, final String... args); static void startService(final Class c, final byte[] bytes, final String... args); static void startActivity(Class c); static Intent getStartActivityIntent(Class c); static void goFullScreen(boolean fullScreen, View decorView); static Bitmap screenShot(View view, String annotation); static Bitmap screenShot2(View view); static void bitmapToFile(Bitmap bitmap, String path, String fileName); static void shareImage(Context context, File file); static void cancelAlarm(Context context, PendingIntent serviceIntent); static long wakeUpIntent(Context context, long delayMs, PendingIntent pendingIntent); static void scheduleNotification(Context context, String title, String body, int delaySeconds, int notification_id); static void cancelNotification(int notificationId); static void showNotification(String title, String content, PendingIntent intent, int notificationId, boolean sound, boolean vibrate, boolean onetime); static void showNotification(String title, String content, PendingIntent intent, int notificationId, boolean sound, boolean vibrate, PendingIntent deleteIntent, Uri sound_uri); static void showNotification(String title, String content, PendingIntent intent, int notificationId, boolean sound, boolean vibrate, PendingIntent deleteIntent, Uri sound_uri, String bigmsg); static void showNotification(String title, String content, PendingIntent intent, int notificationId, String channelId, boolean sound, boolean vibrate, PendingIntent deleteIntent, Uri sound_uri, String bigmsg); static void releaseOrientation(Activity activity); @SuppressWarnings("deprecation") @SuppressLint("NewApi") static void lockOrientation(Activity activity); static boolean areWeRunningOnAndroidWear(); static boolean isAirplaneModeEnabled(Context context); static byte[] convertPinToBytes(String pin); static boolean doPairingRequest(Context context, BroadcastReceiver broadcastReceiver, Intent intent, String mBluetoothDeviceAddress); @TargetApi(19) static boolean doPairingRequest(Context context, BroadcastReceiver broadcastReceiver, Intent intent, final String mBluetoothDeviceAddress, final String pinHint); static String getLocalBluetoothName(); static boolean refreshDeviceCache(String thisTAG, BluetoothGatt gatt); static boolean createSpecialBond(final String thisTAG, final BluetoothDevice device); synchronized static void setBluetoothEnabled(Context context, boolean state); static void niceRestartBluetooth(Context context); synchronized static void restartBluetooth(final Context context); synchronized static void restartBluetooth(final Context context, final int startInMs); static synchronized void unBond(String transmitterMAC); static Map<String, String> bundleToMap(Bundle bundle); static void threadSleep(long millis); static ByteBuffer bArrayAsBuffer(byte[] bytes); static long checksum(byte[] bytes); static byte[] bchecksum(byte[] bytes); static boolean checkChecksum(byte[] bytes); static int parseIntWithDefault(String number, int radix, int defaultVal); static double roundDouble(final double value, int places); static float roundFloat(final float value, int places); static boolean isServiceRunningInForeground(Class<?> serviceClass); static boolean emptyString(final String str); static boolean buggy_samsung; }
@Test public void validateMacAddressTest() { assertWithMessage("pass 1").that(validateMacAddress("00:11:22:33:44:55")).isTrue(); assertWithMessage("pass 2").that(validateMacAddress("06:18:A2:33:3F:91")).isTrue(); assertWithMessage("pass 3").that(validateMacAddress("AB:CD:EF:12:34:CC")).isTrue(); assertWithMessage("pass 4").that(validateMacAddress("ab:cd:ef:12:34:cc")).isTrue(); assertWithMessage("pass 5").that(validateMacAddress("ab:AA:Ef:12:54:cD")).isTrue(); assertWithMessage("fail 1").that(validateMacAddress("00:11:22:33:44:55:66")).isFalse(); assertWithMessage("fail 2").that(validateMacAddress("00:11:22:33:44")).isFalse(); assertWithMessage("fail 3").that(validateMacAddress("00:11:22:33:44:55:")).isFalse(); assertWithMessage("fail 4").that(validateMacAddress("00:11:22:33:44:")).isFalse(); assertWithMessage("fail 5").that(validateMacAddress("00:11:22:33:44")).isFalse(); assertWithMessage("fail 6").that(validateMacAddress("Hello World")).isFalse(); assertWithMessage("fail 7").that(validateMacAddress("")).isFalse(); assertWithMessage("fail 8").that(validateMacAddress(null)).isFalse(); assertWithMessage("fail 9").that(validateMacAddress("ab:AA:Ef:12:54:cG")).isFalse(); }