Package intellijcoder.ipc

Source Code of intellijcoder.ipc.FakeWorkspaceManager

package intellijcoder.ipc;

import intellijcoder.workspace.WorkspaceManager;
import intellijcoder.model.Problem;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

import static java.util.concurrent.TimeUnit.SECONDS;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

/**
* Fake WorkspaceManager implementation to use in testing asynchronous code
*
* Date: 14.01.11
*
* @author Konstantin Fadeyev
*/
public class FakeWorkspaceManager implements WorkspaceManager {
    private static final int TIMEOUT = 5;
    private final BlockingQueue<Problem> receivingProblemQueue = new ArrayBlockingQueue<Problem>(1);

    public void createProblemWorkspace(Problem problem) {
        receivingProblemQueue.add(problem);
    }

    public String getSolutionSource(String className) {
        return null;
    }

    public void hasReceivedProblemEqualTo(Problem expectedProblem) throws InterruptedException {
        Problem receviedProblem = receivingProblemQueue.poll(TIMEOUT, SECONDS);
        assertNotNull("hasn't received problem data in "+TIMEOUT+" seconds", receviedProblem);
        assertEquals("Problem", expectedProblem, receviedProblem);
    }
}
TOP

Related Classes of intellijcoder.ipc.FakeWorkspaceManager

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.