Skip to content
Browse files

Sessions can be saved again

  • Loading branch information...
1 parent 6138fa4 commit 4754322a7b77a8a64151b3c2b494964c8f51392e @obrok obrok committed Apr 4, 2012
View
2 src/main/java/pl/llp/aircasting/activity/ButtonsActivity.java
@@ -261,7 +261,7 @@ private synchronized void toggleAirCasting() {
}
private void stopAirCasting() {
- if (sessionManager.getSoundMeasurements().isEmpty()) {
+ if (sessionManager.getSession().isEmpty()) {
Toast.makeText(context, R.string.no_data, Toast.LENGTH_SHORT).show();
sessionManager.discardSession();
} else {
View
3 src/main/java/pl/llp/aircasting/model/SessionManager.java
@@ -268,6 +268,7 @@ private void notifyNewSession() {
public void startSession() {
setSession(new Session());
+ session.setStart(new Date());
startSensors();
sessionStarted = true;
notificationHelper.showRecordingNotification();
@@ -291,6 +292,8 @@ private void fillInDetails() {
session.setInstrument(metadataHelper.getInstrument());
session.setOsVersion(metadataHelper.getOSVersion());
session.setPhoneModel(metadataHelper.getPhoneModel());
+
+ session.setEnd(new Date());
}
private void cleanup() {
View
55 src/test/java/pl/llp/aircasting/model/SessionManagerTest.java
@@ -19,6 +19,17 @@
*/
package pl.llp.aircasting.model;
+import android.location.Location;
+import android.location.LocationManager;
+import com.google.common.collect.Iterables;
+import com.google.common.eventbus.EventBus;
+import com.google.inject.Inject;
+import org.hamcrest.BaseMatcher;
+import org.hamcrest.Description;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
import pl.llp.aircasting.InjectedTestRunner;
import pl.llp.aircasting.event.sensor.MeasurementEvent;
import pl.llp.aircasting.event.sensor.SensorEvent;
@@ -31,17 +42,7 @@
import pl.llp.aircasting.sensor.builtin.SimpleAudioReader;
import pl.llp.aircasting.sensor.external.ExternalSensor;
-import android.location.Location;
-import android.location.LocationManager;
-import com.google.common.collect.Iterables;
-import com.google.common.eventbus.EventBus;
-import com.google.inject.Inject;
-import org.hamcrest.BaseMatcher;
-import org.hamcrest.Description;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mockito;
+import java.util.Date;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.not;
@@ -176,7 +177,7 @@ public void shouldProvidePeakForEachStream() {
String name = sensor.getSensorName();
when(stream.getSensorName()).thenReturn(name);
sessionManager.session.add(stream);
-
+
assertThat(sessionManager.getPeak(sensor), equalTo(11.0));
}
@@ -320,6 +321,36 @@ public void shouldNotAddMeasurementsToASavedSession() {
}
@Test
+ public void shouldSetSessionStart() {
+ sessionManager.startSession();
+
+ int oneSecond = 1000;
+ assertThat(new Date().getTime() - sessionManager.session.getStart().getTime() < oneSecond, equalTo(true));
+ }
+
+ @Test
+ public void shouldSetSessionEnd() {
+ sessionManager.startSession();
+ triggerMeasurement();
+
+ sessionManager.finishSession(null);
+
+ verify(sessionManager.sessionRepository).save(Mockito.argThat(new BaseMatcher<Session>() {
+ @Override
+ public boolean matches(Object o) {
+ Session other = (Session) o;
+ long oneSecond = 1000;
+ return new Date().getTime() - other.getEnd().getTime() < oneSecond;
+ }
+
+ @Override
+ public void describeTo(Description description) {
+ description.appendText("Session with end set");
+ }
+ }), Mockito.<ProgressListener>any());
+ }
+
+ @Test
public void shouldSaveAdditionalData() {
fail("Needs a redo");

0 comments on commit 4754322

Please sign in to comment.
Something went wrong with that request. Please try again.