本文整理匯總了Java中org.junit.jupiter.api.DisplayName類的典型用法代碼示例。如果您正苦於以下問題:Java DisplayName類的具體用法?Java DisplayName怎麽用?Java DisplayName使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
DisplayName類屬於org.junit.jupiter.api包,在下文中一共展示了DisplayName類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: updateGreeting
import org.junit.jupiter.api.DisplayName; //導入依賴的package包/類
@Test
@DisplayName("Updating a greeting should work")
void updateGreeting() {
// Given we have a greeting already saved
GreetingDto savedGreeting = service.createGreeting(createGreetingDto("We come in peace!"));
Assumptions.assumeTrue(savedGreeting != null);
// When we update it
savedGreeting.setMessage("Updated message");
service.updateGreetingWithId(savedGreeting.getId(), savedGreeting);
// Then it should be updated
Optional<GreetingDto> updatedGreetingOptional = service.findGreetingById(savedGreeting.getId());
Assertions.assertAll("Updating a greeting by id should work",
() -> assertTrue(updatedGreetingOptional.isPresent(), "Could not find greeting by id"),
() -> assertEquals(savedGreeting.getId(), updatedGreetingOptional.get().getId(), "Updated greeting has invalid id"),
() -> assertEquals("Updated message", updatedGreetingOptional.get().getMessage(), "Updated greeting has different message from the expected updated one"));
}
示例2: paramMatcher
import org.junit.jupiter.api.DisplayName; //導入依賴的package包/類
/**
* Methods inherited from class org.mockito.ArgumentMatchers
* any, any, anyBoolean, anyByte, anyChar, anyCollection, anyCollectionOf, anyDouble, anyFloat,
* anyInt, anyIterable, anyIterableOf, anyList, anyListOf, anyLong, anyMap, anyMapOf, anyObject,
* anySet, anySetOf, anyShort, anyString, anyVararg, argThat, booleanThat, byteThat, charThat,
* contains, doubleThat, endsWith, eq, eq, eq, eq, eq, eq, eq, eq, eq, floatThat, intThat, isA,
* isNotNull, isNotNull, isNull, isNull, longThat, matches, matches, notNull, notNull, nullable,
* refEq, same, shortThat, startsWith
*/
@Test
@DisplayName("參數匹配器")
void paramMatcher(){
//You can mock concrete classes, not just interfaces
LinkedList mockedList = mock(LinkedList.class);
//stubbing
// when(mockedList.get(1)).thenThrow(new RuntimeException());
when(mockedList.get(anyInt())).thenReturn("first");
System.out.println(mockedList.get(0));
System.out.println(mockedList.get(1));
}
示例3: postLocationTest
import org.junit.jupiter.api.DisplayName; //導入依賴的package包/類
@Test
@DisplayName("post location")
void postLocationTest() {
final LocationResponse response = post(
builder -> builder.path(LOCATION_PATH).build(),
new LocationRequest(GOOGLE_ADDRESS),
LocationResponse.class);
assertThat(response.getGeographicCoordinates(), not(nullValue()));
assertThat(response.getGeographicCoordinates().getLatitude(), not(nullValue()));
assertThat(response.getGeographicCoordinates().getLongitude(), not(nullValue()));
assertThat(response.getSunriseSunset(), not(nullValue()));
assertThat(response.getSunriseSunset().getSunrise(), not(isEmptyOrNullString()));
assertThat(response.getSunriseSunset().getSunset(), not(isEmptyOrNullString()));
}
示例4: runForComplexCase
import org.junit.jupiter.api.DisplayName; //導入依賴的package包/類
@Test
@DisplayName("Complex request with level of assurance 2")
public void runForComplexCase() throws Exception {
String jsonString = fileUtils.readFromResources("LoA2-extensive-case.json")
.replace("%yesterdayDate%", Instant.now().minus(1, DAYS).toString())
.replace("%within405days-100days%", Instant.now().minus(100, DAYS).toString())
.replace("%within405days-101days%", Instant.now().minus(150, DAYS).toString())
.replace("%within405days-200days%", Instant.now().minus(400, DAYS).toString())
.replace("%within180days-100days%", Instant.now().minus(100, DAYS).toString())
.replace("%within180days-101days%", Instant.now().minus(140, DAYS).toString())
.replace("%within180days-150days%", Instant.now().minus(160, DAYS).toString());
Response response = client.target(configuration.getLocalMatchingServiceMatchUrl())
.request(APPLICATION_JSON)
.post(Entity.json(jsonString));
validateMatchNoMatch(response);
}
示例5: basicRollbackTest
import org.junit.jupiter.api.DisplayName; //導入依賴的package包/類
@Test
@DisplayName( "Basic rollback test" )
public void basicRollbackTest() throws SQLException {
TransactionManager txManager = com.arjuna.ats.jta.TransactionManager.transactionManager();
TransactionSynchronizationRegistry txSyncRegistry = new com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionSynchronizationRegistryImple();
AgroalDataSourceConfigurationSupplier configurationSupplier = new AgroalDataSourceConfigurationSupplier()
.connectionPoolConfiguration( cp -> cp
.transactionIntegration( new NarayanaTransactionIntegration( txManager, txSyncRegistry ) )
);
try ( AgroalDataSource dataSource = AgroalDataSource.from( configurationSupplier ) ) {
txManager.begin();
Connection connection = dataSource.getConnection();
logger.info( format( "Got connection {0}", connection ) );
txManager.rollback();
assertTrue( connection.isClosed() );
} catch ( NotSupportedException | SystemException e ) {
fail( "Exception: " + e.getMessage() );
}
}
示例6: monitorExecutorService
import org.junit.jupiter.api.DisplayName; //導入依賴的package包/類
@DisplayName("ExecutorService can be monitored with a default set of metrics")
@Test
void monitorExecutorService() throws InterruptedException {
ExecutorService pool = ExecutorServiceMetrics.monitor(registry, Executors.newSingleThreadExecutor(), "beep.pool", userTags);
CountDownLatch taskStart = new CountDownLatch(1);
CountDownLatch taskComplete = new CountDownLatch(1);
pool.submit(() -> {
taskStart.countDown();
taskComplete.await(1, TimeUnit.SECONDS);
System.out.println("beep");
return 0;
});
pool.submit(() -> System.out.println("boop"));
taskStart.await(1, TimeUnit.SECONDS);
assertThat(registry.mustFind("beep.pool.queued").tags(userTags).gauge().value()).isEqualTo(1.0);
taskComplete.countDown();
pool.awaitTermination(1, TimeUnit.SECONDS);
assertThat(registry.mustFind("beep.pool").tags(userTags).timer().count()).isEqualTo(2L);
assertThat(registry.mustFind("beep.pool.queued").tags(userTags).gauge().value()).isEqualTo(0.0);
}
示例7: metricAfterRegistryRemove
import org.junit.jupiter.api.DisplayName; //導入依賴的package包/類
@DisplayName("metrics stop receiving updates when their registry parent is removed from a composite")
@Test
void metricAfterRegistryRemove() {
composite.add(simple);
Counter compositeCounter = composite.counter("counter");
compositeCounter.increment();
Counter simpleCounter = simple.mustFind("counter").counter();
assertThat(simpleCounter.count()).isEqualTo(1);
composite.remove(simple);
compositeCounter.increment();
// simple counter doesn't receive the increment after simple is removed from the composite
assertThat(simpleCounter.count()).isEqualTo(1);
composite.add(simple);
compositeCounter.increment();
// now it receives updates again
assertThat(simpleCounter.count()).isEqualTo(2);
}
示例8: multipleCloseTest
import org.junit.jupiter.api.DisplayName; //導入依賴的package包/類
@Test
@DisplayName( "Multiple close test" )
public void multipleCloseTest() throws SQLException {
TransactionManager txManager = com.arjuna.ats.jta.TransactionManager.transactionManager();
TransactionSynchronizationRegistry txSyncRegistry = new com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionSynchronizationRegistryImple();
AgroalDataSourceConfigurationSupplier configurationSupplier = new AgroalDataSourceConfigurationSupplier()
.connectionPoolConfiguration( cp -> cp
.transactionIntegration( new NarayanaTransactionIntegration( txManager, txSyncRegistry ) )
);
try ( AgroalDataSource dataSource = AgroalDataSource.from( configurationSupplier ) ) {
// there is a call to connection#close in the try-with-resources block and another on the callback from the transaction#commit()
try ( Connection connection = dataSource.getConnection() ) {
logger.info( format( "Got connection {0}", connection ) );
try {
txManager.begin();
txManager.commit();
} catch ( NotSupportedException | SystemException | RollbackException | HeuristicMixedException | HeuristicRollbackException e ) {
fail( "Exception: " + e.getMessage() );
}
}
}
}
示例9: testUpdate
import org.junit.jupiter.api.DisplayName; //導入依賴的package包/類
@Test
@DisplayName("Update Category")
public void testUpdate() {
// Not sure what IDs are there, so let's grab
/// them all, update one and make sure the update works
List<Category> categories = classUnderTest.findAll();
assertNotNull(categories, "List cannot be null!");
assertFalse(categories.isEmpty());
Category cat0 = categories.get(0);
cat0.withDescription(cat0.getDescription() + "_UPDATED");
boolean succeeded = classUnderTest.update(cat0);
assertTrue(succeeded);// , "Update should succeed");
Category catUpdated = classUnderTest.findById(cat0.getId());
assertNotNull(catUpdated);
doFieldByFieldAssertEquals(cat0, catUpdated);
}
示例10: objectGauge
import org.junit.jupiter.api.DisplayName; //導入依賴的package包/類
@Test
@DisplayName("gauges attached to an object are updated when their values are observed")
default void objectGauge(MeterRegistry registry) {
List<String> list = registry.gauge("my.gauge", emptyList(), new ArrayList<>(), List::size);
list.addAll(Arrays.asList("a", "b"));
Gauge g = registry.mustFind("my.gauge").gauge();
assertThat(g.value()).isEqualTo(2);
}
示例11: unsubscribe
import org.junit.jupiter.api.DisplayName; //導入依賴的package包/類
@Test
@DisplayName("should unsubscribe a subscribing receiver")
void unsubscribe() {
// Arrange
DataReceiver receiver = new DataReceiver() {
@Override
public void dataReceived(String data) {
assert false;
}
};
comInstance.subscribe(Direction.INTERNAL, receiver);
// Act
comInstance.unsubscribe(Direction.INTERNAL, receiver);
// Assert
comInstance.transmitData(value, Direction.INTERNAL);
}
示例12: testZigZag
import org.junit.jupiter.api.DisplayName; //導入依賴的package包/類
@DisplayName("ZigZag")
@Test
void testZigZag() {
assertAll(
() -> assertEquals(0x2468acf0, VarInt.encodeZigZag32(0x12345678)),
() -> assertEquals(0x2b826b1d, VarInt.encodeZigZag32(0xea3eca71)),
() -> assertEquals(0x12345678, VarInt.decodeZigZag32(0x2468acf0)),
() -> assertEquals(0xea3eca71, VarInt.decodeZigZag32(0x2b826b1d)),
() -> assertEquals(2623536930346282224L, VarInt.encodeZigZag64(0x1234567812345678L)),
() -> assertEquals(3135186066796324391L, VarInt.encodeZigZag64(0xea3eca710becececL)),
() -> assertEquals(0x1234567812345678L, VarInt.decodeZigZag64(2623536930346282224L)),
() -> assertEquals(0xea3eca710becececL, VarInt.decodeZigZag64(3135186066796324391L))
);
}
示例13: testRead
import org.junit.jupiter.api.DisplayName; //導入依賴的package包/類
@DisplayName("Reading")
@Test
void testRead() {
assertAll(
() -> assertEquals(2412, VarInt.readUnsignedVarInt(wrapBinaryStream("EC123EC456"))),
() -> assertEquals(583868, VarInt.readUnsignedVarInt(wrapBinaryStream("BCD123EFA0"))),
() -> assertEquals(1206, VarInt.readVarInt(wrapBinaryStream("EC123EC456"))),
() -> assertEquals(291934, VarInt.readVarInt(wrapBinaryStream("BCD123EFA0"))),
() -> assertEquals(6015, VarInt.readUnsignedVarLong(wrapBinaryStream("FF2EC456EC789EC012EC"))),
() -> assertEquals(3694, VarInt.readUnsignedVarLong(wrapBinaryStream("EE1CD34BCD56BCD78BCD"))),
() -> assertEquals(-3008, VarInt.readVarLong(wrapBinaryStream("FF2EC456EC789EC012EC"))),
() -> assertEquals(1847, VarInt.readVarLong(wrapBinaryStream("EE1CD34BCD56BCD78BCD")))
);
}
示例14: testGutterGame
import org.junit.jupiter.api.DisplayName; //導入依賴的package包/類
@Test
@DisplayName("the score should be 0")
void testGutterGame() {
rollMany(20, 0);
assertEquals(0, game.score());
}
示例15: testWithCustomDisplayNames
import org.junit.jupiter.api.DisplayName; //導入依賴的package包/類
@DisplayName("Display name of test container")
@ParameterizedTest(name = "[{index}] first argument=\"{0}\", second argument={1}")
@CsvSource({ "mastering, 1", "parameterized, 2", "tests, 3" })
void testWithCustomDisplayNames(String first, int second) {
System.out.println(
"Testing with parameters: " + first + " and " + second);
}