Skip to content

Commit

Permalink
see 09/07 log
Browse files Browse the repository at this point in the history
  • Loading branch information
Blankj committed Sep 7, 2017
1 parent aeae30a commit 9c98177
Show file tree
Hide file tree
Showing 10 changed files with 175 additions and 139 deletions.
6 changes: 4 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ android {

buildTypes {
debug {
minifyEnabled false
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
release {
Expand Down Expand Up @@ -77,7 +77,9 @@ dependencies {
releaseCompile leakCanary
testCompile leakCanary

// compile 'com.blankj:utilcode:1.8.4'
compile 'com.tencent.mars:mars-core:1.2.0'

// compile 'com.blankj:utilcode:1.9.0'
}


1 change: 0 additions & 1 deletion app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

4 changes: 3 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.blankj.androidutilcode">

<!--bar-->
Expand Down Expand Up @@ -50,6 +51,8 @@
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<uses-sdk tools:overrideLibrary="com.tencent.mars"/>

<application
android:name=".UtilsApp"
android:allowBackup="false"
Expand All @@ -63,7 +66,6 @@
</intent-filter>
</activity>


<!--core-->
<activity
android:name=".core.main.CoreUtilActivity" />
Expand Down
2 changes: 1 addition & 1 deletion utilcode/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
release {
minifyEnabled false
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
Expand Down
6 changes: 1 addition & 5 deletions utilcode/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,4 @@
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

-keep class com.blankj.utilcode.** { *; }
-keepclassmembers class com.blankj.utilcode.** { *; }
-dontwarn com.blankj.utilcode.**
#}
Original file line number Diff line number Diff line change
Expand Up @@ -145,23 +145,25 @@ public void getJSONArray() throws Exception {

@Test
public void getBitmap() throws Exception {
Assert.assertTrue(mCacheUtils1.getString("bitmap1").equals("Bitmap (100 x 100) compressed as PNG with quality 100"));
Assert.assertTrue(mCacheUtils1.getString("bitmap1", null).equals("Bitmap (100 x 100) compressed as PNG with quality 100"));
String bitmapString = "Bitmap (100 x 100) compressed as PNG with quality 100";
Assert.assertTrue(mCacheUtils1.getString("bitmap1").equals(bitmapString));
Assert.assertTrue(mCacheUtils1.getString("bitmap1", null).equals(bitmapString));
Assert.assertNull(mCacheUtils1.getString("bitmap2", null));

Assert.assertTrue(mCacheUtils2.getString("bitmap2").equals("Bitmap (100 x 100) compressed as PNG with quality 100"));
Assert.assertTrue(mCacheUtils2.getString("bitmap2", null).equals("Bitmap (100 x 100) compressed as PNG with quality 100"));
Assert.assertTrue(mCacheUtils2.getString("bitmap2").equals(bitmapString));
Assert.assertTrue(mCacheUtils2.getString("bitmap2", null).equals(bitmapString));
Assert.assertNull(mCacheUtils2.getString("bitmap1", null));
}

@Test
public void getDrawable() throws Exception {
Assert.assertTrue(mCacheUtils1.getString("drawable1").equals("Bitmap (100 x 100) compressed as PNG with quality 100"));
Assert.assertTrue(mCacheUtils1.getString("drawable1", null).equals("Bitmap (100 x 100) compressed as PNG with quality 100"));
String bitmapString = "Bitmap (100 x 100) compressed as PNG with quality 100";
Assert.assertTrue(mCacheUtils1.getString("drawable1").equals(bitmapString));
Assert.assertTrue(mCacheUtils1.getString("drawable1", null).equals(bitmapString));
Assert.assertNull(mCacheUtils1.getString("drawable2", null));

Assert.assertTrue(mCacheUtils2.getString("drawable2").equals("Bitmap (100 x 100) compressed as PNG with quality 100"));
Assert.assertTrue(mCacheUtils2.getString("drawable2", null).equals("Bitmap (100 x 100) compressed as PNG with quality 100"));
Assert.assertTrue(mCacheUtils2.getString("drawable2").equals(bitmapString));
Assert.assertTrue(mCacheUtils2.getString("drawable2", null).equals(bitmapString));
Assert.assertNull(mCacheUtils2.getString("drawable1", null));
}

Expand Down Expand Up @@ -348,7 +350,9 @@ public void setClassName(String className) {

@Override
public boolean equals(Object obj) {
return obj instanceof SerializableTest && ((SerializableTest) obj).author.equals(author) && ((SerializableTest) obj).className.equals(className);
return obj instanceof SerializableTest
&& ((SerializableTest) obj).author.equals(author)
&& ((SerializableTest) obj).className.equals(className);
}
}
}
Expand Down
124 changes: 84 additions & 40 deletions utilcode/src/test/java/com/blankj/utilcode/util/ConvertUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import com.blankj.utilcode.constant.MemoryConstants;
import com.blankj.utilcode.constant.TimeConstants;

import org.junit.Assert;
import org.junit.Test;

import static com.blankj.utilcode.util.ConvertUtils.*;
import static com.google.common.truth.Truth.assertThat;
import java.util.Arrays;


/**
Expand All @@ -20,75 +20,119 @@
*/
public class ConvertUtilsTest {

byte[] mBytes = new byte[]{0x00, 0x08, (byte) 0xdb, 0x33, 0x45, (byte) 0xab, 0x02, 0x23};
String hexString = "0008DB3345AB0223";
private byte[] mBytes = new byte[]{0x00, 0x08, (byte) 0xdb, 0x33, 0x45, (byte) 0xab, 0x02, 0x23};
private String hexString = "0008DB3345AB0223";

@Test
public void testBytes2HexString() throws Exception {
assertThat(bytes2HexString(mBytes)).isEqualTo(hexString);
}
private char[] mChars1 = new char[]{'0', '1', '2'};
private byte[] mBytes1 = new byte[]{48, 49, 50};

@Test
public void testHexString2Bytes() throws Exception {
assertThat(hexString2Bytes(hexString)).isEqualTo(mBytes);
public void bytes2HexString() throws Exception {
Assert.assertEquals(
hexString,
ConvertUtils.bytes2HexString(mBytes)
);
}

char[] mChars1 = new char[]{'0', '1', '2'};
byte[] mBytes1 = new byte[]{48, 49, 50};

@Test
public void testChars2Bytes() throws Exception {
assertThat(chars2Bytes(mChars1)).isEqualTo(mBytes1);
public void hexString2Bytes() throws Exception {
Assert.assertTrue(
Arrays.equals(
mBytes,
ConvertUtils.hexString2Bytes(hexString)
)
);
}

@Test
public void testBytes2Chars() throws Exception {
assertThat(bytes2Chars(mBytes1)).isEqualTo(mChars1);
public void chars2Bytes() throws Exception {
Assert.assertTrue(
Arrays.equals(
mBytes1,
ConvertUtils.chars2Bytes(mChars1)
)
);
}

@Test
public void testByte2Unit() throws Exception {
assertThat(byte2MemorySize(MemoryConstants.GB, MemoryConstants.MB) - 1024).isWithin(0.001);
public void bytes2Chars() throws Exception {
Assert.assertTrue(
Arrays.equals(
mChars1,
ConvertUtils.bytes2Chars(mBytes1)
)
);
}

@Test
public void testByte2FitSize() throws Exception {
assertThat(byte2FitMemorySize(1024 * 1024 * 3 + 1024 * 100)).isEqualTo("3.098MB");
public void byte2MemorySize() throws Exception {
Assert.assertEquals(
1024,
ConvertUtils.byte2MemorySize(MemoryConstants.GB, MemoryConstants.MB),
0.001
);
}

@Test
public void testMillis2FitTimeSpan() throws Exception {
long millis = TimeConstants.DAY * 6 + TimeConstants.HOUR * 6
+ TimeConstants.MIN * 6 + TimeConstants.SEC * 6 + 6;
System.out.println(millis2FitTimeSpan(millis, 7));
System.out.println(millis2FitTimeSpan(millis, 4));
System.out.println(millis2FitTimeSpan(millis, 3));
System.out.println(millis2FitTimeSpan(millis * 4, 5));
public void byte2FitMemorySize() throws Exception {
Assert.assertEquals(
"3.098MB",
ConvertUtils.byte2FitMemorySize(1024 * 1024 * 3 + 1024 * 100)
);
}

@Test
public void testBytes2Bits() throws Exception {
System.out.println(bytes2Bits(new byte[]{0x7F, (byte) 0xFA}));
public void millis2FitTimeSpan() throws Exception {
long millis = 6 * TimeConstants.DAY
+ 6 * TimeConstants.HOUR
+ 6 * TimeConstants.MIN
+ 6 * TimeConstants.SEC
+ 6;
Assert.assertEquals(
"6天6小时6分钟6秒6毫秒",
ConvertUtils.millis2FitTimeSpan(millis, 7)
);
Assert.assertEquals(
"6天6小时6分钟6秒",
ConvertUtils.millis2FitTimeSpan(millis, 4)
);
Assert.assertEquals(
"6天6小时6分钟",
ConvertUtils.millis2FitTimeSpan(millis, 3)
);
Assert.assertEquals(
"25天24分钟24秒24毫秒",
ConvertUtils.millis2FitTimeSpan(millis * 4, 5)
);
}

@Test
public void testBits2Bytes() throws Exception {
System.out.println(bytes2HexString(bits2Bytes("111111111111010")));
public void bytes2Bits_bits2Bytes() throws Exception {
Assert.assertEquals(
"0111111111111010",
ConvertUtils.bytes2Bits(new byte[]{0x7F, (byte) 0xFA})
);
Assert.assertEquals(
"0111111111111010",
ConvertUtils.bytes2Bits(ConvertUtils.bits2Bytes("111111111111010"))
);
}

@Test
public void testInputStream2BytesAndBytes2InputStream() throws Exception {
public void inputStream2Bytes_bytes2InputStream() throws Exception {
String string = "this is test string";
assertThat(new String(inputStream2Bytes(
bytes2InputStream(string.getBytes("UTF-8")))))
.isEqualTo(string);
Assert.assertEquals(
string.getBytes("UTF-8"),
ConvertUtils.inputStream2Bytes(ConvertUtils.bytes2InputStream(string.getBytes("UTF-8")))
);
}

@Test
public void testInputStream2StringAndString2InputStream() throws Exception {
public void inputStream2String_string2InputStream() throws Exception {
String string = "this is test string";
assertThat(inputStream2String(
string2InputStream(string, "UTF-8")
, "UTF-8")).isEqualTo(string);
Assert.assertEquals(
string,
ConvertUtils.inputStream2String(ConvertUtils.string2InputStream(string, "UTF-8"), "UTF-8")
);
}
}
58 changes: 34 additions & 24 deletions utilcode/src/test/java/com/blankj/utilcode/util/EmptyUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import android.annotation.TargetApi;
import android.os.Build;
import android.support.v4.util.LongSparseArray;
import android.support.v4.util.SimpleArrayMap;
import android.util.SparseArray;
import android.util.SparseBooleanArray;
import android.util.SparseIntArray;
import android.util.SparseLongArray;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
Expand All @@ -15,8 +18,6 @@
import java.util.HashMap;
import java.util.LinkedList;

import static com.google.common.truth.Truth.assertThat;

/**
* <pre>
* author: Blankj
Expand All @@ -26,7 +27,7 @@
* </pre>
*/
@RunWith(RobolectricTestRunner.class)
@Config(manifest = Config.NONE , sdk = 23)
@Config(manifest = Config.NONE, sdk = 23)
public class EmptyUtilsTest {

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
Expand All @@ -37,32 +38,41 @@ public void isEmpty() throws Exception {
int[][] arr = new int[][]{};
int[] arr1 = null;
LinkedList<Integer> list = new LinkedList<>();
HashMap<String,Integer> map = new HashMap<>();
HashMap<String, Integer> map = new HashMap<>();
SimpleArrayMap<String, Integer> sam = new SimpleArrayMap<>();
SparseArray<String> sa = new SparseArray<>();
SparseBooleanArray sba = new SparseBooleanArray();
SparseIntArray sia = new SparseIntArray();
SparseLongArray sla = new SparseLongArray();
LongSparseArray<String> lsa = new LongSparseArray<>();
android.util.LongSparseArray<String> lsa4 = new android.util.LongSparseArray<>();

assertThat(EmptyUtils.isEmpty(string)).isTrue();
assertThat(EmptyUtils.isEmpty(string1)).isFalse();
assertThat(EmptyUtils.isEmpty(arr)).isTrue();
assertThat(EmptyUtils.isEmpty(arr1)).isTrue();
assertThat(EmptyUtils.isEmpty(list)).isTrue();
assertThat(EmptyUtils.isEmpty(map)).isTrue();
assertThat(EmptyUtils.isEmpty(sa)).isTrue();
assertThat(EmptyUtils.isEmpty(sba)).isTrue();
assertThat(EmptyUtils.isEmpty(sia)).isTrue();
assertThat(EmptyUtils.isEmpty(sla)).isTrue();
Assert.assertTrue(EmptyUtils.isEmpty(string));
Assert.assertFalse(EmptyUtils.isEmpty(string1));
Assert.assertTrue(EmptyUtils.isEmpty(arr));
Assert.assertTrue(EmptyUtils.isEmpty(arr1));
Assert.assertTrue(EmptyUtils.isEmpty(list));
Assert.assertTrue(EmptyUtils.isEmpty(map));
Assert.assertTrue(EmptyUtils.isEmpty(sam));
Assert.assertTrue(EmptyUtils.isEmpty(sa));
Assert.assertTrue(EmptyUtils.isEmpty(sba));
Assert.assertTrue(EmptyUtils.isEmpty(sia));
Assert.assertTrue(EmptyUtils.isEmpty(sla));
Assert.assertTrue(EmptyUtils.isEmpty(lsa));
Assert.assertTrue(EmptyUtils.isEmpty(lsa4));

assertThat(!EmptyUtils.isNotEmpty(string)).isTrue();
assertThat(!EmptyUtils.isNotEmpty(string1)).isFalse();
assertThat(!EmptyUtils.isNotEmpty(arr)).isTrue();
assertThat(!EmptyUtils.isNotEmpty(arr1)).isTrue();
assertThat(!EmptyUtils.isNotEmpty(list)).isTrue();
assertThat(!EmptyUtils.isNotEmpty(map)).isTrue();
assertThat(!EmptyUtils.isNotEmpty(sa)).isTrue();
assertThat(!EmptyUtils.isNotEmpty(sba)).isTrue();
assertThat(!EmptyUtils.isNotEmpty(sia)).isTrue();
assertThat(!EmptyUtils.isNotEmpty(sla)).isTrue();
Assert.assertTrue(!EmptyUtils.isNotEmpty(string));
Assert.assertFalse(!EmptyUtils.isNotEmpty(string1));
Assert.assertTrue(!EmptyUtils.isNotEmpty(arr));
Assert.assertTrue(!EmptyUtils.isNotEmpty(arr1));
Assert.assertTrue(!EmptyUtils.isNotEmpty(list));
Assert.assertTrue(!EmptyUtils.isNotEmpty(map));
Assert.assertTrue(!EmptyUtils.isNotEmpty(sam));
Assert.assertTrue(!EmptyUtils.isNotEmpty(sa));
Assert.assertTrue(!EmptyUtils.isNotEmpty(sba));
Assert.assertTrue(!EmptyUtils.isNotEmpty(sia));
Assert.assertTrue(!EmptyUtils.isNotEmpty(sla));
Assert.assertTrue(!EmptyUtils.isNotEmpty(lsa));
Assert.assertTrue(!EmptyUtils.isNotEmpty(lsa4));
}
}
Loading

0 comments on commit 9c98177

Please sign in to comment.