8000 Refactor tests by hajk1 · Pull Request #108 · arturmkrtchyan/iban4j · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Refactor tests #108

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

Merged
merged 28 commits into from
Jun 21, 2023
Merged
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
10000
20 changes: 17 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,35 @@
<maven.compiler.source>1.8</maven.compiler.source>
<jdk7Signature>java17</jdk7Signature>
<skipSigning>true</skipSigning>
<junit-jupiter.version>5.9.2</junit-jupiter.version>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<artifactId>junit-jupiter-params</artifactId>
<groupId>org.junit.jupiter</groupId>
<scope>test</scope>
<version>${junit-jupiter.version}</version>
</dependency>
<dependency>
<groupId>com.carrotsearch</groupId>
<artifactId>junit-benchmarks</artifactId>
<version>0.7.2</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hamcrest/hamcrest -->
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<distributionManagement>
Expand Down
23 changes: 23 additions & 0 deletions src/test/java/org/iban4j/BicCreationTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.iban4j;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

import java.util.Collection;

public class BicCreationTest {

public static Collection<Object[]> bicParameters() {
return TestDataHelper.getBicData();
}

@DisplayName("Test bicConstructionWithValueOfShouldReturnBic")
@ParameterizedTest(name = "{index} ==> the bic string ''{0}''")
@MethodSource("bicParameters")
public void bicConstructionWithValueOfShouldReturnBic(String bicString) {
Assertions.assertNotNull(Bic.valueOf(bicString));
}

}
77 changes: 22 additions & 55 deletions src/test/java/org/iban4j/BicTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,128 +15,95 @@
*/
package org.iban4j;

import org.junit.Test;
import org.junit.experimental.runners.Enclosed;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import java.util.Collection;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;

import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertThat;

@RunWith(Enclosed.class)
@DisplayName("BIC Test class")
public class BicTest {

public static class BicCreationTest1 {
@Nested
public class BicCreationTest {

@Test(expected = UnsupportedCountryException.class)
@Test
@DisplayName("Invalid country code")
public void bicConstructionWithInvalidCountryCodeShouldThrowException() {
Bic.valueOf("DEUTAAFF500");

Assertions.assertThrows(UnsupportedCountryException.class,()->Bic.valueOf("DEUTAAFF500"));
}

@Test
public void bicsWithSameDataShouldBeEqual() {
Bic bic1 = Bic.valueOf("DEUTDEFF500");
Bic bic2 = Bic.valueOf("DEUTDEFF500");

assertThat(bic1, is(equalTo(bic2)));
Assertions.assertEquals(bic1, bic2);
}

@Test
public void bicsWithDifferentDataShouldNotBeEqual() {
Bic bic1 = Bic.valueOf("DEUTDEFF500");
Bic bic2 = Bic.valueOf("DEUTDEFF501");

assertThat(bic1, is(not(equalTo(bic2))));
Assertions.assertNotEquals(bic1, bic2);
}

@Test
public void bicsWithStringValueAndBicShouldNotBeEqual() {
Bic bic = Bic.valueOf("DEUTDEFF500");

assertNotEquals(bic, "DEUTDEFF500");
Assertions.assertNotEquals(bic, "DEUTDEFF500");
}

@Test
public void bicsWithSameDataShouldHaveSameHashCode() {
Bic bic1 = Bic.valueOf("DEUTDEFF500");
Bic bic2 = Bic.valueOf("DEUTDEFF500");
Assertions.assertEquals(bic1.hashCode(), bic2.hashCode());

assertThat(bic1.hashCode(), is(equalTo(bic2.hashCode())));
}

@Test
public void bicsWithDifferentDataShouldNotHaveSameHashCode() {
Bic bic1 = Bic.valueOf("DEUTDEFF500");
Bic bic2 = Bic.valueOf("DEUTDEFF501");

assertThat(bic1.hashCode(), is(not(equalTo(bic2.hashCode()))));
Assertions.assertNotEquals(bic1.hashCode(), bic2.hashCode());
}

@Test
public void bicShouldReturnBankCode() {
Bic bic = Bic.valueOf("DEUTDEFF500");

assertThat(bic.getBankCode(), is(equalTo("DEUT")));
Assertions.assertEquals(bic.getBankCode(),"DEUT");
}

@Test
public void bicShouldReturnCountryCode() {
Bic bic = Bic.valueOf("DEUTDEFF500");

assertThat(bic.getCountryCode(), is(equalTo(CountryCode.DE)));
Assertions.assertEquals(bic.getCountryCode(), CountryCode.DE);
}

@Test
public void bicShouldReturnBranchCode() {
Bic bic = Bic.valueOf("DEUTDEFF500");

assertThat(bic.getBranchCode(), is(equalTo("500")));
Assertions.assertEquals(bic.getBranchCode(), "500");
}

@Test
public void bicWithoutBrnachCodeShouldReturnNull() {
Bic bic = Bic.valueOf("DEUTDEFF");

assertThat(bic.getBranchCode(), is(equalTo(null)));
Assertions.assertNull(bic.getBranchCode());
}

@Test
public void bicShouldReturnLocationCode() {
Bic bic = Bic.valueOf("DEUTDEFF500");

assertThat(bic.getLocationCode(), is(equalTo("FF")));
Assertions.assertEquals(bic.getLocationCode(), "FF");
}

@Test
public void bicToStringShouldReturnString() {
Bic bic = Bic.valueOf("DEUTDEFF500");

assertThat(bic.toString(), is(equalTo("DEUTDEFF500")));
}
}

@RunWith(Parameterized.class)
public static class BicCreationTest2 {

private final String bicString;

public BicCreationTest2(String bicString) {
this.bicString = bicString;
Assertions.assertEquals(bic.toString(), "DEUTDEFF500");
}

@Test
public void bicConstructionWithValueOfShouldReturnBic() {
assertThat(Bic.valueOf(bicString), is(notNullValue()));
}

@Parameterized.Parameters
public static Collection<Object[]> bicParameters() {
return TestDataHelper.getBicData();
}

}

}
99 changes: 59 additions & 40 deletions src/test/java/org/iban4j/BicUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,91 +15,110 @@
*/
package org.iban4j;

import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.runners.Enclosed;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

@RunWith(Enclosed.class)

@DisplayName("BIC Util Test class")
public class BicUtilTest {

public static class InvalidBicValidationTest {

@Rule
public ExpectedException expectedException = ExpectedException.none();

String defaultExceptionMessage ="Expected doThing() to throw, but it didn't";

@Test
public void bicValidationWithNullShouldThrowException() {
expectedException.expect(BicFormatException.class);
expectedException.expectMessage(containsString("Null can't be a valid Bic"));
BicUtil.validate(null);
BicFormatException thrown = assertThrows(
BicFormatException.class,
() -> BicUtil.validate(null),
defaultExceptionMessage);
assertThat(thrown.getMessage(), containsString("Null can't be a valid Bic"));
}

@Test
public void bicValidationWithEmptyStringShouldThrowException() {
expectedException.expect(BicFormatException.class);
expectedException.expectMessage(containsString("Empty string can't be a valid Bic"));
BicUtil.validate("");
BicFormatException thrown = assertThrows(
BicFormatException.class,
() -> BicUtil.validate(""),
defaultExceptionMessage);
assertThat(thrown.getMessage(), containsString("Empty string can't be a valid Bic"));
}

@Test
public void bicValidationWithLessCharactersShouldThrowException() {
expectedException.expect(BicFormatException.class);
expectedException.expectMessage(containsString("Bic length must be 8 or 11"));
BicUtil.validate("DEUTFF");
BicFormatException thrown = assertThrows(
BicFormatException.class,
() -> BicUtil.validate("DEUTFF"),
defaultExceptionMessage);
assertEquals("Bic length must be 8 or 11", thrown.getMessage());
}

@Test
public void bicValidationWithMoreCharactersShouldThrowException() {
expectedException.expect(BicFormatException.class);
expectedException.expectMessage(containsString("Bic length must be 8 or 11"));
BicUtil.validate("DEUTFFDEUTFF");
BicFormatException thrown = assertThrows(
BicFormatException.class,
() -> BicUtil.validate("DEUTFFDEUTFF"),
defaultExceptionMessage);
assertEquals("Bic length must be 8 or 11", thrown.getMessage());
}

@Test
public void bicValidationWithLowercaseShouldThrowException() {
expectedException.expect(BicFormatException.class);
expectedException.expectMessage(containsString("Bic must contain only upper case letters"));
BicUtil.validate("DEUTdeFF");
BicFormatException thrown = assertThrows(
BicFormatException.class,
() -> BicUtil.validate("DEUTdeFF"),
defaultExceptionMessage);
assertThat(thrown.getMessage(), containsString("Bic must contain only upper case letters"));
}

@Test
public void bicValidationWithInvalidBankCodeShouldThrowException() {
expectedException.expect(BicFormatException.class);
expectedException.expectMessage(containsString("Bank code must contain only letters"));
BicUtil.validate("DEU1DEFF");
BicFormatException thrown = assertThrows(
BicFormatException.class,
() -> BicUtil.validate("DEU1DEFF"),
defaultExceptionMessage);
assertThat(thrown.getMessage(), containsString("Bank code must contain only letters"));
}

@Test
public void bicValidationWithNonExistingCountryCodeShouldThrowException() {
expectedException.expect(UnsupportedCountryException.class);
expectedException.expectMessage(containsString("Country code is not supported"));
BicUtil.validate("DEUTDDFF");
UnsupportedCountryException thrown = assertThrows(
UnsupportedCountryException.class,
() -> BicUtil.validate("DEUTDDFF"),
defaultExceptionMessage);
assertThat(thrown.getMessage(), containsString("Country code is not supported"));
}

@Test
public void bicValidationWithInvalidCountryCodeShouldThrowException() {
expectedException.expect(BicFormatException.class);
expectedException.expectMessage(containsString("Bic country code must contain upper case letters"));
BicUtil.validate("DEUT_1FF");
BicFormatException thrown = assertThrows(
BicFormatException.class,
() -> BicUtil.validate("DEUT_1FF"),
defaultExceptionMessage);
assertEquals("Bic country code must contain upper case letters", thrown.getMessage());
}

@Test
public void bicValidationWithInvalidLocationCodeShouldThrowException() {
expectedException.expect(BicFormatException.class);
expectedException.expectMessage(containsString("Location code must contain only letters or digits"));
BicUtil.validate("DEUTDEF ");
BicFormatException thrown = assertThrows(
BicFormatException.class,
() -> BicUtil.validate("DEUTDEF "),
defaultExceptionMessage);
assertThat(thrown.getMessage(), containsString("Location code must contain only letters or digits"));
}

@Test
public void bicValidationWithInvalidBranchCodeShouldThrowException() {
expectedException.expect(BicFormatException.class);
expectedException.expectMessage(containsString("Branch code must contain only letters or digits"));
BicUtil.validate("DEUTDEFF50_");
BicFormatException thrown = assertThrows(
BicFormatException.class,
() -> BicUtil.validate("DEUTDEFF50_"),
defaultExceptionMessage);
assertThat(thrown.getMessage(), containsString("Branch code must contain only letters or digits"));
}
}

Expand Down
Loading
0