提交 34202aaf 编写于 作者: S Stefan Spieker

minor test refactoring

上级 297f4b2e
......@@ -33,13 +33,14 @@ import static org.junit.Assert.*;
import java.util.Collections;
import java.util.List;
import edu.umd.cs.findbugs.annotations.NonNull;
import org.junit.Assert;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
public class ActionableTest {
private Actionable thing = new ActionableImpl();
private final Actionable thing = new ActionableImpl();
@SuppressWarnings("deprecation")
@Test
......@@ -67,6 +68,7 @@ public class ActionableTest {
}
@Override
@NonNull
public List<Action> getActions() {
return specialActions;
}
......@@ -75,7 +77,7 @@ public class ActionableTest {
@SuppressWarnings("deprecation")
@Issue("JENKINS-39555")
@Test
public void testExtensionOverrides() throws Exception {
public void testExtensionOverrides() {
ActionableOverride myOverridden = new ActionableOverride();
InvisibleAction invis = new InvisibleAction() {
};
......@@ -144,11 +146,11 @@ public class ActionableTest {
thing.addAction(a2);
assertEquals(Arrays.asList(a1, a2), thing.getActions());
assertThat(thing.removeAction(a1), is(true));
assertEquals(Arrays.asList(a2), thing.getActions());
assertEquals(Collections.singletonList(a2), thing.getActions());
assertThat(thing.removeAction(a1), is(false));
assertEquals(Arrays.asList(a2), thing.getActions());
assertEquals(Collections.singletonList(a2), thing.getActions());
assertThat(thing.removeAction(null), is(false));
assertEquals(Arrays.asList(a2), thing.getActions());
assertEquals(Collections.singletonList(a2), thing.getActions());
}
@SuppressWarnings("deprecation")
......@@ -160,9 +162,9 @@ public class ActionableTest {
thing.addAction(a2);
assertEquals(Arrays.asList(a1, a2), thing.getActions());
assertThat(thing.removeActions(CauseAction.class), is(true));
assertEquals(Arrays.asList(a2), thing.getActions());
assertEquals(Collections.singletonList(a2), thing.getActions());
assertThat(thing.removeActions(CauseAction.class), is(false));
assertEquals(Arrays.asList(a2), thing.getActions());
assertEquals(Collections.singletonList(a2), thing.getActions());
}
@SuppressWarnings("deprecation")
......
package hudson.model;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.EnvVars;
import org.junit.Test;
......@@ -15,7 +16,7 @@ public class EnvironmentContributingActionTest {
private boolean wasCalled = false;
@Override
public void buildEnvironment(Run<?, ?> run, EnvVars env) {
public void buildEnvironment(@NonNull Run<?, ?> run, @NonNull EnvVars env) {
wasCalled = true;
}
......@@ -49,7 +50,7 @@ public class EnvironmentContributingActionTest {
}
@Override
public void buildEnvironment(Run<?, ?> run, EnvVars env) {
public void buildEnvironment(@NonNull Run<?, ?> run, @NonNull EnvVars env) {
wasCalledRun = true;
}
......@@ -65,9 +66,8 @@ public class EnvironmentContributingActionTest {
private final EnvVars envVars = mock(EnvVars.class);
@Test
public void testOverrideRunMethodAndCallNewMethod() throws Exception {
Run run = mock(Run.class);
Node node = mock(Node.class);
public void testOverrideRunMethodAndCallNewMethod() {
Run<?,?> run = mock(Run.class);
OverrideRun overrideRun = new OverrideRun();
overrideRun.buildEnvironment(run, envVars);
......@@ -77,12 +77,11 @@ public class EnvironmentContributingActionTest {
/**
* If only non-deprecated method was overridden it would be executed even if someone would call deprecated method.
* @throws Exception if happens.
*/
@Test
@SuppressWarnings("deprecation")
public void testOverrideRunMethodAndCallDeprecatedMethod() throws Exception {
AbstractBuild abstractBuild = mock(AbstractBuild.class);
public void testOverrideRunMethodAndCallDeprecatedMethod() {
AbstractBuild<?,?> abstractBuild = mock(AbstractBuild.class);
when(abstractBuild.getBuiltOn()).thenReturn(mock(Node.class));
OverrideRun overrideRun = new OverrideRun();
......@@ -93,11 +92,10 @@ public class EnvironmentContributingActionTest {
/**
* {@link AbstractBuild} should work as before.
* @throws Exception if happens.
*/
@Test
public void testOverrideAbstractBuildAndCallNewMethodWithAbstractBuild() throws Exception {
AbstractBuild abstractBuild = mock(AbstractBuild.class);
public void testOverrideAbstractBuildAndCallNewMethodWithAbstractBuild() {
AbstractBuild<?,?> abstractBuild = mock(AbstractBuild.class);
OverrideAbstractBuild action = new OverrideAbstractBuild();
action.buildEnvironment(abstractBuild, envVars);
......@@ -107,11 +105,10 @@ public class EnvironmentContributingActionTest {
/**
* {@link Run} should not execute method that was overridden for {@link AbstractBuild}.
* @throws Exception if happens.
*/
@Test
public void testOverrideAbstractBuildAndCallNewMethodWithRun() throws Exception {
Run run = mock(Run.class);
public void testOverrideAbstractBuildAndCallNewMethodWithRun() {
Run<?,?> run = mock(Run.class);
OverrideAbstractBuild action = new OverrideAbstractBuild();
action.buildEnvironment(run, envVars);
......@@ -121,11 +118,10 @@ public class EnvironmentContributingActionTest {
/**
* If someone wants to use overridden deprecated method, it would still work.
* @throws Exception if happens.
*/
@Test
public void testOverrideAbstractBuildAndCallDeprecatedMethod() throws Exception {
AbstractBuild abstractBuild = mock(AbstractBuild.class);
public void testOverrideAbstractBuildAndCallDeprecatedMethod() {
AbstractBuild<?,?> abstractBuild = mock(AbstractBuild.class);
OverrideAbstractBuild overrideRun = new OverrideAbstractBuild();
overrideRun.buildEnvVars(abstractBuild, envVars);
......@@ -134,8 +130,8 @@ public class EnvironmentContributingActionTest {
}
@Test
public void testOverrideBothAndCallNewMethod() throws Exception {
Run run = mock(Run.class);
public void testOverrideBothAndCallNewMethod() {
Run<?,?> run = mock(Run.class);
OverrideBoth overrideRun = new OverrideBoth();
overrideRun.buildEnvironment(run, envVars);
......@@ -144,8 +140,8 @@ public class EnvironmentContributingActionTest {
}
@Test
public void testOverrideBothAndCallDeprecatedMethod() throws Exception {
AbstractBuild abstractBuild = mock(AbstractBuild.class);
public void testOverrideBothAndCallDeprecatedMethod() {
AbstractBuild<?,?> abstractBuild = mock(AbstractBuild.class);
OverrideBoth overrideRun = new OverrideBoth();
overrideRun.buildEnvVars(abstractBuild, envVars);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册