Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8b0fa19

Browse files
committed
Updated gradle version and added extra tests
1 parent f0d9be6 commit 8b0fa19

File tree

9 files changed

+81
-35
lines changed

9 files changed

+81
-35
lines changed

app/build.gradle

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ android {
5858
}
5959
}
6060

61-
productFlavors {
62-
regular { }
63-
// Add a CI only flavor that has extra permissions needed for CI to perform
64-
ci { }
65-
}
61+
// productFlavors {
62+
// regular { }
63+
// // Add a CI only flavor that has extra permissions needed for CI to perform
64+
// ci { }
65+
// }
6666

6767
}
6868

@@ -74,14 +74,13 @@ spoon {
7474
}
7575

7676
dependencies {
77-
compile fileTree(dir: 'libs', include: ['*.jar'])
78-
compile "com.android.support:appcompat-v7:$supportLibVer"
79-
compile "com.android.support:design:$supportLibVer"
80-
compile project(':library')
77+
implementation "com.android.support:appcompat-v7:$supportLibVer"
78+
implementation "com.android.support:design:$supportLibVer"
79+
implementation project(':library')
8180

82-
testCompile 'junit:junit:4.12'
81+
testImplementation 'junit:junit:4.12'
8382

84-
androidTestCompile 'com.squareup.spoon:spoon-client:1.6.4'
85-
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
86-
androidTestCompile('com.android.support.test.espresso:espresso-intents:2.2')
83+
androidTestImplementation 'com.squareup.spoon:spoon-client:1.6.4'
84+
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
85+
androidTestImplementation('com.android.support.test.espresso:espresso-intents:2.2')
8786
}

build.gradle

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@
22

33
buildscript {
44
repositories {
5+
google()
56
jcenter()
67
}
78
dependencies {
8-
classpath 'com.android.tools.build:gradle:2.2.2'
9+
classpath 'com.android.tools.build:gradle:3.1.3'
910
// NOTE: Do not place your application dependencies here; they belong
1011
// in the individual module build.gradle files
1112
}
1213
}
1314

1415
allprojects {
1516
repositories {
17+
google()
1618
jcenter()
1719
}
1820
}
@@ -22,11 +24,11 @@ task clean(type: Delete) {
2224
}
2325

2426
subprojects {
25-
ext.compileSdkVer = 24
26-
ext.buildToolsVer = "24.0.0"
27-
ext.minSdkVer = 10
28-
ext.targetSdkVer = 24
29-
ext.supportLibVer = "24.0.0"
27+
ext.compileSdkVer = 27
28+
ext.buildToolsVer = "27.0.3"
29+
ext.minSdkVer = 14
30+
ext.targetSdkVer = 27
31+
ext.supportLibVer = "27.1.1"
3032

3133
ext.versionName = "0.3.08"
3234
ext.versionCode = 13

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

library/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ android {
1919
}
2020

2121
dependencies {
22-
testCompile 'junit:junit:4.12'
23-
testCompile 'org.mockito:mockito-core:1.10.19'
24-
provided 'com.android.support:appcompat-v7:24.2.0'
22+
testImplementation 'junit:junit:4.12'
23+
testImplementation 'org.mockito:mockito-core:2.10.0'
24+
provided 'com.android.support:appcompat-v7:27.1.1'
2525
}

library/src/main/java/com/stealthcopter/networktools/IPTools.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@
1515
*/
1616
public class IPTools {
1717

18-
// This class is not to be instantiated
19-
private IPTools() {
20-
}
21-
22-
2318
/**
2419
* Ip matching patterns from
2520
* https://examples.javacodegeeks.com/core-java/util/regex/regular-expressions-for-ip-v4-and-ip-v6-addresses/
@@ -38,20 +33,24 @@ private IPTools() {
3833
Pattern.compile(
3934
"^((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)::((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)$");
4035

36+
// This class is not to be instantiated
37+
private IPTools() {
38+
}
39+
4140
public static boolean isIPv4Address(final String address) {
42-
return IPV4_PATTERN.matcher(address).matches();
41+
return address != null && IPV4_PATTERN.matcher(address).matches();
4342
}
4443

4544
public static boolean isIPv6StdAddress(final String address) {
46-
return IPV6_STD_PATTERN.matcher(address).matches();
45+
return address != null && IPV6_STD_PATTERN.matcher(address).matches();
4746
}
4847

4948
public static boolean isIPv6HexCompressedAddress(final String address) {
50-
return IPV6_HEX_COMPRESSED_PATTERN.matcher(address).matches();
49+
return address != null && IPV6_HEX_COMPRESSED_PATTERN.matcher(address).matches();
5150
}
5251

5352
public static boolean isIPv6Address(final String address) {
54-
return isIPv6StdAddress(address) || isIPv6HexCompressedAddress(address);
53+
return address != null && (isIPv6StdAddress(address) || isIPv6HexCompressedAddress(address));
5554
}
5655

5756
/**
@@ -101,6 +100,8 @@ public static ArrayList<InetAddress> getLocalIPv4Addresses() {
101100
* @return - true if ip address is self
102101
*/
103102
public static boolean isIpAddressLocalhost(InetAddress addr) {
103+
if (addr == null) return false;
104+
104105
// Check if the address is a valid special local or loop back
105106
if (addr.isAnyLocalAddress() || addr.isLoopbackAddress())
106107
return true;
@@ -122,7 +123,7 @@ public static boolean isIpAddressLocalhost(InetAddress addr) {
122123
* @return - true if ip address is self
123124
*/
124125
public static boolean isIpAddressLocalNetwork(InetAddress addr) {
125-
return addr.isSiteLocalAddress();
126+
return addr != null && addr.isSiteLocalAddress();
126127
}
127128

128129

library/src/main/java/com/stealthcopter/networktools/MACTools.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ private MACTools() {
2424
* eg: "01:23:45:67:89:AB:CD:EF" or "01-23-45-67-89-AB-CD-EF"
2525
*/
2626
public static boolean isValidMACAddress(final String macAddress) {
27-
return PATTERN_MAC.matcher(macAddress).matches();
27+
return macAddress != null && PATTERN_MAC.matcher(macAddress).matches();
2828
}
2929

3030

library/src/main/java/com/stealthcopter/networktools/WakeOnLan.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ public static void sendWakeOnLan(@NonNull String ipStr, @NonNull String macStr)
185185
* @param packets - number of packets to send
186186
*/
187187
public static void sendWakeOnLan(@NonNull final String ipStr, @NonNull final String macStr, final int port, final int timeoutMillis, final int packets) throws IllegalArgumentException, IOException {
188+
if (ipStr == null) throw new IllegalArgumentException("Address cannot be null");
188189
InetAddress address = InetAddress.getByName(ipStr);
189190
sendWakeOnLan(address, macStr, port, timeoutMillis, packets);
190191
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.stealthcopter.networktools;
2+
3+
import org.junit.Test;
4+
5+
import static org.junit.Assert.assertFalse;
6+
import static org.junit.Assert.assertTrue;
7+
8+
/**
9+
* Created by matthew on 03/11/17.
10+
*/
11+
12+
public class MACToolsTest {
13+
14+
String[] getInvalidMACAddresses(){
15+
return new String[]{null, "beepbeep", "nope", "hello", "00-15-E9-2B-99+3C", "0G-15-E9-2B-99-3C"};
16+
}
17+
18+
String[] getValidMACAddresses(){
19+
return new String[]{"00:00:00:00:00:00", "00-15-E9-2B-99-3C", "00:15:E9:2B:99:3C", "00-15-e9-2b-99-3c"};
20+
}
21+
22+
@Test
23+
public void testValidMACAddresses() {
24+
for (String macAddress : getValidMACAddresses()) {
25+
assertTrue(MACTools.isValidMACAddress(macAddress));
26+
}
27+
}
28+
29+
@Test
30+
public void testInvalidMACAddresses() {
31+
for (String macAddress: getInvalidMACAddresses()) {
32+
assertFalse(MACTools.isValidMACAddress(macAddress));
33+
}
34+
}
35+
36+
}

library/src/test/java/com/stealthcopter/networktools/WakeOnLanTest.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,21 @@
22

33
import org.junit.Test;
44

5+
import java.net.InetAddress;
6+
57
/**
68
* To work on unit tests, switch the Test Artifact in the Build Variants view.
79
*/
810
public class WakeOnLanTest {
911

12+
@Test(expected = IllegalArgumentException.class)
13+
public void testIllegalArgumentThrownOnInvalidIPaddressStr() throws Exception {
14+
WakeOnLan.sendWakeOnLan((String)null, "00:04:20:06:55:1a", 9, 10000, 5);
15+
}
16+
1017
@Test(expected = IllegalArgumentException.class)
1118
public void testIllegalArgumentThrownOnInvalidIPaddress() throws Exception {
12-
WakeOnLan.sendWakeOnLan(null, "00:04:20:06:55:1a", 9, 10000, 5);
19+
WakeOnLan.sendWakeOnLan((InetAddress) null, "00:04:20:06:55:1a", 9, 10000, 5);
1320
}
1421

1522
@Test(expected = IllegalArgumentException.class)

0 commit comments

Comments
 (0)