Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed 4 unnecessary stubbings in RoundhouseActionTest.java #224

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import static org.mockito.Mockito.mock;

import hudson.model.Job;
import hudson.model.Result;
import hudson.model.Run;
import java.util.Arrays;
import junit.framework.TestCase;
Expand All @@ -25,7 +24,6 @@ public void setUp() {
action = new RoundhouseAction(Style.BAD_ASS, "Chuck Norris can divide by zero.");

run = mock(Run.class);
given(run.getResult()).willReturn(Result.SUCCESS);

lastBuildAction = new RoundhouseAction(Style.ALERT, "Chuck Norris went out of an infinite loop.");
final Job job = mock(Job.class);
Expand All @@ -41,26 +39,6 @@ public Job answer(InvocationOnMock invocation) throws Throwable {
given(lastRun.getActions(eq(RoundhouseAction.class))).willReturn(Arrays.asList(lastBuildAction));
}

public void testAccessors() {
assertEquals(Style.BAD_ASS, action.getStyle());
assertEquals("Chuck Norris can divide by zero.", action.getFact());
assertEquals("Chuck Norris", action.getDisplayName());
assertNull(action.getIconFileName());
assertEquals("chucknorris", action.getUrlName());
}

public void testGetProjectActions() {
assertNotNull(action.getProjectActions());
assertEquals(1, action.getProjectActions().size());
assertSame(action, action.getProjectActions().iterator().next());
}

public void testGetStyleFromRunResult() {
action.onAttached(run);

assertEquals(Style.THUMB_UP, action.getStyle());
}

public void testGetProjectActionsFromLastProjectBuild() {
action.onAttached(run);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package hudson.plugins.chucknorris;

import static org.mockito.Mockito.mock;

import hudson.model.Job;
import hudson.model.Run;
import junit.framework.TestCase;

public class SecondRoundhouseActionTest extends TestCase {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use JUnit 4 rather than JUnit 3 for the tests. JUnit 4 is more familiar to Jenkins developers and is widely used in Jenkins plugins. See the stackoverflow article for more details on why JUnit 4 annotations are better than JUnit 3 inheritance.

Note that this suggestion won't compile if you apply it directly.

Suggested change
public class SecondRoundhouseActionTest extends TestCase {
public class SecondRoundhouseActionTest {


private RoundhouseAction action;

private Run<?, ?> run;
private RoundhouseAction lastBuildAction;

@Override
@SuppressWarnings("rawtypes")
public void setUp() {
action = new RoundhouseAction(Style.BAD_ASS, "Chuck Norris can divide by zero.");

run = mock(Run.class);
lastBuildAction = new RoundhouseAction(Style.ALERT, "Chuck Norris went out of an infinite loop.");
final Job job = mock(Job.class);
Run<?, ?> lastRun = mock(Run.class);
}

public void testAccessors() {
assertEquals(Style.BAD_ASS, action.getStyle());
assertEquals("Chuck Norris can divide by zero.", action.getFact());
assertEquals("Chuck Norris", action.getDisplayName());
assertNull(action.getIconFileName());
assertEquals("chucknorris", action.getUrlName());
}

public void testGetProjectActions() {
assertNotNull(action.getProjectActions());
assertEquals(1, action.getProjectActions().size());
assertSame(action, action.getProjectActions().iterator().next());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package hudson.plugins.chucknorris;

import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;

import hudson.model.Job;
import hudson.model.Result;
import hudson.model.Run;
import junit.framework.TestCase;

public class ThirdRoundhouseActionTest extends TestCase {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use JUnit 4 rather than JUnit 3 for the tests. JUnit 4 is more familiar to Jenkins developers and is widely used in Jenkins plugins. See the stackoverflow article for more details on why JUnit 4 annotations are better than JUnit 3 inheritance.

Note that this suggestion won't compile if applied directly. Switching to JUnit 4 requires more than this single change.

Suggested change
public class ThirdRoundhouseActionTest extends TestCase {
public class ThirdRoundhouseActionTest {


private RoundhouseAction action;

private Run<?, ?> run;
private RoundhouseAction lastBuildAction;

@Override
@SuppressWarnings("rawtypes")
public void setUp() {
action = new RoundhouseAction(Style.BAD_ASS, "Chuck Norris can divide by zero.");

run = mock(Run.class);
given(run.getResult()).willReturn(Result.SUCCESS);

lastBuildAction = new RoundhouseAction(Style.ALERT, "Chuck Norris went out of an infinite loop.");
final Job job = mock(Job.class);
Run<?, ?> lastRun = mock(Run.class);
}

public void testGetStyleFromRunResult() {
action.onAttached(run);

assertEquals(Style.THUMB_UP, action.getStyle());
}
}