Skip to content

Commit

Permalink
:fix: importing org.junit.Assert and explicitly referencing its metho…
Browse files Browse the repository at this point in the history
…ds instead of having test classes extend it

Signed-off-by: dseurotech <davide.salvador@eurotech.com>
  • Loading branch information
dseurotech authored and Coduz committed Oct 27, 2022
1 parent 91de06d commit c83ed31
Show file tree
Hide file tree
Showing 25 changed files with 405 additions and 384 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
import org.junit.Test;
import org.junit.experimental.categories.Category;


@Category(JUnitTests.class)
public class BrokerDomainTest extends Assert {
public class BrokerDomainTest {

BrokerDomain brokerDomain;
BrokerDomain secondBrokerDomain;
Expand All @@ -34,29 +35,29 @@ public void initialize() {

@Test
public void getNameTest() {
assertEquals("Expected and actual values should be the same.", "broker", brokerDomain.getName());
Assert.assertEquals("Expected and actual values should be the same.", "broker", brokerDomain.getName());
}

@Test
public void getActionsTest() {
assertEquals("Expected and actual values should be the same.", "[connect]", brokerDomain.getActions().toString());
Assert.assertEquals("Expected and actual values should be the same.", "[connect]", brokerDomain.getActions().toString());
}

@Test
public void getGroupableTest() {
assertFalse("False expected.", brokerDomain.getGroupable());
Assert.assertFalse("False expected.", brokerDomain.getGroupable());
}

@Test
public void equalsTest() {
assertTrue("True expected.", brokerDomain.equals(secondBrokerDomain));
Assert.assertTrue("True expected.", brokerDomain.equals(secondBrokerDomain));
for (Object object : objects) {
assertFalse("False expected.", brokerDomain.equals(object));
Assert.assertFalse("False expected.", brokerDomain.equals(object));
}
}

@Test
public void hashCodeTest() {
assertNotNull("NotNull expected.", brokerDomain.hashCode());
Assert.assertNotNull("NotNull expected.", brokerDomain.hashCode());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,21 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;


@Category(JUnitTests.class)
public class BrokerDomainsTest extends Assert {
public class BrokerDomainsTest {

@Test
public void brokerDomainsTest() throws Exception {
Constructor<BrokerDomains> brokerDomains = BrokerDomains.class.getDeclaredConstructor();
assertTrue("True expected.", Modifier.isPrivate(brokerDomains.getModifiers()));
Assert.assertTrue("True expected.", Modifier.isPrivate(brokerDomains.getModifiers()));
brokerDomains.setAccessible(true);
brokerDomains.newInstance();
}

@Test
public void brokerDomainTest() {
BrokerDomain brokerDomain = BrokerDomains.BROKER_DOMAIN;
assertNotNull("NotNull expected.", brokerDomain);
Assert.assertNotNull("NotNull expected.", brokerDomain);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;


@Category(JUnitTests.class)
public class CredentialsTest extends Assert {
public class CredentialsTest {

String specialSymbolsAndNumbers = "1234567890~!@$%^&*()_+, .?-/[];':<>";
String[] stringLengths = new String[]{"", "a", "abc", "qwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjqwer", "qwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjqwerqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjqwer"};
Expand All @@ -34,108 +35,108 @@ public void privateConstructorTest() throws NoSuchMethodException, IllegalAccess
Constructor<Credentials> credentialsConstructor = Credentials.class.getDeclaredConstructor();
credentialsConstructor.setAccessible(true);
Credentials credentials = credentialsConstructor.newInstance();
assertThat("Instance of Credentials.java expected", credentials, IsInstanceOf.instanceOf(Credentials.class));
Assert.assertThat("Instance of Credentials.java expected", credentials, IsInstanceOf.instanceOf(Credentials.class));
}

@Test
public void firstUserAndPasswordValidTest() {
UserAndPassword userAndPassword = Credentials.userAndPassword("username", "password");
assertEquals("Expected and actual values should be the same!", "username", userAndPassword.getUsername());
assertEquals("Expected and actual values should be the same!", "password", userAndPassword.getPasswordAsString());
assertNotNull("The value should not be null!", userAndPassword.getPassword());
Assert.assertEquals("Expected and actual values should be the same!", "username", userAndPassword.getUsername());
Assert.assertEquals("Expected and actual values should be the same!", "password", userAndPassword.getPasswordAsString());
Assert.assertNotNull("The value should not be null!", userAndPassword.getPassword());
}

@Test
public void firstUserAndPasswordAllNullTest() {
UserAndPassword userAndPassword = Credentials.userAndPassword(null, (String) null);
assertNull("Null expected!", userAndPassword.getUsername());
assertNull("Null expected!", userAndPassword.getPassword());
Assert.assertNull("Null expected!", userAndPassword.getUsername());
Assert.assertNull("Null expected!", userAndPassword.getPassword());
}

@Test
public void usernameNullTest() {
UserAndPassword userAndPassword = Credentials.userAndPassword(null, "password");
assertNull("Null expected!", userAndPassword.getUsername());
assertEquals("Expected and actual values should be the same!", "password", userAndPassword.getPasswordAsString());
assertNotNull("The value should not be null!", userAndPassword.getPassword());
Assert.assertNull("Null expected!", userAndPassword.getUsername());
Assert.assertEquals("Expected and actual values should be the same!", "password", userAndPassword.getPasswordAsString());
Assert.assertNotNull("The value should not be null!", userAndPassword.getPassword());
}

@Test
public void passwordNullTest() {
UserAndPassword userAndPassword = Credentials.userAndPassword("username", (String) null);
assertEquals("Expected and actual values should be the same!", "username", userAndPassword.getUsername());
assertNull("Null expected!", userAndPassword.getPassword());
assertNull("Null expected!", userAndPassword.getPasswordAsString());
Assert.assertEquals("Expected and actual values should be the same!", "username", userAndPassword.getUsername());
Assert.assertNull("Null expected!", userAndPassword.getPassword());
Assert.assertNull("Null expected!", userAndPassword.getPasswordAsString());

}

@Test
public void firstUserAndPasswordCharacterTest() {
for (int i=0; i<specialSymbolsAndNumbers.length(); i++) {
UserAndPassword userAndPassword = Credentials.userAndPassword("username" + specialSymbolsAndNumbers.charAt(i), "password" + specialSymbolsAndNumbers.charAt(i));
assertEquals("Expected and actual values should be the same!", "username" + specialSymbolsAndNumbers.charAt(i), userAndPassword.getUsername());
assertEquals("Expected and actual values should be the same!", "password" + specialSymbolsAndNumbers.charAt(i), userAndPassword.getPasswordAsString());
Assert.assertEquals("Expected and actual values should be the same!", "username" + specialSymbolsAndNumbers.charAt(i), userAndPassword.getUsername());
Assert.assertEquals("Expected and actual values should be the same!", "password" + specialSymbolsAndNumbers.charAt(i), userAndPassword.getPasswordAsString());
}
}

@Test
public void firstUserAndPasswordStringLengthTest() {
for(String value : stringLengths) {
UserAndPassword userAndPassword = Credentials.userAndPassword(value, value);
assertEquals("Expected and actual values should be the same!", value, userAndPassword.getUsername());
assertEquals("Expected and actual values should be the same!", value, userAndPassword.getPasswordAsString());
Assert.assertEquals("Expected and actual values should be the same!", value, userAndPassword.getUsername());
Assert.assertEquals("Expected and actual values should be the same!", value, userAndPassword.getPasswordAsString());
}
}

@Test
public void secondUserAndPasswordValidTest() {
UserAndPassword userAndPassword = Credentials.userAndPassword("user", "password".toCharArray());
assertEquals("Expected and actual values should be the same!", "user", userAndPassword.getUsername());
assertNotNull("The value should not be null!", userAndPassword.getPassword());
assertEquals("Expected and actual values should be the same!", "password", userAndPassword.getPasswordAsString());
Assert.assertEquals("Expected and actual values should be the same!", "user", userAndPassword.getUsername());
Assert.assertNotNull("The value should not be null!", userAndPassword.getPassword());
Assert.assertEquals("Expected and actual values should be the same!", "password", userAndPassword.getPasswordAsString());
}

@Test
public void secondUserAndPasswordAllNullTest() {
UserAndPassword userAndPassword = Credentials.userAndPassword(null, (char[]) null);
assertNull("Null expected!", userAndPassword.getUsername());
assertNull("Null expected!", userAndPassword.getPassword());
assertNull("Null expected!", userAndPassword.getPasswordAsString());
Assert.assertNull("Null expected!", userAndPassword.getUsername());
Assert.assertNull("Null expected!", userAndPassword.getPassword());
Assert.assertNull("Null expected!", userAndPassword.getPasswordAsString());
}

@Test
public void usernameNullTest2() {
UserAndPassword userAndPassword = Credentials.userAndPassword(null, "password".toCharArray());
assertNull("Null expected!", userAndPassword.getUsername());
assertNotNull("The value should not be null!", userAndPassword.getPassword());
assertEquals("Expected and actual values should be the same!", "password", userAndPassword.getPasswordAsString());
Assert.assertNull("Null expected!", userAndPassword.getUsername());
Assert.assertNotNull("The value should not be null!", userAndPassword.getPassword());
Assert.assertEquals("Expected and actual values should be the same!", "password", userAndPassword.getPasswordAsString());
}

@Test
public void passwordNullTest2() {
UserAndPassword userAndPassword = Credentials.userAndPassword("user", (char[]) null);
assertEquals("Expected and actual values should be the same!", "user", userAndPassword.getUsername());
assertNull("Null expected!", userAndPassword.getPassword());
assertNull("Null expected!", userAndPassword.getPasswordAsString());
Assert.assertEquals("Expected and actual values should be the same!", "user", userAndPassword.getUsername());
Assert.assertNull("Null expected!", userAndPassword.getPassword());
Assert.assertNull("Null expected!", userAndPassword.getPasswordAsString());
}

@Test
public void secondUserAndPasswordCharacterTest() {
for (int i=0; i<specialSymbolsAndNumbers.length(); i++) {
UserAndPassword userAndPassword = Credentials.userAndPassword("username" + specialSymbolsAndNumbers.charAt(i), "password".toCharArray());
assertEquals("Expected and actual values should be the same!", "username" + specialSymbolsAndNumbers.charAt(i), userAndPassword.getUsername());
assertEquals("Expected and actual values should be the same!", "password", userAndPassword.getPasswordAsString());
assertNotNull("The value should not be null!", userAndPassword.getPassword());
Assert.assertEquals("Expected and actual values should be the same!", "username" + specialSymbolsAndNumbers.charAt(i), userAndPassword.getUsername());
Assert.assertEquals("Expected and actual values should be the same!", "password", userAndPassword.getPasswordAsString());
Assert.assertNotNull("The value should not be null!", userAndPassword.getPassword());
}
}

@Test
public void secondUserAndPasswordCharacterLengthTest() {
for(String value : stringLengths) {
UserAndPassword userAndPassword = Credentials.userAndPassword(value, value.toCharArray());
assertEquals("Expected and actual values should be the same!", value, userAndPassword.getUsername());
assertEquals("Expected and actual values should be the same!", value, userAndPassword.getPasswordAsString());
assertNotNull("The value should not be null!", userAndPassword.getPassword());
Assert.assertEquals("Expected and actual values should be the same!", value, userAndPassword.getUsername());
Assert.assertEquals("Expected and actual values should be the same!", value, userAndPassword.getPasswordAsString());
Assert.assertNotNull("The value should not be null!", userAndPassword.getPassword());
}
}
}

0 comments on commit c83ed31

Please sign in to comment.