tak też testowałem, ale teraz chciałem przetestować szyfrowanie pesela:
@Entity
public abstract class Employee {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@PESEL
@Transient
private final String pesel; // TODO encrypt and validate
@Column(unique = true, updatable = false)
public final String peselEncrypted; // TODO encrypt and validate
public Employee(String pesel) {
this.pesel = pesel;
this.peselEncrypted = HashMD5.getHashed(pesel);
}
// ...
public class EncryptingTest {
PESELValidator peselValidator;
@Before
public void onStart2() {
this.peselValidator = new PESELValidator();
peselValidator.initialize(null);
}
@Test
public void testEncryptingPesel() {
// given
CharSequence validPesel = "94092367705";
// when
Employee emp = new Shipper(validPesel.toString());
// then
assertTrue(peselValidator.isValid(validPesel, null));
assertTrue(!peselValidator.isValid(emp.peselEncrypted, null));
}
}