Simplify assertions in tests
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2022 the original author or authors.
|
||||
* Copyright 2006-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,7 +16,8 @@
|
||||
package org.springframework.batch.core;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -71,7 +72,7 @@ class ExitStatusTests {
|
||||
|
||||
@Test
|
||||
void testEqualsWithNull() {
|
||||
assertFalse(ExitStatus.EXECUTING.equals(null));
|
||||
assertNotEquals(null, ExitStatus.EXECUTING);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -119,35 +120,35 @@ class ExitStatusTests {
|
||||
@Test
|
||||
void testAddExitCode() {
|
||||
ExitStatus status = ExitStatus.EXECUTING.replaceExitCode("FOO");
|
||||
assertTrue(ExitStatus.EXECUTING != status);
|
||||
assertNotSame(ExitStatus.EXECUTING, status);
|
||||
assertEquals("FOO", status.getExitCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAddExitCodeToExistingStatus() {
|
||||
ExitStatus status = ExitStatus.EXECUTING.replaceExitCode("FOO").replaceExitCode("BAR");
|
||||
assertTrue(ExitStatus.EXECUTING != status);
|
||||
assertNotSame(ExitStatus.EXECUTING, status);
|
||||
assertEquals("BAR", status.getExitCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAddExitCodeToSameStatus() {
|
||||
ExitStatus status = ExitStatus.EXECUTING.replaceExitCode(ExitStatus.EXECUTING.getExitCode());
|
||||
assertTrue(ExitStatus.EXECUTING != status);
|
||||
assertNotSame(ExitStatus.EXECUTING, status);
|
||||
assertEquals(ExitStatus.EXECUTING.getExitCode(), status.getExitCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAddExitDescription() {
|
||||
ExitStatus status = ExitStatus.EXECUTING.addExitDescription("Foo");
|
||||
assertTrue(ExitStatus.EXECUTING != status);
|
||||
assertNotSame(ExitStatus.EXECUTING, status);
|
||||
assertEquals("Foo", status.getExitDescription());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAddExitDescriptionWIthStacktrace() {
|
||||
ExitStatus status = ExitStatus.EXECUTING.addExitDescription(new RuntimeException("Foo"));
|
||||
assertTrue(ExitStatus.EXECUTING != status);
|
||||
assertNotSame(ExitStatus.EXECUTING, status);
|
||||
String description = status.getExitDescription();
|
||||
assertTrue(description.contains("Foo"), "Wrong description: " + description);
|
||||
assertTrue(description.contains("RuntimeException"), "Wrong description: " + description);
|
||||
@@ -156,7 +157,7 @@ class ExitStatusTests {
|
||||
@Test
|
||||
void testAddExitDescriptionToSameStatus() {
|
||||
ExitStatus status = ExitStatus.EXECUTING.addExitDescription("Foo").addExitDescription("Foo");
|
||||
assertTrue(ExitStatus.EXECUTING != status);
|
||||
assertNotSame(ExitStatus.EXECUTING, status);
|
||||
assertEquals("Foo", status.getExitDescription());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2022 the original author or authors.
|
||||
* Copyright 2006-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -128,7 +128,7 @@ class JobExecutionTests {
|
||||
@Test
|
||||
void testGetJobIdForNullJob() {
|
||||
execution = new JobExecution((JobInstance) null, (JobParameters) null);
|
||||
assertEquals(null, execution.getJobId());
|
||||
assertNull(execution.getJobId());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2008-2022 the original author or authors.
|
||||
* Copyright 2008-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,6 +17,7 @@ package org.springframework.batch.core;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@@ -112,27 +113,27 @@ class JobParametersTests {
|
||||
@Test
|
||||
void testEquals() {
|
||||
JobParameters testParameters = getNewParameters();
|
||||
assertTrue(testParameters.equals(parameters));
|
||||
assertEquals(testParameters, parameters);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEqualsSelf() {
|
||||
assertTrue(parameters.equals(parameters));
|
||||
assertEquals(parameters, parameters);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEqualsDifferent() {
|
||||
assertFalse(parameters.equals(new JobParameters()));
|
||||
assertNotEquals(parameters, new JobParameters());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEqualsWrongType() {
|
||||
assertFalse(parameters.equals("foo"));
|
||||
assertNotEquals("foo", parameters);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEqualsNull() {
|
||||
assertFalse(parameters.equals(null));
|
||||
assertNotEquals(null, parameters);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2022 the original author or authors.
|
||||
* Copyright 2006-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -96,7 +96,7 @@ class ExtendedAbstractJobTests {
|
||||
@Test
|
||||
void testSetBeanNameWithNullName() {
|
||||
job = new StubJob(null, null);
|
||||
assertEquals(null, job.getName());
|
||||
assertNull(job.getName());
|
||||
job.setBeanName("foo");
|
||||
assertEquals("foo", job.getName());
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2022 the original author or authors.
|
||||
* Copyright 2006-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -50,6 +50,7 @@ import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
@@ -333,7 +334,7 @@ class CommandLineJobRunnerTests {
|
||||
StubJobExplorer.jobExecution = jobExecution;
|
||||
CommandLineJobRunner.main(args);
|
||||
assertEquals(1, StubSystemExiter.status);
|
||||
assertEquals(null, StubJobLauncher.jobParameters);
|
||||
assertNull(StubJobLauncher.jobParameters);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2008-2022 the original author or authors.
|
||||
* Copyright 2008-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -36,6 +36,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
@@ -329,13 +330,13 @@ public abstract class AbstractJobExecutionDaoTests {
|
||||
dao.saveJobExecution(exec1);
|
||||
|
||||
JobExecution exec2 = new JobExecution(jobInstance, jobParameters);
|
||||
assertTrue(exec1.getId() != null);
|
||||
assertNotNull(exec1.getId());
|
||||
exec2.setId(exec1.getId());
|
||||
|
||||
exec2.setStatus(BatchStatus.STARTED);
|
||||
exec2.setVersion(7);
|
||||
assertTrue(exec1.getVersion() != exec2.getVersion());
|
||||
assertTrue(exec1.getStatus() != exec2.getStatus());
|
||||
assertNotSame(exec1.getVersion(), exec2.getVersion());
|
||||
assertNotSame(exec1.getStatus(), exec2.getStatus());
|
||||
|
||||
dao.synchronizeStatus(exec2);
|
||||
|
||||
@@ -356,12 +357,12 @@ public abstract class AbstractJobExecutionDaoTests {
|
||||
dao.saveJobExecution(exec1);
|
||||
|
||||
JobExecution exec2 = new JobExecution(jobInstance, jobParameters);
|
||||
assertTrue(exec1.getId() != null);
|
||||
assertNotNull(exec1.getId());
|
||||
exec2.setId(exec1.getId());
|
||||
|
||||
exec2.setStatus(BatchStatus.UNKNOWN);
|
||||
exec2.setVersion(7);
|
||||
assertTrue(exec1.getVersion() != exec2.getVersion());
|
||||
assertNotSame(exec1.getVersion(), exec2.getVersion());
|
||||
assertTrue(exec1.getStatus().isLessThan(exec2.getStatus()));
|
||||
|
||||
dao.synchronizeStatus(exec2);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2022 the original author or authors.
|
||||
* Copyright 2006-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,7 +16,7 @@
|
||||
package org.springframework.batch.core.scope.context;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
@@ -35,6 +35,7 @@ import org.springframework.batch.item.ExecutionContext;
|
||||
/**
|
||||
* @author Dave Syer
|
||||
* @author Jimmy Praet
|
||||
* @author Mahmoud Ben Hassine
|
||||
*/
|
||||
class JobContextTests {
|
||||
|
||||
@@ -71,7 +72,7 @@ class JobContextTests {
|
||||
|
||||
@Test
|
||||
void testNotEqualsNull() {
|
||||
assertFalse(context.equals(null));
|
||||
assertNotEquals(null, context);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2022 the original author or authors.
|
||||
* Copyright 2006-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,7 +16,7 @@
|
||||
package org.springframework.batch.core.scope.context;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
@@ -65,7 +65,7 @@ class StepContextTests {
|
||||
|
||||
@Test
|
||||
void testNotEqualsNull() {
|
||||
assertFalse(context.equals(null));
|
||||
assertNotEquals(null, context);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -140,7 +140,7 @@ class FaultTolerantStepFactoryBeanRollbackTests {
|
||||
step.execute(stepExecution);
|
||||
assertEquals(FAILED, stepExecution.getStatus());
|
||||
assertEquals(FAILED.toString(), stepExecution.getExitStatus().getExitCode());
|
||||
assertTrue(stepExecution.getCommitCount() == 0);// Make sure exception was thrown
|
||||
assertEquals(0, stepExecution.getCommitCount());// Make sure exception was thrown
|
||||
// in after, not before
|
||||
Throwable e = stepExecution.getFailureExceptions().get(0);
|
||||
assertThat(e, instanceOf(FatalStepExecutionException.class));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2022 the original author or authors.
|
||||
* Copyright 2006-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -446,7 +446,7 @@ class TaskletStepTests {
|
||||
JobExecution jobExecution = new JobExecution(jobInstance, jobParameters);
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecution);
|
||||
|
||||
assertEquals(false, stepExecution.getExecutionContext().containsKey("foo"));
|
||||
assertFalse(stepExecution.getExecutionContext().containsKey("foo"));
|
||||
|
||||
step.execute(stepExecution);
|
||||
|
||||
@@ -467,7 +467,7 @@ class TaskletStepTests {
|
||||
JobExecution jobExecution = new JobExecution(jobInstance, jobParameters);
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecution);
|
||||
|
||||
assertEquals(false, stepExecution.getExecutionContext().containsKey("foo"));
|
||||
assertFalse(stepExecution.getExecutionContext().containsKey("foo"));
|
||||
|
||||
step.execute(stepExecution);
|
||||
|
||||
@@ -587,7 +587,7 @@ class TaskletStepTests {
|
||||
JobExecution jobExecution = new JobExecution(jobInstance, jobParameters);
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecution);
|
||||
|
||||
assertEquals(false, stepExecution.getExecutionContext().containsKey("foo"));
|
||||
assertFalse(stepExecution.getExecutionContext().containsKey("foo"));
|
||||
|
||||
step.execute(stepExecution);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user