Simplify assertions in tests

This commit is contained in:
Mahmoud Ben Hassine
2023-06-05 13:08:15 +02:00
parent 42fc4f686e
commit 6d3e48a0bc
15 changed files with 81 additions and 75 deletions

View File

@@ -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.
@@ -17,6 +17,7 @@ package org.springframework.batch.item;
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.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -107,9 +108,9 @@ class ExecutionContextTests {
void testEquals() {
context.putString("1", "testString");
ExecutionContext tempContext = new ExecutionContext();
assertFalse(tempContext.equals(context));
assertNotEquals(tempContext, context);
tempContext.putString("1", "testString");
assertTrue(tempContext.equals(context));
assertEquals(tempContext, context);
}
/**

View File

@@ -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.
@@ -97,7 +97,7 @@ class BeanWrapperFieldSetMapperTests {
new String[] { "varString", "varBoolean", "varChar" });
TestObject result = mapper.mapFieldSet(fieldSet);
assertEquals("This is some dummy string", result.getVarString());
assertEquals(true, result.isVarBoolean());
assertTrue(result.isVarBoolean());
assertEquals('C', result.getVarChar());
}
@@ -125,7 +125,7 @@ class BeanWrapperFieldSetMapperTests {
new String[] { "varString", "varBoolean", "varChar" });
TestObject result = mapper.mapFieldSet(fieldSet);
assertEquals("This is some dummy string", result.getVarString());
assertEquals(true, result.isVarBoolean());
assertTrue(result.isVarBoolean());
assertEquals('C', result.getVarChar());
}
@@ -142,7 +142,7 @@ class BeanWrapperFieldSetMapperTests {
new String[] { "VarString", "VAR_BOOLEAN", "VAR_CHAR" });
TestObject result = mapper.mapFieldSet(fieldSet);
assertEquals("This is some dummy string", result.getVarString());
assertEquals(true, result.isVarBoolean());
assertTrue(result.isVarBoolean());
assertEquals('C', result.getVarChar());
}
@@ -158,7 +158,7 @@ class BeanWrapperFieldSetMapperTests {
new String[] { "varString", "varBoolean", "varChar" });
TestObject result = mapper.mapFieldSet(fieldSet);
assertEquals("This is some dummy string", result.getVarString());
assertEquals(true, result.isVarBoolean());
assertTrue(result.isVarBoolean());
assertEquals('C', result.getVarChar());
}
@@ -292,7 +292,7 @@ class BeanWrapperFieldSetMapperTests {
Properties props = (Properties) editor.getValue();
wrapper.setPropertyValues(props);
assertEquals("This is some dummy string", result.getVarString());
assertEquals(true, result.isVarBoolean());
assertTrue(result.isVarBoolean());
assertEquals('C', result.getVarChar());
}
@@ -452,7 +452,7 @@ class BeanWrapperFieldSetMapperTests {
assertEquals(bean.getVarInt(), 12, "Expected 12 for varInt");
assertEquals(bean.getVarLong(), 12345L, "Expected 12345 for varLong");
assertEquals(bean.isVarBoolean(), true, "Expected true for varBoolean");
assertTrue(bean.isVarBoolean(), "Expected true for varBoolean");
assertEquals(bean.getVarChar(), 'Z', "Expected Z for varChar");
assertEquals(bean.getVarByte(), 123, "Expected A for varByte");
assertEquals(bean.getVarFloat(), 12345F, 1F, "Expected 12345 for varFloat");
@@ -556,7 +556,7 @@ class BeanWrapperFieldSetMapperTests {
new String[] { "varString", "illegalPropertyName", "varBoolean", "varChar" });
TestObject result = mapper.mapFieldSet(fieldSet);
assertEquals("This is some dummy string", result.getVarString());
assertEquals(true, result.isVarBoolean());
assertTrue(result.isVarBoolean());
assertEquals('C', result.getVarChar());
}

View File

@@ -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.
@@ -18,6 +18,7 @@ package org.springframework.batch.item.file.transform;
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.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -406,12 +407,12 @@ class DefaultFieldSetTests {
@Test
void testEqualsNull() {
assertFalse(fieldSet.equals(null));
assertNotEquals(null, fieldSet);
}
@Test
void testEqualsNullTokens() {
assertFalse(new DefaultFieldSet(null).equals(fieldSet));
assertNotEquals(new DefaultFieldSet(null), fieldSet);
}
@Test
@@ -421,7 +422,7 @@ class DefaultFieldSetTests {
String[] tokens2 = new String[] { "token1", "token2" };
FieldSet fs1 = new DefaultFieldSet(tokens1);
FieldSet fs2 = new DefaultFieldSet(tokens2);
assertFalse(fs1.equals(fs2));
assertNotEquals(fs1, fs2);
}

View File

@@ -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.
@@ -20,7 +20,6 @@ import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
class DelimitedLineTokenizerTests {
@@ -32,29 +31,29 @@ class DelimitedLineTokenizerTests {
void testTokenizeRegularUse() {
FieldSet tokens = tokenizer.tokenize("sfd,\"Well,I have no idea what to do in the afternoon\",sFj, asdf,,as\n");
assertEquals(6, tokens.getFieldCount());
assertTrue(tokens.readString(0).equals("sfd"), TOKEN_MATCHES);
assertTrue(tokens.readString(1).equals("Well,I have no idea what to do in the afternoon"), TOKEN_MATCHES);
assertTrue(tokens.readString(2).equals("sFj"), TOKEN_MATCHES);
assertTrue(tokens.readString(3).equals("asdf"), TOKEN_MATCHES);
assertTrue(tokens.readString(4).equals(""), TOKEN_MATCHES);
assertTrue(tokens.readString(5).equals("as"), TOKEN_MATCHES);
assertEquals("sfd", tokens.readString(0), TOKEN_MATCHES);
assertEquals("Well,I have no idea what to do in the afternoon", tokens.readString(1), TOKEN_MATCHES);
assertEquals("sFj", tokens.readString(2), TOKEN_MATCHES);
assertEquals("asdf", tokens.readString(3), TOKEN_MATCHES);
assertEquals("", tokens.readString(4), TOKEN_MATCHES);
assertEquals("as", tokens.readString(5), TOKEN_MATCHES);
tokens = tokenizer.tokenize("First string,");
assertEquals(2, tokens.getFieldCount());
assertTrue(tokens.readString(0).equals("First string"), TOKEN_MATCHES);
assertTrue(tokens.readString(1).equals(""), TOKEN_MATCHES);
assertEquals("First string", tokens.readString(0), TOKEN_MATCHES);
assertEquals("", tokens.readString(1), TOKEN_MATCHES);
}
@Test
void testBlankString() {
FieldSet tokens = tokenizer.tokenize(" ");
assertTrue(tokens.readString(0).equals(""), TOKEN_MATCHES);
assertEquals("", tokens.readString(0), TOKEN_MATCHES);
}
@Test
void testEmptyString() {
FieldSet tokens = tokenizer.tokenize("\"\"");
assertTrue(tokens.readString(0).equals(""), TOKEN_MATCHES);
assertEquals("", tokens.readString(0), TOKEN_MATCHES);
}
@Test
@@ -93,8 +92,8 @@ class DelimitedLineTokenizerTests {
FieldSet tokens = tokenizer.tokenize("a,b,c");
assertTrue(tokens.readString(0).equals("a"), TOKEN_MATCHES);
assertTrue(tokens.readString(1).equals("b"), TOKEN_MATCHES);
assertEquals("a", tokens.readString(0), TOKEN_MATCHES);
assertEquals("b", tokens.readString(1), TOKEN_MATCHES);
}
@Test
@@ -118,11 +117,11 @@ class DelimitedLineTokenizerTests {
FieldSet tokens = tokenizer.tokenize("a,b,c");
assertTrue(tokens.readString(0).equals("a"), TOKEN_MATCHES);
assertTrue(tokens.readString(1).equals("b"), TOKEN_MATCHES);
assertTrue(tokens.readString(2).equals("c"), TOKEN_MATCHES);
assertTrue(tokens.readString(3).equals(""), TOKEN_MATCHES);
assertTrue(tokens.readString(4).equals(""), TOKEN_MATCHES);
assertEquals("a", tokens.readString(0), TOKEN_MATCHES);
assertEquals("b", tokens.readString(1), TOKEN_MATCHES);
assertEquals("c", tokens.readString(2), TOKEN_MATCHES);
assertEquals("", tokens.readString(3), TOKEN_MATCHES);
assertEquals("", tokens.readString(4), TOKEN_MATCHES);
}
@Test

View File

@@ -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.
@@ -25,7 +25,7 @@ import org.junit.jupiter.api.Test;
import org.springframework.core.AttributeAccessorSupport;
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.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -84,7 +84,7 @@ class SynchronizedAttributeAccessorTests {
Map<String, String> another = Collections.singletonMap("foo", "bar");
// Accessor and another are instances of unrelated classes, they should
// never be equal...
assertFalse(accessor.equals(another));
assertNotEquals(accessor, another);
}
@Test