Package hudson.plugins.im.bot

Source Code of hudson.plugins.im.bot.CommentCommandTest

package hudson.plugins.im.bot;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.plugins.im.Sender;

import java.io.IOException;

import org.junit.Test;

public class CommentCommandTest {

    @Test
    public void testSetComment() throws IOException, CommandException {
        @SuppressWarnings({ "rawtypes" })
        AbstractProject project = mock(AbstractProject.class);
        AbstractBuild<?, ?> build = mock(AbstractBuild.class);
        when(project.getBuildByNumber(4711)).thenReturn(build);
       
        CommentCommand command = new CommentCommand();
        String result = command.getMessageForJob(project, new Sender("kutzi"),
                new String[] { "4711", "my comment"}).toString();
        assertEquals("Ok", result);
       
        verify(build).setDescription("my comment");
    }
   
    @Test(expected = CommandException.class)
    public void testMalformedBuildNumber() throws CommandException {
        AbstractProject<?, ?> project = mock(AbstractProject.class);
       
        CommentCommand command = new CommentCommand();
        command.getMessageForJob(project, new Sender("kutzi"),
                new String[] { "abc", "my comment"}).toString();
    }
   
    @Test(expected = CommandException.class)
    public void testUnknownBuildNumber() throws CommandException {
        @SuppressWarnings("rawtypes")
        AbstractProject project = mock(AbstractProject.class);
        AbstractBuild<?, ?> build = mock(AbstractBuild.class);
        when(project.getBuildByNumber(4711)).thenReturn(build);
       
        CommentCommand command = new CommentCommand();
        command.getMessageForJob(project, new Sender("kutzi"),
                new String[] { "4712", "my comment"}).toString();
    }
}
TOP

Related Classes of hudson.plugins.im.bot.CommentCommandTest

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.