當前位置: 首頁>>代碼示例>>Java>>正文


Java LocalDateTime.getYear方法代碼示例

本文整理匯總了Java中java.time.LocalDateTime.getYear方法的典型用法代碼示例。如果您正苦於以下問題:Java LocalDateTime.getYear方法的具體用法?Java LocalDateTime.getYear怎麽用?Java LocalDateTime.getYear使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.time.LocalDateTime的用法示例。


在下文中一共展示了LocalDateTime.getYear方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: writeDateTimeUntil

import java.time.LocalDateTime; //導入方法依賴的package包/類
public static void writeDateTimeUntil(LocalDateTime dateTime, ByteArrayOutputStream bos) {
    // this is frigging confusing.. who the hell did think about this...
    // the first three bits are the months
    // next five bits are the day
    // next bit is always 0
    // next bit is the month again (the very first one)
    // next bit is always 0
    // last five bits are the year

    // only the first three bits!

    // int month = (positiveFirst >> 5 << 1) + (64 >> 6 & 1);
    int month = dateTime.getMonthValue();
    int monthAndDay = (month << 4 & 224) + dateTime.getDayOfMonth();
    bos.write(monthAndDay);

    int monthAndYear = (month % 2 == 1 ? 128 : 0) + (dateTime.getYear() - 2000);
    bos.write(monthAndYear);

    int halfhours = (dateTime.getHour() * 2) + (dateTime.getMinute() == 30 ? 1 : 0);
    bos.write(halfhours);
}
 
開發者ID:spinscale,項目名稱:maxcube-java,代碼行數:23,代碼來源:Generator.java

示例2: javaToDosTime

import java.time.LocalDateTime; //導入方法依賴的package包/類
/**
 * Converts Java time to DOS time.
 */
private static long javaToDosTime(long time) {
    Instant instant = Instant.ofEpochMilli(time);
    LocalDateTime ldt = LocalDateTime.ofInstant(
            instant, ZoneId.systemDefault());
    int year = ldt.getYear() - 1980;
    if (year < 0) {
        return (1 << 21) | (1 << 16);
    }
    return (year << 25 |
        ldt.getMonthValue() << 21 |
        ldt.getDayOfMonth() << 16 |
        ldt.getHour() << 11 |
        ldt.getMinute() << 5 |
        ldt.getSecond() >> 1) & 0xffffffffL;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:ZipUtils.java

示例3: getNormalDate

import java.time.LocalDateTime; //導入方法依賴的package包/類
/**
 * Returns String representing given LocalDateTime.
 *
 * @param date to format
 * @return date as string
 */
public static String getNormalDate(LocalDateTime date, int type) {
    String returnString = date.getDayOfMonth() + " " + date.getMonth().toString().substring(0, 1).toUpperCase();
    return returnString + (type == SHORT_DATE ?
            date.getMonth().toString().substring(1, 3).toLowerCase() :
            date.getMonth().toString().substring(1).toLowerCase()) +
            " " + date.getYear();
}
 
開發者ID:kristenkotkas,項目名稱:moviediary,代碼行數:14,代碼來源:StringUtils.java

示例4: dateFormatterForLogs

import java.time.LocalDateTime; //導入方法依賴的package包/類
private static String dateFormatterForLogs(LocalDateTime dateTime) {
    String dateString = "[";
    dateString += dateTime.getDayOfMonth() + "_";
    dateString += dateTime.getMonthValue() + "_";
    dateString += dateTime.getYear() + "_";
    dateString += dateTime.getHour() + ":";
    dateString += dateTime.getMinute() + ":";
    dateString += dateTime.getSecond();
    dateString += "] ";
    return dateString;
}
 
開發者ID:samurayrj,項目名稱:rubenlagus-TelegramBots,代碼行數:12,代碼來源:FileFormatter.java

示例5: getDateIdFromTimestamp

import java.time.LocalDateTime; //導入方法依賴的package包/類
public static int getDateIdFromTimestamp(long millis)
{
   	int result;
   	Instant i = Instant.ofEpochMilli(millis);
   	LocalDateTime ldt = LocalDateTime.ofInstant(i, ZoneId.of("UTC") ); //ZoneId.systemDefault()
   	int year = ldt.getYear();
   	int month = ldt.getMonth().getValue();
   	int day = ldt.getDayOfMonth();
   	result = day + (100 * month) + (10000 * year);
   	return result;
}
 
開發者ID:datancoffee,項目名稱:sirocco,代碼行數:12,代碼來源:IdConverterUtils.java

示例6: decodeNotNull

import java.time.LocalDateTime; //導入方法依賴的package包/類
@Override
public Object decodeNotNull(int flag, CodecDataInput cdi) {
  long val = IntegerType.decodeNotNullPrimitive(flag, cdi);
  LocalDateTime localDateTime = fromPackedLong(val);
  if (localDateTime == null) {
    return null;
  }
  //TODO revisit this later.
  return new Date(localDateTime.getYear() - 1900,
      localDateTime.getMonthValue() - 1,
      localDateTime.getDayOfMonth());
}
 
開發者ID:pingcap,項目名稱:tikv-client-lib-java,代碼行數:13,代碼來源:DateType.java

示例7: getLatestMotTestByDvlaVehicleId_VehicleDoesNotExist_DvlaVehicleDoes

import java.time.LocalDateTime; //導入方法依賴的package包/類
@Test
public void getLatestMotTestByDvlaVehicleId_VehicleDoesNotExist_DvlaVehicleDoes() {

    uk.gov.dvsa.mot.trade.api.DvlaVehicle dvlaVehicle = createDvlaVehicle();

    final LocalDateTime manufactureDateTime =
            LocalDateTime.ofInstant(dvlaVehicle.getManufactureDate().toInstant(), ZoneId.systemDefault());
    final int manufactureYear = manufactureDateTime.getYear();
    final String primaryColour = "BLUE";
    final String secondaryColour = "WHITE";

    int dvlaVehicleId = dvlaVehicle.getDvlaVehicleId();
    when(vehicleReadServiceMock.findByDvlaVehicleId(dvlaVehicleId)).thenReturn(null);

    when(vehicleReadServiceMock.findDvlaVehicleById(dvlaVehicleId)).thenReturn(Arrays.asList(dvlaVehicle));

    MotrResponse motrResponse =
            motrReadService.getLatestMotTestByDvlaVehicleId(dvlaVehicleId);

    assertNotNull("Returned vehicle is null", motrResponse);
    assertEquals("Registration is incorrect", dvlaVehicle.getRegistration(), motrResponse.getRegistration());
    assertEquals("Make is incorrect", dvlaVehicle.getMakeDetail(), motrResponse.getMake());
    assertEquals("Model is incorrect", dvlaVehicle.getModelDetail(), motrResponse.getModel());
    assertEquals("Manufacturing year is incorrect", Integer.toString(manufactureYear),
            motrResponse.getManufactureYear());
    assertNotNull("Test expiry date is incorrect", motrResponse.getMotTestExpiryDate());
    assertNull("Test number is incorrect", motrResponse.getMotTestNumber());
    assertEquals("Primary colour is incorrect", primaryColour, motrResponse.getPrimaryColour());
    assertEquals("DvlaId is incorrect", Integer.toString(dvlaVehicleId), motrResponse.getDvlaId());
    assertEquals("Secondary colour is incorrect", secondaryColour, motrResponse.getSecondaryColour());
}
 
開發者ID:dvsa,項目名稱:mot-public-api,代碼行數:32,代碼來源:MotrReadServiceTest.java

示例8: javaToDosTime

import java.time.LocalDateTime; //導入方法依賴的package包/類
public static long javaToDosTime(long time) {
    Instant instant = Instant.ofEpochMilli(time);
    LocalDateTime ldt = LocalDateTime.ofInstant(
            instant, ZoneId.systemDefault());
    int year = ldt.getYear() - 1980;
    if (year < 0) {
        return (1 << 21) | (1 << 16);
    }
    return (year << 25 |
        ldt.getMonthValue() << 21 |
        ldt.getDayOfMonth() << 16 |
        ldt.getHour() << 11 |
        ldt.getMinute() << 5 |
        ldt.getSecond() >> 1) & 0xffffffffL;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:16,代碼來源:ZipUtils.java

示例9: getLatestMotTestByRegistration_ValidRegistration_NullTest

import java.time.LocalDateTime; //導入方法依賴的package包/類
@Test
public void getLatestMotTestByRegistration_ValidRegistration_NullTest() {

    final String registration = "AA00AAA";
    final LocalDateTime manufactureDateTime = LocalDateTime.now().minus(5, ChronoUnit.YEARS);
    final int manufactureYear = manufactureDateTime.getYear();
    final Date manufactureDate = Date.from(manufactureDateTime.atZone(ZoneId.systemDefault()).toInstant());
    final String make = "MADEBY";
    final String model = "ETERNIA";
    final String primaryColour = "BLUE";
    final String secondaryColour = "WHITE";

    final Vehicle backendVehicle = new Vehicle();
    backendVehicle.setRegistration(registration);
    backendVehicle.setManufactureDate(manufactureDate);
    backendVehicle.setMake(make);
    backendVehicle.setModel(model);
    backendVehicle.setPrimaryColour(primaryColour);
    backendVehicle.setSecondaryColour(secondaryColour);

    uk.gov.dvsa.mot.trade.api.DvlaVehicle dvlaVehicle = createDvlaVehicle();

    when(vehicleReadServiceMock.findByRegistration(registration)).thenReturn(Arrays.asList(backendVehicle));
    when(motTestReadServiceMock.getLatestMotTestPassByVehicle(backendVehicle)).thenReturn(null);
    when(vehicleReadServiceMock.findDvlaVehicleByRegistration(registration)).thenReturn(Arrays.asList(dvlaVehicle));

    MotrResponse motrResponse = motrReadService.getLatestMotTestByRegistration(registration);

    assertNotNull("Returned vehicle is null", motrResponse);
    assertEquals("Registration is incorrect", registration, motrResponse.getRegistration());
    assertEquals("Make is incorrect", make, motrResponse.getMake());
    assertEquals("Model is incorrect", model, motrResponse.getModel());
    assertEquals("Manufacturing year is incorrect", Integer.toString(manufactureYear),
            motrResponse.getManufactureYear());
    assertNotNull("Test expiry date is incorrect", motrResponse.getMotTestExpiryDate());
    assertNull("Test number is incorrect", motrResponse.getMotTestNumber());
    assertEquals("Primary colour is incorrect", primaryColour, motrResponse.getPrimaryColour());
    assertEquals("Secondary colour is incorrect", secondaryColour, motrResponse.getSecondaryColour());

}
 
開發者ID:dvsa,項目名稱:mot-public-api,代碼行數:41,代碼來源:MotrReadServiceTest.java

示例10: isNeededToLaunch

import java.time.LocalDateTime; //導入方法依賴的package包/類
/**
 * Vérifie si le batch doit être lancé grace a son schedul
 * 
 * @param batch
 * @param lastExec
 * @return true si le batch doit etre lance ou non
 */
private Boolean isNeededToLaunch(Batch batch, LocalDateTime lastExec) {
	/* Vérification si le batch doit etre lancé immediatement */
	if (batch.getTemIsLaunchImediaBatch()) {
		batch.setTemIsLaunchImediaBatch(false);
		batchRepository.saveAndFlush(batch);
		return true;
	}
	LocalDateTime now = LocalDateTime.now();

	/* Vérification si le batch doit etre lancé à une date précise */
	if (batch.getFixeYearBatch() != null && batch.getFixeMonthBatch() != null && batch.getFixeDayBatch() != null) {
		if (now.getYear() != batch.getFixeYearBatch() || now.getMonth().getValue() != batch.getFixeMonthBatch()
				|| now.getDayOfMonth() != batch.getFixeDayBatch()) {
			return false;
		}
	}
	/*
	 * Vérification si le batch doit etre lancé annuelement avec un mois donné et un
	 * jour donné
	 */
	if (batch.getFixeMonthBatch() != null && batch.getFixeDayBatch() != null) {
		if (now.getMonth().getValue() != batch.getFixeMonthBatch()
				|| now.getDayOfMonth() != batch.getFixeDayBatch()) {
			return false;
		}
	}
	/* Vérification si le batch doit etre lancé mensuelement avec un jour donné */
	else if (batch.getFixeDayBatch() != null) {
		if (now.getDayOfMonth() != batch.getFixeDayBatch()) {
			return false;
		}
	}

	/*
	 * Sinon vérification si le batch doit etre lancé hebdo avec les journs précisés
	 */
	else {
		DayOfWeek today = now.getDayOfWeek();
		if (!batch.getTemLundiBatch() && today.getValue() == 1) {
			return false;
		} else if (!batch.getTemMardiBatch() && today.getValue() == 2) {
			return false;
		} else if (!batch.getTemMercrBatch() && today.getValue() == 3) {
			return false;
		} else if (!batch.getTemJeudiBatch() && today.getValue() == 4) {
			return false;
		} else if (!batch.getTemVendrediBatch() && today.getValue() == 5) {
			return false;
		} else if (!batch.getTemSamediBatch() && today.getValue() == 6) {
			return false;
		} else if (!batch.getTemDimanBatch() && today.getValue() == 7) {
			return false;
		}
	}

	logger.trace("OK à lancer aujourd'hui");
	if ((batch.getFixeHourBatch().isAfter(lastExec.toLocalTime()))
			&& batch.getFixeHourBatch().isBefore(now.toLocalTime())) {
		logger.trace("OK à lancer maintenant");
		return true;
	}
	return false;
}
 
開發者ID:EsupPortail,項目名稱:esup-ecandidat,代碼行數:71,代碼來源:BatchController.java

示例11: Vehicle

import java.time.LocalDateTime; //導入方法依賴的package包/類
@Test
public void getLatestMotTestByMotTestNumberWithSameRegistrationAndVin_ValidRegistration_ReturnsVehicle_FullyPopulated() {

    final String registration = "AA00AAA";
    final LocalDateTime expiryDateTime = LocalDateTime.now().plus(Period.ofMonths(6));
    final Date expiryDate = Date.from(expiryDateTime.atZone(ZoneId.systemDefault()).toInstant());
    final LocalDateTime manufactureDateTime = LocalDateTime.now().minus(5, ChronoUnit.YEARS);
    final int manufactureYear = manufactureDateTime.getYear();
    final Date manufactureDate = Date.from(manufactureDateTime.atZone(ZoneId.systemDefault()).toInstant());
    final long motTestNumber = 5672823;
    final String make = "MADEBY";
    final String model = "ETERNIA";
    final String primaryColour = "BLUE";
    final String secondaryColour = "WHITE";

    final Vehicle backendVehicle = new Vehicle();
    backendVehicle.setRegistration(registration);
    backendVehicle.setManufactureDate(manufactureDate);
    backendVehicle.setMake(make);
    backendVehicle.setModel(model);
    backendVehicle.setPrimaryColour(primaryColour);
    backendVehicle.setSecondaryColour(secondaryColour);

    final MotTest backendTest = new MotTest();
    backendTest.setExpiryDate(expiryDate);
    backendTest.setNumber(motTestNumber);

    when(vehicleReadServiceMock.findByMotTestNumberWithSameRegistrationAndVin(motTestNumber)).thenReturn(Arrays.asList(backendVehicle));
    when(motTestReadServiceMock.getLatestMotTestPassByVehicle(backendVehicle)).thenReturn(backendTest);

    MotrResponse motrResponse =
            motrReadService.getLatestMotTestByMotTestNumberWithSameRegistrationAndVin(motTestNumber);

    assertNotNull("Returned vehicle is null", motrResponse);
    assertEquals("Registration is incorrect", registration, motrResponse.getRegistration());
    assertEquals("Make is incorrect", make, motrResponse.getMake());
    assertEquals("Model is incorrect", model, motrResponse.getModel());
    assertEquals("Manufacturing year is incorrect", Integer.toString(manufactureYear),
            motrResponse.getManufactureYear());
    assertEquals("Test expiry date is incorrect", expiryDateTime.format(DateTimeFormatter.ISO_DATE),
            motrResponse.getMotTestExpiryDate());
    assertEquals("Test number is incorrect", Long.toString(motTestNumber), motrResponse.getMotTestNumber());
    assertEquals("Primary colour is incorrect", primaryColour, motrResponse.getPrimaryColour());
    assertEquals("Secondary colour is incorrect", secondaryColour, motrResponse.getSecondaryColour());

}
 
開發者ID:dvsa,項目名稱:mot-public-api,代碼行數:47,代碼來源:MotrReadServiceTest.java

示例12: getLatestMotTestByRegistration_ValidRegistration_ReturnsVehicle_WithoutExpiryDate

import java.time.LocalDateTime; //導入方法依賴的package包/類
@Test
public void getLatestMotTestByRegistration_ValidRegistration_ReturnsVehicle_WithoutExpiryDate() {

    final String registration = "AA00AAA";
    final LocalDateTime manufactureDateTime = LocalDateTime.now().minus(5, ChronoUnit.YEARS);
    final int manufactureYear = manufactureDateTime.getYear();
    final Date manufactureDate = Date.from(manufactureDateTime.atZone(ZoneId.systemDefault()).toInstant());
    final long motTestNumber = 5672823;
    final String make = "MADEBY";
    final String model = "ETERNIA";
    final String primaryColour = "BLUE";
    final String secondaryColour = "WHITE";

    final Vehicle backendVehicle = new Vehicle();
    backendVehicle.setRegistration(registration);
    backendVehicle.setManufactureDate(manufactureDate);
    backendVehicle.setMake(make);
    backendVehicle.setModel(model);
    backendVehicle.setPrimaryColour(primaryColour);
    backendVehicle.setSecondaryColour(secondaryColour);

    final MotTest backendTest = new MotTest();
    backendTest.setNumber(motTestNumber);

    when(vehicleReadServiceMock.findByRegistration(registration)).thenReturn(Arrays.asList(backendVehicle));
    when(motTestReadServiceMock.getLatestMotTestPassByVehicle(backendVehicle)).thenReturn(backendTest);

    MotrResponse motrResponse = motrReadService.getLatestMotTestByRegistration(registration);

    assertNotNull("Returned vehicle is null", motrResponse);
    assertEquals("Registration is incorrect", registration, motrResponse.getRegistration());
    assertEquals("Make is incorrect", make, motrResponse.getMake());
    assertEquals("Model is incorrect", model, motrResponse.getModel());
    assertEquals("Manufacturing year is incorrect", Integer.toString(manufactureYear),
            motrResponse.getManufactureYear());
    assertNull("Test expiry date was made up out of nowhere", motrResponse.getMotTestExpiryDate());
    assertEquals("Test number is incorrect", Long.toString(motTestNumber), motrResponse.getMotTestNumber());
    assertEquals("Primary colour is incorrect", primaryColour, motrResponse.getPrimaryColour());
    assertEquals("Secondary colour is incorrect", secondaryColour, motrResponse.getSecondaryColour());

}
 
開發者ID:dvsa,項目名稱:mot-public-api,代碼行數:42,代碼來源:MotrReadServiceTest.java

示例13: testDateTimeInfo

import java.time.LocalDateTime; //導入方法依賴的package包/類
/**
 * 獲取時間節點的詳細信息
 */
@Test
public void testDateTimeInfo(){
    LocalDateTime ldt = LocalDateTime.now();

    // 獲取當前的年份
    int year = ldt.getYear();
    System.out.println(year);

    // 當前年中的第幾天
    int dayOfYear = ldt.getDayOfYear();
    System.out.println(dayOfYear);

    // 當前月份中的第幾天
    int dayOfMonth = ldt.getDayOfMonth();
    System.out.println(dayOfMonth);

    // 當前周中的第幾天
    DayOfWeek dayOfWeek = ldt.getDayOfWeek();
    int dayOfWeekValue = dayOfWeek.getValue();
    System.out.println(dayOfWeekValue);

    // 獲取小時
    int hour = ldt.getHour();
    System.out.println(hour);

    // 獲取月份信息
    Month month = ldt.getMonth();
    int monthValue = month.getValue();
    System.out.println(monthValue);
    int ldtMonthValue = ldt.getMonthValue();
    System.out.println(ldtMonthValue);

    // 獲取分鍾
    int minute = ldt.getMinute();
    System.out.println(minute);
}
 
開發者ID:cbooy,項目名稱:cakes,代碼行數:40,代碼來源:LocalDateTimeDemo.java

示例14: getLatestMotTestByMotTestNumberWithSameRegistrationAndVin_VehicleWithSplitHistory_MotExistsOneVehicle

import java.time.LocalDateTime; //導入方法依賴的package包/類
@Test
public void getLatestMotTestByMotTestNumberWithSameRegistrationAndVin_VehicleWithSplitHistory_MotExistsOneVehicle() {

    final String registration = "AA00AAA";
    final LocalDateTime expiryDateTime = LocalDateTime.now().plus(Period.ofMonths(6));
    final Date expiryDate = Date.from(expiryDateTime.atZone(ZoneId.systemDefault()).toInstant());
    final LocalDateTime manufactureDateTime = LocalDateTime.now().minus(5, ChronoUnit.YEARS);
    final int manufactureYear = manufactureDateTime.getYear();
    final Date manufactureDate = Date.from(manufactureDateTime.atZone(ZoneId.systemDefault()).toInstant());
    final long motTestNumber = 5672823;
    final String make = "MADEBY";
    final String model = "ETERNIA";
    final String primaryColour = "BLUE";
    final String secondaryColour = "WHITE";

    final Vehicle backendVehicle = new Vehicle();
    backendVehicle.setRegistration(registration);
    backendVehicle.setManufactureDate(manufactureDate);
    backendVehicle.setMake(make);
    backendVehicle.setModel(model);
    backendVehicle.setPrimaryColour(primaryColour);
    backendVehicle.setSecondaryColour(secondaryColour);

    final Vehicle backendVehicle2 = new Vehicle();
    backendVehicle2.setRegistration(registration);
    backendVehicle2.setManufactureDate(manufactureDate);
    backendVehicle2.setMake(make);
    backendVehicle2.setModel(model);
    backendVehicle2.setPrimaryColour(primaryColour);
    backendVehicle2.setSecondaryColour(secondaryColour);

    final MotTest backendTest = new MotTest();
    backendTest.setExpiryDate(expiryDate);
    backendTest.setNumber(motTestNumber);

    when(vehicleReadServiceMock.findByMotTestNumberWithSameRegistrationAndVin(motTestNumber))
            .thenReturn(Arrays.asList(backendVehicle, backendVehicle2));
    when(motTestReadServiceMock.getLatestMotTestPassByVehicle(backendVehicle)).thenReturn(null);
    when(motTestReadServiceMock.getLatestMotTestPassByVehicle(backendVehicle2)).thenReturn(backendTest);

    MotrResponse motrResponse =
            motrReadService.getLatestMotTestByMotTestNumberWithSameRegistrationAndVin(motTestNumber);

    assertNotNull("Returned vehicle is null", motrResponse);
    assertEquals("Registration is incorrect", registration, motrResponse.getRegistration());
    assertEquals("Make is incorrect", make, motrResponse.getMake());
    assertEquals("Model is incorrect", model, motrResponse.getModel());
    assertEquals("Manufacturing year is incorrect", Integer.toString(manufactureYear),
            motrResponse.getManufactureYear());
    assertEquals("Test expiry date is incorrect", expiryDateTime.format(DateTimeFormatter.ISO_DATE),
            motrResponse.getMotTestExpiryDate());
    assertEquals("Test number is incorrect", Long.toString(motTestNumber), motrResponse.getMotTestNumber());
    assertEquals("Primary colour is incorrect", primaryColour, motrResponse.getPrimaryColour());
    assertEquals("Secondary colour is incorrect", secondaryColour, motrResponse.getSecondaryColour());
}
 
開發者ID:dvsa,項目名稱:mot-public-api,代碼行數:56,代碼來源:MotrReadServiceTest.java

示例15: getLatestMotTestByMotTestNumberWithSameRegistrationAndVin_VehicleWithSplitHistory_MotDoesNotExist

import java.time.LocalDateTime; //導入方法依賴的package包/類
@Test
public void getLatestMotTestByMotTestNumberWithSameRegistrationAndVin_VehicleWithSplitHistory_MotDoesNotExist() {

    final String registration = "AA00AAA";
    final LocalDateTime manufactureDateTime = LocalDateTime.now().minus(5, ChronoUnit.YEARS);
    final int manufactureYear = manufactureDateTime.getYear();
    final Date manufactureDate = Date.from(manufactureDateTime.atZone(ZoneId.systemDefault()).toInstant());
    final long motTestNumber = 5672823;
    final String make = "MADEBY";
    final String model = "ETERNIA";
    final String primaryColour = "BLUE";
    final String secondaryColour = "WHITE";

    final Vehicle backendVehicle = new Vehicle();
    backendVehicle.setRegistration(registration);
    backendVehicle.setManufactureDate(manufactureDate);
    backendVehicle.setMake(make);
    backendVehicle.setModel(model);
    backendVehicle.setPrimaryColour(primaryColour);
    backendVehicle.setSecondaryColour(secondaryColour);

    final Vehicle backendVehicle2 = new Vehicle();
    backendVehicle2.setRegistration(registration);
    backendVehicle2.setManufactureDate(manufactureDate);
    backendVehicle2.setMake(make);
    backendVehicle2.setModel(model);
    backendVehicle2.setPrimaryColour(primaryColour);
    backendVehicle2.setSecondaryColour(secondaryColour);

    when(vehicleReadServiceMock.findByMotTestNumberWithSameRegistrationAndVin(motTestNumber))
            .thenReturn(Arrays.asList(backendVehicle, backendVehicle2));
    when(motTestReadServiceMock.getLatestMotTestPassByVehicle(backendVehicle)).thenReturn(null);
    when(motTestReadServiceMock.getLatestMotTestPassByVehicle(backendVehicle2)).thenReturn(null);

    MotrResponse motrResponse =
            motrReadService.getLatestMotTestByMotTestNumberWithSameRegistrationAndVin(motTestNumber);

    assertNotNull("Returned vehicle is null", motrResponse);
    assertEquals("Registration is incorrect", registration, motrResponse.getRegistration());
    assertEquals("Make is incorrect", make, motrResponse.getMake());
    assertEquals("Model is incorrect", model, motrResponse.getModel());
    assertEquals("Manufacturing year is incorrect", Integer.toString(manufactureYear),
            motrResponse.getManufactureYear());
    assertNull("Test expiry date is incorrect", motrResponse.getMotTestExpiryDate());
    assertNull("Test number is incorrect", motrResponse.getMotTestNumber());
    assertEquals("Primary colour is incorrect", primaryColour, motrResponse.getPrimaryColour());
    assertEquals("Secondary colour is incorrect", secondaryColour, motrResponse.getSecondaryColour());
}
 
開發者ID:dvsa,項目名稱:mot-public-api,代碼行數:49,代碼來源:MotrReadServiceTest.java


注:本文中的java.time.LocalDateTime.getYear方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。