Skip to content

Commit

Permalink
Merge pull request #6 from isuPatches/issue-5
Browse files Browse the repository at this point in the history
issue-5
  • Loading branch information
isuPatches committed Apr 30, 2016
2 parents 772558b + ae81d49 commit a2aefad
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
32 changes: 31 additions & 1 deletion app/src/androidTest/java/com/metova/wisefy/WiseFyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import com.metova.wisefy.util.GetManagerUtil;
import com.metova.wisefy.util.TestActivity;
import com.robotium.solo.Condition;
import org.mockito.Mockito;
import java.util.ArrayList;
import java.util.List;
import static org.mockito.Mockito.*;
Expand Down Expand Up @@ -257,6 +256,37 @@ public void testIsSecureNullCapabilities() {
assertEquals(false, WiseFy.getSmarts().isSecure(scanResult));
}

public void testIsWiFiEnabledFalse() {
final WifiManager wifiManager = getLiveWiFiManager(getActivity());
wifiManager.setWifiEnabled(false);
assertTrue(getSolo().waitForCondition(new Condition() {
@Override
public boolean isSatisfied() {
return !wifiManager.isWifiEnabled();
}
}, 3000));
assertEquals(false, WiseFy.getSmarts().isWifiEnabled(getActivity()));
wifiManager.setWifiEnabled(true);
assertTrue(getSolo().waitForCondition(new Condition() {
@Override
public boolean isSatisfied() {
return wifiManager.isWifiEnabled();
}
}, 3000));
}

public void testIsWifiEnabledTrue() {
final WifiManager wifiManager = getLiveWiFiManager(getActivity());
wifiManager.setWifiEnabled(true);
assertTrue(getSolo().waitForCondition(new Condition() {
@Override
public boolean isSatisfied() {
return wifiManager.isWifiEnabled();
}
}, 3000));
assertEquals(true, WiseFy.getSmarts().isWifiEnabled(getActivity()));
}

public void testReconnectToNetworkSuccess() {
WiseFy.getSmarts().mGetManagerUtil = mMockGetManagerUtil;
List<WifiConfiguration> wifiList = new ArrayList<>();
Expand Down
18 changes: 18 additions & 0 deletions app/src/main/java/com/metova/wisefy/WiseFy.java
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,24 @@ public boolean isSecure(ScanResult scanResult) {
return isSecure;
}


/**
* To check if Wifi is enabled on the device or not
*
* @param activity - The activity to use as context to retrieve a wifi manager via getSystemService
* @return boolean - if Wifi is enabled on device
*/
public boolean isWifiEnabled(Activity activity) {
boolean isWifiEnabled = false;
if(activity != null) {
WifiManager wifiManager = GetManagerUtil.getInstance().getWiFiManager(activity);
isWifiEnabled = wifiManager.isWifiEnabled();
} else {
LogUtil.w(TAG, "No activity to get wifi config");
}
return isWifiEnabled;
}

/**
* Used to reconnect to a network
*
Expand Down

0 comments on commit a2aefad

Please sign in to comment.