Package de.mh4j.solver

Source Code of de.mh4j.solver.AbstractSolverTest$AbstractSolverMock

package de.mh4j.solver;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import org.testng.annotations.Test;

import ch.qos.logback.classic.Level;
import de.mh4j.solver.termination.TerminationCondition;

public class AbstractSolverTest {

    @Test
    public void testSolverRun() {
        AbstractSolver<Object> solver = spy(new AbstractSolverMock());

        TerminationCondition terminationCondition = mock(TerminationCondition.class);
        when(terminationCondition.shouldTerminate()).thenReturn(true);
        solver.addTerminationCondition(terminationCondition);

        @SuppressWarnings("unchecked")
        SolverStateListener<Object> stateListener = mock(SolverStateListener.class);
        solver.addStateListener(stateListener);

        solver.run();

        verify(solver).step();
        verify(solver).hasFinished();
        verify(stateListener).solverHasFinished(solver);
    }

    @Test
    public void testStateListenerisNotifiedAfterReset() {
        AbstractSolver<Object> solver = new AbstractSolverMock();

        @SuppressWarnings("unchecked")
        SolverStateListener<Object> stateListener = mock(SolverStateListener.class);

        solver.addStateListener(stateListener);
        solver.reset();

        verify(stateListener).solverHasBeenRestarted(solver);
    }

    @Test
    public void testSetLogLevel() {
        AbstractSolver<Object> solver = new AbstractSolverMock();

        solver.setLogLevel(Level.DEBUG);
        assert solver.log.getLevel() == Level.DEBUG;

        solver.setLogLevel(Level.INFO);
        assert solver.log.getLevel() == Level.INFO;

        solver.setLogLevel(Level.WARN);
        assert solver.log.getLevel() == Level.WARN;

        solver.setLogLevel(Level.ERROR);
        assert solver.log.getLevel() == Level.ERROR;
    }

    private class AbstractSolverMock extends AbstractSolver<Object> {

        @Override
        public AbstractSolverTest getCurrentSolution() {
            return null;
        }

        @Override
        protected void doInitialize() {
        }

        @Override
        protected void doStep() {
        }

    }
}
TOP

Related Classes of de.mh4j.solver.AbstractSolverTest$AbstractSolverMock

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.