下面列出了java.time.LocalTime#now ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Test
public void testAddTimerWidgetWithStopTimeAndRemove() throws Exception {
ses.scheduleAtFixedRate(holder.timerWorker, 0, 1000, TimeUnit.MILLISECONDS);
Timer timer = new Timer();
timer.id = 112;
timer.x = 1;
timer.y = 1;
timer.pinType = PinType.DIGITAL;
timer.pin = 5;
timer.width = 2;
timer.height = 1;
timer.startValue = "1";
timer.stopValue = "0";
LocalTime localDateTime = LocalTime.now(ZoneId.of("UTC"));
int curTime = localDateTime.toSecondOfDay();
timer.startTime = curTime + 1;
timer.stopTime = curTime + 2;
clientPair.appClient.createWidget(1, timer);
clientPair.appClient.verifyResult(ok(1));
clientPair.appClient.deleteWidget(1, 112);
clientPair.appClient.verifyResult(ok(2));
verify(clientPair.hardwareClient.responseMock, after(2500).never()).channelRead(any(), any());
}
public static LocalDate thisOrNextMarketDay(Exchange exchange, LocalDate tradingDay, boolean thisCompleted){
if ( exchange==null) {
exchange = Exchange.SSE;
}
if( tradingDay==null ) {
tradingDay = LocalDate.now(exchange.getZoneId());
}
LocalTime thisTime = LocalTime.now(exchange.getZoneId());
if ( thisCompleted && thisTime.compareTo(exchange.getMarketTimes()[1])<=0 ){
tradingDay = tradingDay.plusMonths(1);
}
if ( isMarketDay(exchange, tradingDay) ) {
return tradingDay;
}
return nextMarketDay(exchange, tradingDay);
}
@Test
public void now_Clock_allSecsInDay() {
for (int i = 0; i < (2 * 24 * 60 * 60); i++) {
Instant instant = Instant.ofEpochSecond(i, 8);
Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
LocalTime test = LocalTime.now(clock);
assertEquals(test.getHour(), (i / (60 * 60)) % 24);
assertEquals(test.getMinute(), (i / 60) % 60);
assertEquals(test.getSecond(), i % 60);
assertEquals(test.getNano(), 8);
}
}
@Test
public void now_Clock_allSecsInDay() {
for (int i = 0; i < (2 * 24 * 60 * 60); i++) {
Instant instant = Instant.ofEpochSecond(i, 8);
Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
LocalTime test = LocalTime.now(clock);
assertEquals(test.getHour(), (i / (60 * 60)) % 24);
assertEquals(test.getMinute(), (i / 60) % 60);
assertEquals(test.getSecond(), i % 60);
assertEquals(test.getNano(), 8);
}
}
@Test
public void testPreRegistration() {
List<TicketCategoryModification> categories = Collections.singletonList(
new TicketCategoryModification(null, "default", 10,
new DateTimeModification(LocalDate.now().plusDays(1), LocalTime.now()),
new DateTimeModification(LocalDate.now().plusDays(2), LocalTime.now()),
DESCRIPTION, BigDecimal.TEN, false, "", false, null, null, null, null, null, 0, null, null, AlfioMetadata.empty()));
Pair<Event, String> pair = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository);
Event event = pair.getKey();
waitingQueueManager.subscribe(event, new CustomerName("Giuseppe Garibaldi", "Giuseppe", "Garibaldi", event.mustUseFirstAndLastName()), "[email protected]", null, Locale.ENGLISH);
waitingQueueManager.subscribe(event, new CustomerName("Nino Bixio", "Nino", "Bixio", event.mustUseFirstAndLastName()), "[email protected]", null, Locale.ITALIAN);
assertTrue(waitingQueueRepository.countWaitingPeople(event.getId()) == 2);
waitingQueueSubscriptionProcessor.distributeAvailableSeats(event);
assertEquals(18, ticketRepository.findFreeByEventId(event.getId()).size());
TicketCategoryModification tcm = new TicketCategoryModification(null, "default", 10,
new DateTimeModification(LocalDate.now().minusDays(1), LocalTime.now()),
new DateTimeModification(LocalDate.now().plusDays(5), LocalTime.now()),
DESCRIPTION, BigDecimal.TEN, false, "", true, null, null, null, null, null, 0, null, null, AlfioMetadata.empty());
eventManager.insertCategory(event.getId(), tcm, pair.getValue());
waitingQueueSubscriptionProcessor.distributeAvailableSeats(event);
List<WaitingQueueSubscription> subscriptions = waitingQueueRepository.loadAll(event.getId());
assertEquals(2, subscriptions.stream().filter(w -> StringUtils.isNotBlank(w.getReservationId())).count());
assertTrue(subscriptions.stream().allMatch(w -> w.getStatus().equals(WaitingQueueSubscription.Status.PENDING)));
assertTrue(subscriptions.stream().allMatch(w -> w.getSubscriptionType().equals(WaitingQueueSubscription.Type.PRE_SALES)));
}
@Test
public void testTimeColumn() {
LocalTime now = LocalTime.now(ZoneId.systemDefault());
Long value = now.toNanoOfDay();
primeWithType(value, TIME);
ResultSet resultSet = getResultSet();
Schema schema = Schema.builder().addNullableField("col", FieldType.INT64).build();
Row expected = Row.withSchema(schema).addValue(value).build();
assertEquals(expected, cassandraRowMapper.map(resultSet).next());
}
@Test
public void now_Clock_min() {
Clock clock = Clock.fixed(Instant.MIN, ZoneOffset.UTC);
LocalTime test = LocalTime.now(clock);
assertEquals(test.getHour(), 0);
assertEquals(test.getMinute(), 0);
assertEquals(test.getSecond(), 0);
assertEquals(test.getNano(), 0);
}
@Test
public void now_ZoneId() {
ZoneId zone = ZoneId.of("UTC+01:02:03");
LocalTime expected = LocalTime.now(Clock.system(zone));
LocalTime test = LocalTime.now(zone);
for (int i = 0; i < 100; i++) {
if (expected.equals(test)) {
return;
}
expected = LocalTime.now(Clock.system(zone));
test = LocalTime.now(zone);
}
assertEquals(test, expected);
}
@Test
public void now_ZoneId() {
ZoneId zone = ZoneId.of("UTC+01:02:03");
LocalTime expected = LocalTime.now(Clock.system(zone));
LocalTime test = LocalTime.now(zone);
for (int i = 0; i < 100; i++) {
if (expected.equals(test)) {
return;
}
expected = LocalTime.now(Clock.system(zone));
test = LocalTime.now(zone);
}
assertEquals(test, expected);
}
@Override
public long eval(VdmContext ctx, Heap heap, Parameters params, long pRecord) {
LocalTime time = LocalTime.now();
Duration duration = Duration.ofSeconds(time.getHour() * 3600 + time.getMinute() * 60 + time.getSecond());
long addr = FishTime.allocSet(heap, duration);
return addr;
}
@Test
public void now_Clock_allSecsInDay() {
for (int i = 0; i < (2 * 24 * 60 * 60); i++) {
Instant instant = Instant.ofEpochSecond(i, 8);
Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
LocalTime test = LocalTime.now(clock);
assertEquals(test.getHour(), (i / (60 * 60)) % 24);
assertEquals(test.getMinute(), (i / 60) % 60);
assertEquals(test.getSecond(), i % 60);
assertEquals(test.getNano(), 8);
}
}
@Test
public void testTimerWidgetTriggeredAndSendCommandToCorrectDevice() throws Exception {
TestHardClient hardClient2 = new TestHardClient("localhost", properties.getHttpPort());
hardClient2.start();
ses.scheduleAtFixedRate(holder.timerWorker, 0, 1000, TimeUnit.MILLISECONDS);
clientPair.appClient.deactivate(1);
clientPair.appClient.verifyResult(ok(1));
Timer timer = new Timer();
timer.id = 1;
timer.x = 1;
timer.y = 1;
timer.pinType = PinType.DIGITAL;
timer.pin = 5;
timer.startValue = "1";
timer.stopValue = "0";
LocalTime localDateTime = LocalTime.now(ZoneId.of("UTC"));
int curTime = localDateTime.toSecondOfDay();
timer.startTime = curTime + 1;
timer.stopTime = curTime + 2;
DashBoard dashBoard = new DashBoard();
dashBoard.id = 1;
dashBoard.name = "Test";
dashBoard.widgets = new Widget[] {timer};
clientPair.appClient.updateDash(dashBoard);
clientPair.appClient.verifyResult(ok(2));
dashBoard.id = 2;
clientPair.appClient.createDash(dashBoard);
clientPair.appClient.verifyResult(ok(3));
clientPair.appClient.activate(1);
clientPair.appClient.verifyResult(ok(4));
clientPair.appClient.reset();
clientPair.appClient.createDevice(2, new Device(1, "Device", BoardType.ESP8266));
Device device = clientPair.appClient.parseDevice();
hardClient2.login(device.token);
hardClient2.verifyResult(ok(1));
hardClient2.reset();
verify(clientPair.hardwareClient.responseMock, timeout(2000)).channelRead(any(), eq(hardware(7777, "dw 5 1")));
clientPair.hardwareClient.reset();
verify(clientPair.hardwareClient.responseMock, timeout(2000)).channelRead(any(), eq(hardware(7777, "dw 5 0")));
verify(hardClient2.responseMock, never()).channelRead(any(), any());
hardClient2.stop().awaitUninterruptibly();
}
private String getJagexTime()
{
LocalTime time = LocalTime.now(JAGEX);
return time.format(timeFormat);
}
@Test(expectedExceptions=NullPointerException.class)
public void now_Clock_nullClock() {
LocalTime.now((Clock) null);
}
@Test(expectedExceptions=NullPointerException.class)
public void now_ZoneId_nullZoneId() {
LocalTime.now((ZoneId) null);
}
public String getTimeMessage(){
return "It is "+LocalTime.now();
}
@Test(expectedExceptions=NullPointerException.class)
public void now_ZoneId_nullZoneId() {
LocalTime.now((ZoneId) null);
}
private String getJagexTime()
{
LocalTime time = LocalTime.now(JAGEX);
return time.format(timeFormat);
}
@Test
public void testTimerWidgetTriggeredAndSyncWorks() throws Exception {
ses.scheduleAtFixedRate(holder.timerWorker, 0, 1000, TimeUnit.MILLISECONDS);
clientPair.appClient.deactivate(1);
clientPair.appClient.verifyResult(ok(1));
Timer timer = new Timer();
timer.id = 1;
timer.x = 1;
timer.y = 1;
timer.pinType = PinType.VIRTUAL;
timer.pin = 5;
timer.startValue = "1";
timer.stopValue = "0";
LocalTime localDateTime = LocalTime.now(ZoneId.of("UTC"));
int curTime = localDateTime.toSecondOfDay();
timer.startTime = curTime + 1;
timer.stopTime = curTime + 2;
DashBoard dashBoard = new DashBoard();
dashBoard.id = 1;
dashBoard.name = "Test";
dashBoard.widgets = new Widget[] {timer};
clientPair.appClient.updateDash(dashBoard);
clientPair.appClient.verifyResult(ok(2));
clientPair.appClient.activate(1);
clientPair.appClient.verifyResult(ok(3));
verify(clientPair.hardwareClient.responseMock, timeout(2000)).channelRead(any(), eq(hardware(7777, "vw 5 1")));
clientPair.hardwareClient.reset();
clientPair.hardwareClient.sync(PinType.VIRTUAL, 5);
verify(clientPair.hardwareClient.responseMock, timeout(2000)).channelRead(any(), eq(hardware(1, "vw 5 1")));
verify(clientPair.hardwareClient.responseMock, timeout(2000)).channelRead(any(), eq(hardware(7777, "vw 5 0")));
clientPair.hardwareClient.sync(PinType.VIRTUAL, 5);
verify(clientPair.hardwareClient.responseMock, timeout(2000)).channelRead(any(), eq(hardware(2, "vw 5 0")));
}
@Test(expectedExceptions=NullPointerException.class)
public void now_Clock_nullClock() {
LocalTime.now((Clock) null);
}