// Path: app/src/mixedbit/speechtrainer/controller/RecordPlayTaskManager.java
// enum RecordPlayTaskState {
//     RECORD, PLAY, TERMINATE
// }
// 
// Path: app/src/mixedbit/speechtrainer/controller/SilenceFilter.java
// public enum Action {
//     // Accept the buffer.
//     ACCEPT_BUFFER,
//     // Drop all buffers accepted so far (including the buffer passed to the
//     // filterRecordedBuffer call that returned this action).
//     DROP_ALL_ACCEPTED_BUFFERS,
//     // Drop some number of trailing buffers and play all other accepted
//     // buffers. The number of buffers to drop is hold in the FilterResult.
//     DROP_TRAILING_BUFFERS_AND_PLAY,
// }


import org.easymock.EasyMock;
import mixedbit.speechtrainer.controller.RecordPlayTaskManager.RecordPlayTaskState;
import mixedbit.speechtrainer.controller.SilenceFilter.Action;
import org.easymock.Capture;
        final int trailingBuffersToDrop = 2;
        final int totalBuffersToRecord = leadingBuffersToDrop + buffersToPlay
        + trailingBuffersToDrop;
        expectTrainingStarted();
        // Expect totalBuffersToRecord to be filtered. When a buffer number
        // leadingBufferToDrop is recorded, all buffers should be dropped. Next,
        // buffersToPlay + trailingBuffersToDrop - 1 buffers should be accepted.
        // When a buffer number buffersToPlay + trailingBuffersToDrop is passed
        // to the silence filter, the filter should request
        // trailingBuffersToDrop to be dropped and the rest to be played.
        EasyMock.expect(
                mockSilenceFilter.filterRecorderBuffer(EasyMock.anyDouble(), EasyMock.anyInt()))
                .andReturn(mockSilenceFilter.new FilterResult(Action.ACCEPT_BUFFER))
                .times(leadingBuffersToDrop - 1)
                .andReturn(mockSilenceFilter.new FilterResult(Action.DROP_ALL_ACCEPTED_BUFFERS))
                .times(1)
                .andReturn(mockSilenceFilter.new FilterResult(Action.ACCEPT_BUFFER))
                .times(buffersToPlay + trailingBuffersToDrop - 1)
                .andReturn(mockSilenceFilter.new FilterResult(
                        Action.DROP_TRAILING_BUFFERS_AND_PLAY, trailingBuffersToDrop))
                        .times(1);
        replayAll();

        trainingController.startTraining();
        for (int i = 0; i < totalBuffersToRecord - 1; ++i) {
            // handleRecord should request recording to continue until the
            // silence filter returns DROP_TRAILING_BUFFERS_AND_PLAY.
            assertEquals(RecordPlayTaskState.RECORD, trainingController.handleRecord(testRecorder));
            assertEquals(i + 1, testRecorder.getRecordedBuffersCount());
        }
// Path: app/src/mixedbit/speechtrainer/controller/RecordPlayTaskManager.java
// enum RecordPlayTaskState {
//     RECORD, PLAY, TERMINATE
// }
// 
// Path: app/src/mixedbit/speechtrainer/controller/SilenceFilter.java
// public enum Action {
//     // Accept the buffer.
//     ACCEPT_BUFFER,
//     // Drop all buffers accepted so far (including the buffer passed to the
//     // filterRecordedBuffer call that returned this action).
//     DROP_ALL_ACCEPTED_BUFFERS,
//     // Drop some number of trailing buffers and play all other accepted
//     // buffers. The number of buffers to drop is hold in the FilterResult.
//     DROP_TRAILING_BUFFERS_AND_PLAY,
// }


// Path: app_tests/src/mixedbit/speechtrainer/controller/AutomaticTrainingControllerTest.java
import org.easymock.EasyMock;
import mixedbit.speechtrainer.controller.RecordPlayTaskManager.RecordPlayTaskState;
import mixedbit.speechtrainer.controller.SilenceFilter.Action;
import org.easymock.Capture;

        final int trailingBuffersToDrop = 2;
        final int totalBuffersToRecord = leadingBuffersToDrop + buffersToPlay
        + trailingBuffersToDrop;
        expectTrainingStarted();
        // Expect totalBuffersToRecord to be filtered. When a buffer number
        // leadingBufferToDrop is recorded, all buffers should be dropped. Next,
        // buffersToPlay + trailingBuffersToDrop - 1 buffers should be accepted.
        // When a buffer number buffersToPlay + trailingBuffersToDrop is passed
        // to the silence filter, the filter should request
        // trailingBuffersToDrop to be dropped and the rest to be played.
        EasyMock.expect(
                mockSilenceFilter.filterRecorderBuffer(EasyMock.anyDouble(), EasyMock.anyInt()))
                .andReturn(mockSilenceFilter.new FilterResult(Action.ACCEPT_BUFFER))
                .times(leadingBuffersToDrop - 1)
                .andReturn(mockSilenceFilter.new FilterResult(Action.DROP_ALL_ACCEPTED_BUFFERS))
                .times(1)
                .andReturn(mockSilenceFilter.new FilterResult(Action.ACCEPT_BUFFER))
                .times(buffersToPlay + trailingBuffersToDrop - 1)
                .andReturn(mockSilenceFilter.new FilterResult(
                        Action.DROP_TRAILING_BUFFERS_AND_PLAY, trailingBuffersToDrop))
                        .times(1);
        replayAll();

        trainingController.startTraining();
        for (int i = 0; i < totalBuffersToRecord - 1; ++i) {
            // handleRecord should request recording to continue until the
            // silence filter returns DROP_TRAILING_BUFFERS_AND_PLAY.
            assertEquals(RecordPlayTaskState.RECORD, trainingController.handleRecord(testRecorder));
            assertEquals(i + 1, testRecorder.getRecordedBuffersCount());
        }
        assertEquals(RecordPlayTaskState.PLAY, trainingController.handleRecord(testRecorder));