From 4f1cdf5208884fc46a4cbac01f266385d4b02f19 Mon Sep 17 00:00:00 2001 From: YuCheng Hu Date: Mon, 6 Jun 2022 14:30:33 -0400 Subject: [PATCH] =?UTF-8?q?Java=208=20AssertJ=20=E7=9A=84=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=EF=BC=88Exception=20=EF=BC=89=E6=96=AD=E8=A8=80=20htt?= =?UTF-8?q?ps://www.ossez.com/t/assertj-exception/13988?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../foramt/NumberFormatExceptionTest.java | 24 ++++++++++++------- testing-modules/assertion-libraries/README.md | 2 +- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/core-java-modules/core-java-numbers/src/test/java/com/ossez/number/foramt/NumberFormatExceptionTest.java b/core-java-modules/core-java-numbers/src/test/java/com/ossez/number/foramt/NumberFormatExceptionTest.java index 8c50e792df..0a7cb69643 100644 --- a/core-java-modules/core-java-numbers/src/test/java/com/ossez/number/foramt/NumberFormatExceptionTest.java +++ b/core-java-modules/core-java-numbers/src/test/java/com/ossez/number/foramt/NumberFormatExceptionTest.java @@ -2,13 +2,14 @@ package com.ossez.number.foramt; import org.apache.commons.lang3.math.NumberUtils; +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; import java.util.Arrays; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertThrows; /** @@ -26,20 +27,25 @@ public class NumberFormatExceptionTest { @Test public void ConstructorNumberFormatException() { -// Exception exception = assertThrows(NumberFormatException.class, () -> { -// new Integer("one"); -// }); +// JUNIT 5 Assert + Exception exception = assertThrows(NumberFormatException.class, () -> { + new Integer("one"); + }); + System.out.println(exception); - assertThatThrownBy(() -> { +// AssertJ assertThatThrownBy + assertThatThrownBy(() -> { new Integer("one"); }).isInstanceOf(NumberFormatException.class).hasMessageStartingWith("For input string"); -// System.out.println(exception); + // AssertJ assertThatExceptionOfType + assertThatExceptionOfType(NumberFormatException.class).isThrownBy(() -> { + new Integer("one"); + }); - Integer aIntegerObj = new Integer("1"); // Integer aIntegerObj = new Integer("one"); - Double doubleDecimalObj = new Double("two.2"); +// Double doubleDecimalObj = new Double("two.2"); } diff --git a/testing-modules/assertion-libraries/README.md b/testing-modules/assertion-libraries/README.md index d055e3a074..0f45125ac2 100644 --- a/testing-modules/assertion-libraries/README.md +++ b/testing-modules/assertion-libraries/README.md @@ -17,4 +17,4 @@ - [Guide to JSpec](http://www.baeldung.com/jspec) - [Custom Assertions with AssertJ](http://www.baeldung.com/assertj-custom-assertion) - [Using Conditions with AssertJ Assertions](http://www.baeldung.com/assertj-conditions) -- [AssertJ Exception Assertions](http://www.baeldung.com/assertj-exception-assertion) +- [AssertJ 的异常(Exception )断言](https://www.ossez.com/t/assertj-exception/13988)