refactor: use AssertJ for testing
Majority of our test cases use AssertJ
This commit is contained in:
parent
ac7a9c7863
commit
87edc7d1db
@ -23,8 +23,7 @@
|
||||
|
||||
package org.owasp.webgoat.lessons.challenges.challenge7;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import java.util.stream.Stream;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
@ -37,7 +36,7 @@ public class MD5Test {
|
||||
@DisplayName("MD5 test")
|
||||
@MethodSource("providedForMD5Values")
|
||||
void testMD5(String in, String out) {
|
||||
assertEquals(MD5.getHashString(in.getBytes()), out);
|
||||
assertThat(out).isEqualTo(MD5.getHashString(in.getBytes()));
|
||||
}
|
||||
|
||||
private static Stream<Arguments> providedForMD5Values() {
|
||||
|
@ -1,7 +1,7 @@
|
||||
package org.owasp.webgoat.lessons.cryptography;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
import java.security.KeyPair;
|
||||
import java.security.PrivateKey;
|
||||
@ -23,11 +23,9 @@ public class CryptoUtilTest {
|
||||
String modulus = DatatypeConverter.printHexBinary(rsaPubKey.getModulus().toByteArray());
|
||||
String signature = CryptoUtil.signMessage(modulus, privateKey);
|
||||
log.debug("public exponent {}", rsaPubKey.getPublicExponent());
|
||||
assertTrue(CryptoUtil.verifyAssignment(modulus, signature, keyPair.getPublic()));
|
||||
assertThat(CryptoUtil.verifyAssignment(modulus, signature, keyPair.getPublic())).isTrue();
|
||||
} catch (Exception e) {
|
||||
log.error("signing failed", e);
|
||||
;
|
||||
fail();
|
||||
fail("Signing failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,11 +22,9 @@
|
||||
|
||||
package org.owasp.webgoat.lessons.spoofcookie.encoders;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@ -48,7 +46,7 @@ class EncDecTest {
|
||||
void testEncode(String decoded, String encoded) {
|
||||
String result = EncDec.encode(decoded);
|
||||
|
||||
assertTrue(result.endsWith(encoded));
|
||||
assertThat(result.endsWith(encoded)).isTrue();
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ -63,13 +61,13 @@ class EncDecTest {
|
||||
@Test
|
||||
@DisplayName("null encode test")
|
||||
void testNullEncode() {
|
||||
assertNull(EncDec.encode(null));
|
||||
assertThat(EncDec.encode(null)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("null decode test")
|
||||
void testNullDecode() {
|
||||
assertNull(EncDec.decode(null));
|
||||
assertThat(EncDec.decode(null)).isNull();
|
||||
}
|
||||
|
||||
private static Stream<Arguments> providedForEncValues() {
|
||||
|
@ -22,10 +22,8 @@
|
||||
|
||||
package org.owasp.webgoat.lessons.vulnerablecomponents;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import com.thoughtworks.xstream.XStream;
|
||||
import com.thoughtworks.xstream.io.StreamException;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
@ -53,7 +51,7 @@ public class VulnerableComponentsLessonTest {
|
||||
xstream.setClassLoader(Contact.class.getClassLoader());
|
||||
xstream.alias("contact", ContactImpl.class);
|
||||
xstream.ignoreUnknownElements();
|
||||
assertNotNull(xstream.fromXML(contact));
|
||||
assertThat(xstream.fromXML(contact)).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -67,7 +65,7 @@ public class VulnerableComponentsLessonTest {
|
||||
assertThrows(
|
||||
RuntimeException.class,
|
||||
() -> ((Contact) xstream.fromXML(strangeContact)).getFirstName());
|
||||
assertTrue(e.getCause().getMessage().contains("calc.exe"));
|
||||
assertThat(e.getCause().getMessage().contains("calc.exe")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -79,6 +77,6 @@ public class VulnerableComponentsLessonTest {
|
||||
Exception e =
|
||||
assertThrows(
|
||||
StreamException.class, () -> ((Contact) xstream.fromXML("bullssjfs")).getFirstName());
|
||||
assertTrue(e.getCause().getMessage().contains("START_DOCUMENT"));
|
||||
assertThat(e.getCause().getMessage().contains("START_DOCUMENT")).isTrue();
|
||||
}
|
||||
}
|
||||
|
@ -22,8 +22,7 @@
|
||||
|
||||
package org.owasp.webgoat.webwolf.mailbox;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@ -58,6 +57,6 @@ public class MailboxRepositoryTest {
|
||||
|
||||
List<Email> emails = mailboxRepository.findByRecipientOrderByTimeDesc("someone@webwolf.org");
|
||||
|
||||
assertEquals(emails.size(), 1);
|
||||
assertThat(emails.size()).isEqualTo(1);
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@
|
||||
|
||||
package org.owasp.webgoat.webwolf.user;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@ -62,7 +62,7 @@ public class UserServiceTest {
|
||||
|
||||
when(mockUserRepository.findByUsername(username)).thenReturn(null);
|
||||
|
||||
assertThrows(UsernameNotFoundException.class, () -> sut.loadUserByUsername(username));
|
||||
assertThatExceptionOfType(UsernameNotFoundException.class).isThrownBy(() -> sut.loadUserByUsername(username));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
x
Reference in New Issue
Block a user