-
Notifications
You must be signed in to change notification settings - Fork 837
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Persist ScanState to temp file then move to perm file
- Loading branch information
1 parent
b2df8be
commit 966b5ca
Showing
2 changed files
with
70 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/test/java/org/altbeacon/beacon/service/ScanStateTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package org.altbeacon.beacon.service; | ||
|
||
/** | ||
* Created by dyoung on 7/30/17. | ||
*/ | ||
|
||
import android.annotation.TargetApi; | ||
import android.content.Context; | ||
import android.os.AsyncTask; | ||
import android.os.Build; | ||
|
||
import org.altbeacon.beacon.BeaconManager; | ||
import org.altbeacon.beacon.logging.LogManager; | ||
import org.altbeacon.beacon.logging.Loggers; | ||
import org.altbeacon.beacon.service.scanner.CycledLeScanCallback; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.robolectric.Robolectric; | ||
import org.robolectric.RobolectricTestRunner; | ||
import org.robolectric.annotation.Config; | ||
import org.robolectric.shadows.ShadowApplication; | ||
import org.robolectric.util.ServiceController; | ||
|
||
import java.util.concurrent.ThreadPoolExecutor; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
/** | ||
* Created by dyoung on 7/1/15. | ||
*/ | ||
@RunWith(RobolectricTestRunner.class) | ||
@Config(sdk = 18) | ||
public class ScanStateTest { | ||
|
||
@Before | ||
public void before() { | ||
org.robolectric.shadows.ShadowLog.stream = System.err; | ||
LogManager.setLogger(Loggers.verboseLogger()); | ||
LogManager.setVerboseLoggingEnabled(true); | ||
BeaconManager.setsManifestCheckingDisabled(true); | ||
} | ||
|
||
@TargetApi(Build.VERSION_CODES.HONEYCOMB) | ||
@Test | ||
public void serializationTest() throws Exception { | ||
Context context = ShadowApplication.getInstance().getApplicationContext(); | ||
ScanState scanState = new ScanState(context); | ||
MonitoringStatus monitoringStatus = new MonitoringStatus(context); | ||
scanState.setMonitoringStatus(monitoringStatus); | ||
scanState.setLastScanStartTimeMillis(1234); | ||
scanState.save(); | ||
ScanState scanState2 = ScanState.restore(context); | ||
assertEquals("Scan start time should be restored", | ||
scanState.getLastScanStartTimeMillis(), scanState2.getLastScanStartTimeMillis()); | ||
} | ||
} |