本文整理匯總了Java中org.junit.jupiter.api.Assertions.fail方法的典型用法代碼示例。如果您正苦於以下問題:Java Assertions.fail方法的具體用法?Java Assertions.fail怎麽用?Java Assertions.fail使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.junit.jupiter.api.Assertions
的用法示例。
在下文中一共展示了Assertions.fail方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: invalidCases
import org.junit.jupiter.api.Assertions; //導入方法依賴的package包/類
@Test
void invalidCases() {
assertThrows(IllegalArgumentException.class, () -> TimeUtils.abbreviate(null));
@NotNull Class<?> clazz = TimeUtils.class;
try {
Constructor constructor = clazz.getDeclaredConstructor();
assertTrue(Modifier.isPrivate(constructor.getModifiers()));
constructor.setAccessible(true);
try {
constructor.newInstance();
Assertions.fail("Private constructor should throw exception");
} catch (InvocationTargetException t) {
assertTrue(t.getTargetException() instanceof Error);
}
constructor.setAccessible(false);
} catch (Exception e) {
Assert.fail("No defaultConstructor");
}
}
示例2: testEncoder
import org.junit.jupiter.api.Assertions; //導入方法依賴的package包/類
@Test
void testEncoder() {
QppOutputEncoder encoder = new QppOutputEncoder(new Context());
encoder.setNodes(nodes);
StringWriter sw = new StringWriter();
try {
encoder.encode(new BufferedWriter(sw));
} catch (EncodeException e) {
Assertions.fail("Failure to encode: " + e.getMessage());
}
assertThat(sw.toString())
.isEqualTo(EXPECTED);
}
示例3: testEncoderWithoutMeasure
import org.junit.jupiter.api.Assertions; //導入方法依賴的package包/類
@Test
void testEncoderWithoutMeasure() {
iaSectionNode.getChildNodes().remove(iaMeasureNode);
QppOutputEncoder encoder = new QppOutputEncoder(new Context());
encoder.setNodes(nodes);
StringWriter sw = new StringWriter();
try {
encoder.encode(new BufferedWriter(sw));
} catch (EncodeException e) {
Assertions.fail("Failure to encode: " + e.getMessage());
}
assertThat(sw.toString())
.isEqualTo(EXPECTED_NO_MEASURE);
}
示例4: testEncoderWithoutMeasureValue1
import org.junit.jupiter.api.Assertions; //導入方法依賴的package包/類
@Test
void testEncoderWithoutMeasureValue1() {
iaMeasureNode.getChildNodes().remove(iaMeasurePerformedNode);
QppOutputEncoder encoder = new QppOutputEncoder(new Context());
encoder.setNodes(nodes);
StringWriter sw = new StringWriter();
try {
encoder.encode(new BufferedWriter(sw));
} catch (EncodeException e) {
Assertions.fail("Failure to encode: " + e.getMessage());
}
assertThat(sw.toString())
.isEqualTo(EXPECTED_NO_MEASURE_VALUE_1);
}
示例5: testEncoderWithoutMeasureValue2
import org.junit.jupiter.api.Assertions; //導入方法依賴的package包/類
@Test
void testEncoderWithoutMeasureValue2() {
iaMeasurePerformedNode.putValue("measurePerformed", null);
QppOutputEncoder encoder = new QppOutputEncoder(new Context());
encoder.setNodes(nodes);
StringWriter sw = new StringWriter();
try {
encoder.encode(new BufferedWriter(sw));
} catch (EncodeException e) {
Assertions.fail("Failure to encode: " + e.getMessage());
}
assertThat(sw.toString())
.isEqualTo(EXPECTED_NO_MEASURE_VALUE_1);
}
示例6: enableDatabaseMySQLTest
import org.junit.jupiter.api.Assertions; //導入方法依賴的package包/類
@Test
public void enableDatabaseMySQLTest() {
try {
final DB database = DB.newEmbeddedDB(3306);
database.start();
try (Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/?user=root&password=")) {
try (Statement statement = conn.createStatement()) {
statement.executeUpdate("CREATE DATABASE db");
}
}
final HikariConfig config = new HikariConfig();
config.setDriverClassName("com.mysql.jdbc.Driver");
config.setConnectionTestQuery("SELECT 1");
config.setJdbcUrl("jdbc:mysql://localhost:3306/db");
config.setMaxLifetime(60000);
config.setIdleTimeout(45000);
config.setMaximumPoolSize(50);
final HikariDataSource ds = new HikariDataSource(config);
ds.close();
database.stop();
} catch (final Exception ex) {
Logger.getLogger(this.getClass().getSimpleName()).log(Level.WARNING, "Failed to enable database.", ex);
Assertions.fail(ex);
}
}
示例7: testEncoderWithFramework
import org.junit.jupiter.api.Assertions; //導入方法依賴的package包/類
/**
* Test Function for the QppOutputEncoder
*/
@Test
void testEncoderWithFramework() {
QppOutputEncoder encoder = new QppOutputEncoder(new Context());
encoder.setNodes(nodes);
StringWriter sw = new StringWriter();
try {
encoder.encode(new BufferedWriter(sw));
} catch (EncodeException e) {
Assertions.fail("Failure to encode: " + e.getMessage());
}
// NOTE: This test is only relevant in that it finds the deep value but it is not actually a result
String expected = "{\n \"value\" : 600\n}";
assertThat(sw.toString())
.isEqualTo(expected);
}
示例8: testEncoder
import org.junit.jupiter.api.Assertions; //導入方法依賴的package包/類
@Test
@SuppressWarnings("unchecked")
void testEncoder() throws IOException {
QppOutputEncoder encoder = new QppOutputEncoder(new Context());
encoder.setNodes(nodes);
StringWriter sw = new StringWriter();
try {
encoder.encode(new BufferedWriter(sw));
} catch (EncodeException e) {
Assertions.fail("Failure to encode: " + e.getMessage());
}
Map<String, Object> content = JsonHelper.readJson(new ByteArrayInputStream(sw.toString().getBytes()), Map.class);
assertThat(content.get("measureId"))
.isEqualTo(MEASURE_ID);
assertThat(content.get("value"))
.isEqualTo(true);
}
示例9: enableDatabaseSQLiteTest
import org.junit.jupiter.api.Assertions; //導入方法依賴的package包/類
@Test
public void enableDatabaseSQLiteTest() {
try {
final HikariConfig config = new HikariConfig();
config.setDriverClassName("org.sqlite.JDBC");
config.setConnectionTestQuery("SELECT 1");
config.setJdbcUrl("jdbc:sqlite:PetBlocks.db");
config.setMaxLifetime(60000);
config.setIdleTimeout(45000);
config.setMaximumPoolSize(50);
final HikariDataSource ds = new HikariDataSource(config);
ds.close();
} catch (final Exception ex) {
Logger.getLogger(this.getClass().getSimpleName()).log(Level.WARNING, "Failed to enable database.", ex);
Assertions.fail(ex);
}
}
示例10: storeLoadPlayerMetaTest
import org.junit.jupiter.api.Assertions; //導入方法依賴的package包/類
@Test
public void storeLoadPlayerMetaTest() throws ClassNotFoundException {
Factory.initialize(mockPlugin());
try (PlayerMetaController controller = Factory.createPlayerDataController()) {
for (final PlayerMeta item : controller.getAll()) {
controller.remove(item);
}
UUID uuid = UUID.randomUUID();
PlayerMeta playerMeta = new PlayerData();
playerMeta.setName("Second");
playerMeta.setUuid(uuid);
controller.store(playerMeta);
assertEquals(1, controller.size());
playerMeta = controller.getAll().get(0);
assertEquals(uuid, playerMeta.getUUID());
assertEquals("Second", playerMeta.getName());
uuid = UUID.randomUUID();
playerMeta.setName("Shynixn");
playerMeta.setUuid(uuid);
controller.store(playerMeta);
playerMeta = controller.getAll().get(0);
assertEquals(uuid, playerMeta.getUUID());
assertEquals("Shynixn", playerMeta.getName());
} catch (final Exception e) {
Logger.getLogger(this.getClass().getSimpleName()).log(Level.WARNING, "Failed to run test.", e);
Assertions.fail(e);
}
}
示例11: testRegistryExistsByDefault
import org.junit.jupiter.api.Assertions; //導入方法依賴的package包/類
@Test
void testRegistryExistsByDefault() {
try {
registry.register(new ComponentKey(TemplateId.PLACEHOLDER, Program.ALL), Placeholder.class);
} catch (NullPointerException e) {
Assertions.fail("Registry should always exist.");
}
}
示例12: executeInternalEncode
import org.junit.jupiter.api.Assertions; //導入方法依賴的package包/類
private void executeInternalEncode() {
qualityMeasureId.addChildNodes(populationNode, denomExclusionNode, numeratorNode, denominatorNode);
try {
encoder.internalEncode(wrapper, qualityMeasureId);
} catch (EncodeException e) {
Assertions.fail("Failure to encode: " + e.getMessage());
}
}
示例13: insertSelectStatsTest
import org.junit.jupiter.api.Assertions; //導入方法依賴的package包/類
@Test
public void insertSelectStatsTest() throws ClassNotFoundException {
Factory.initialize(mockPlugin());
final UUID uuid = UUID.randomUUID();
final Player player = mock(Player.class);
when(player.getName()).thenReturn("Shynixn");
when(player.getUniqueId()).thenReturn(uuid);
try (StatsController controller = Factory.createStatsController()) {
try (PlayerMetaController playerController = Factory.createPlayerDataController()) {
for (final Stats item : controller.getAll()) {
controller.remove(item);
}
final Stats meta = controller.create();
controller.store(meta);
assertEquals(0, controller.size());
final PlayerMeta playerMeta = playerController.create(player);
playerController.store(playerMeta);
meta.setPlayerId(playerMeta.getId());
meta.setAmountOfWins(2);
controller.store(meta);
assertEquals(0, controller.size());
meta.setAmountOfGamesPlayed(2);
controller.store(meta);
assertEquals(1, controller.size());
assertEquals(2, controller.getByPlayer(player).getAmountOfWins());
}
} catch (final Exception e) {
Logger.getLogger(this.getClass().getSimpleName()).log(Level.WARNING, "Failed to run test.", e);
Assertions.fail(e);
}
}
示例14: storeLoadPetMetaTest
import org.junit.jupiter.api.Assertions; //導入方法依賴的package包/類
@Test
public void storeLoadPetMetaTest() throws ClassNotFoundException {
Factory.initialize(mockPlugin());
final UUID uuid = UUID.randomUUID();
final Player player = mock(Player.class);
when(player.getName()).thenReturn("Shynixn");
when(player.getUniqueId()).thenReturn(uuid);
try (StatsController controller = Factory.createStatsController()) {
try (PlayerMetaController playerController = Factory.createPlayerDataController()) {
for (final Stats item : controller.getAll()) {
controller.remove(item);
}
Stats stats = controller.create();
final PlayerMeta playerMeta = playerController.create(player);
playerController.store(playerMeta);
stats.setPlayerId(playerMeta.getId());
stats.setAmountOfGamesPlayed(5);
stats.setAmountOfWins(2);
stats.setAmountOfGoals(20);
controller.store(stats);
stats = controller.getByPlayer(player);
assertEquals(5, stats.getAmountOfGamesPlayed());
assertEquals(2, stats.getAmountOfWins());
assertEquals(20, stats.getAmountOfGoals());
assertEquals(4, stats.getGoalsPerGame());
assertEquals(0.4, stats.getWinRate());
}
} catch (final Exception e) {
Logger.getLogger(this.getClass().getSimpleName()).log(Level.WARNING, "Failed to run test.", e);
Assertions.fail(e);
}
}
示例15: testEncoder
import org.junit.jupiter.api.Assertions; //導入方法依賴的package包/類
/**
* Test Function for the AggregateCountEncode
*/
@Test
void testEncoder() {
AggregateCountEncoder encoder = new AggregateCountEncoder(new Context());
encoder.setNodes(nodes);
JsonWrapper json = new JsonWrapper();
try {
encoder.internalEncode(json, numeratorDenominatorNode);
} catch (EncodeException e) {
Assertions.fail("Failure to encode: " + e.getMessage());
}
assertThat(json.getInteger("value"))
.isEqualTo(600);
}