Java Code Examples for java.time.Period

The following are top voted examples for showing how to use java.time.Period. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: morpheus-core   File: RangeBasicTests.java   Source Code and License 6 votes vote down vote up
@Test(dataProvider = "localDateRanges")
public void testRangeOfLocalDates(LocalDate start, LocalDate end, Period step, boolean parallel) {
    final Range<LocalDate> range = Range.of(start, end, step);
    final Array<LocalDate> array = range.toArray(parallel);
    final boolean ascend = start.isBefore(end);
    final int expectedLength = (int)Math.ceil(Math.abs((double)ChronoUnit.DAYS.between(start, end)) / (double)step.getDays());
    Assert.assertEquals(array.length(), expectedLength);
    Assert.assertEquals(array.typeCode(), ArrayType.LOCAL_DATE);
    Assert.assertTrue(!array.style().isSparse());
    Assert.assertEquals(range.start(), start, "The range start");
    Assert.assertEquals(range.end(), end, "The range end");
    LocalDate expected = null;
    for (int i=0; i<array.length(); ++i) {
        final LocalDate actual = array.getValue(i);
        expected = expected == null ? start : ascend ? expected.plus(step) : expected.minus(step);
        Assert.assertEquals(actual, expected, "Value matches at " + i);
        Assert.assertTrue(ascend ? actual.compareTo(start) >=0 && actual.isBefore(end) : actual.compareTo(start) <= 0 && actual.isAfter(end), "Value in bounds at " + i);
    }
}
 
Example 2
Project: swblocks-decisiontree   File: RuleChangeTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testConstruction() {
    final Instant start = Instant.now().minus(Period.ofWeeks(-1));
    final Instant end = start.plus(Period.ofWeeks(5));
    final InputDriver[] drivers = getInputDriverArray("Test1", "Test2", "Test3");
    final Map<String, String> outputs = Collections.singletonMap("outputDriver", "result");
    final DecisionTreeRule rule =
            new DecisionTreeRule(new UUID(0, 1), new UUID(0, 2), drivers, outputs, start, end);

    final RuleChange change = new RuleChange(Type.ORIGINAL, rule);
    setBean(change);

    this.injectedValues.put("type", Type.ORIGINAL);
    this.injectedValues.put("rule", rule);

    JblTestClassUtils.assertGetterCorrectForConstructorInjection(this.injectedValues, getBean());
}
 
Example 3
Project: openjdk-jdk10   File: TCKDateTimeParseResolver.java   Source Code and License 6 votes vote down vote up
@Test(dataProvider="resolveMinuteOfDay")
public void test_resolveMinuteOfDay(ResolverStyle style, long value, Integer expectedMinute, int expectedDays) {
    String str = Long.toString(value);
    DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(MINUTE_OF_DAY).toFormatter();

    if (expectedMinute != null) {
        TemporalAccessor accessor = f.withResolverStyle(style).parse(str);
        assertEquals(accessor.query(TemporalQueries.localDate()), null);
        assertEquals(accessor.query(TemporalQueries.localTime()), LocalTime.ofSecondOfDay(expectedMinute * 60));
        assertEquals(accessor.query(DateTimeFormatter.parsedExcessDays()), Period.ofDays(expectedDays));
    } else {
        try {
            f.withResolverStyle(style).parse(str);
            fail();
        } catch (DateTimeParseException ex) {
            // expected
        }
    }
}
 
Example 4
Project: swblocks-decisiontree   File: ValueGroupChangeTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testEquals() {
    final UUID id = new UUID(0, 1);
    final Instant start = Instant.now().minus(Period.ofWeeks(-1));
    final Instant end = start.plus(Period.ofWeeks(5));
    final DateRange range = new DateRange(start, end);
    final List<String> drivers = Arrays.asList("Test1", "Test2", "Test3");
    final ValueGroup valueGroup = new ValueGroup(id, "TestValueGroup", drivers, range);

    final ValueGroupChange change = new ValueGroupChange(Type.NEW, valueGroup);

    assertTrue(change.equals(change));
    assertFalse(change.equals(null));
    assertFalse(change.equals(Boolean.TRUE));

    ValueGroupChange other = new ValueGroupChange(Type.NEW, valueGroup);
    assertTrue(change.equals(other));

    final ValueGroup otherValueGroup = new ValueGroup(id, "VG:TestOtherValueGroup", drivers, range);
    other = new ValueGroupChange(Type.NEW, otherValueGroup);
    assertFalse(change.equals(other));

    other = new ValueGroupChange(Type.ORIGINAL, otherValueGroup);
    assertFalse(change.equals(other));
}
 
Example 5
Project: blog-examples   File: TransformerImpl.java   Source Code and License 6 votes vote down vote up
@Override
public IDestinationRecord transform(ISourceRecord source) {
	if(source == null){
		return null;
	}
   	int age = Period.between(source.date(), mAsAt).getYears();
   	return new IDestinationRecord() {
		
		@Override
		public String name() {
			return source.name();
		}
		
		@Override
		public int age() {
			return age;
		}
	};
}
 
Example 6
Project: swblocks-decisiontree   File: RuleChangeTest.java   Source Code and License 6 votes vote down vote up
@Test
public void hashCodeCorrect() {
    final Instant start = Instant.now().minus(Period.ofWeeks(-1));
    final Instant end = start.plus(Period.ofWeeks(5));
    final InputDriver[] drivers = getInputDriverArray("Test1", "Test2", "Test3");
    final Map<String, String> outputs = Collections.singletonMap("outputDriver", "result");

    final DecisionTreeRule rule =
            new DecisionTreeRule(new UUID(0, 1), new UUID(0, 2), drivers, outputs, start, end);
    final RuleChange ruleChange = new RuleChange(Type.ORIGINAL, rule);

    final DecisionTreeRule otherRule =
            new DecisionTreeRule(new UUID(0, 1), new UUID(0, 2), drivers, outputs, start, end);
    final RuleChange otherRuleChange = new RuleChange(Type.ORIGINAL, otherRule);

    assertEquals(ruleChange.hashCode(), otherRuleChange.hashCode());
}
 
Example 7
Project: morpheus-core   File: PrinterOfObject.java   Source Code and License 6 votes vote down vote up
/**
 * Constructor
 * @param nullValue the null value supplier
 */
PrinterOfObject(Supplier<String> nullValue) {
    super(FunctionStyle.OBJECT, nullValue);
    this.printerMap.put(boolean.class, Printer.ofBoolean());
    this.printerMap.put(Boolean.class, Printer.ofBoolean());
    this.printerMap.put(int.class, Printer.ofInt());
    this.printerMap.put(Integer.class, Printer.ofInt());
    this.printerMap.put(long.class, Printer.ofLong());
    this.printerMap.put(Long.class, Printer.ofLong());
    this.printerMap.put(double.class, Printer.ofDouble("0.000###;-0.000###"));
    this.printerMap.put(Double.class, Printer.ofDouble("0.000###;-0.000###"));
    this.printerMap.put(LocalDate.class, Printer.ofLocalDate(DateTimeFormatter.ISO_LOCAL_DATE));
    this.printerMap.put(LocalTime.class, Printer.ofLocalTime(DateTimeFormatter.ISO_LOCAL_TIME));
    this.printerMap.put(LocalDateTime.class, Printer.ofLocalDateTime(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
    this.printerMap.put(ZonedDateTime.class, Printer.ofZonedDateTime(DateTimeFormatter.ISO_ZONED_DATE_TIME));
    this.printerMap.put(Period.class, Printer.ofPeriod());
    this.printerMap.put(ZoneId.class, Printer.ofZoneId());
    this.printerMap.put(TimeZone.class, Printer.ofTimeZone());
    this.printerMap.put(java.util.Date.class, Printer.ofDate("yyyy-MM-dd"));
    this.printerMap.put(java.sql.Date.class, Printer.ofDate("yyyy-MM-dd"));
}
 
Example 8
Project: device-bacnet   File: ScheduleContext.java   Source Code and License 6 votes vote down vote up
private ZonedDateTime initNextTime(ZonedDateTime start, ZonedDateTime now, Period p, Duration d) {
	// if the start time is in the future next will just be start
	ZonedDateTime next = start;
	// if the start time is in the past, increment until we find the next time to execute
	// cannot call isComplete() here as it depends on nextTime
	if(startTime.compareTo(now) <= 0 && !schedule.getRunOnce()) {
		// TODO: Look to optimize.  Consider a one-second timer, it would take too long
		// For example if only a single unit, e.g. only minutes, then can optimize relative to start 
		// if there are more than one unit, then the loop may be best as it will be difficult
		while(next.compareTo(now) <= 0) {
			next = next.plus(p);
			next = next.plus(d);
		}
	}
	return next;
}
 
Example 9
Project: swblocks-decisiontree   File: RuleRangeChangeBuilderTest.java   Source Code and License 6 votes vote down vote up
@Test
public void amendsEndDateOfFirstSegmentToFinishBeforeSecondSegmentStarts() {
    createBuilder(new UUID(0, 1), new DateRange(null, NOW.plus(Period.ofWeeks(3))));
    final List<RuleChange> changes = this.builder.build();
    assertThat(changes, hasSize(2));

    final List<RuleChange> originals = getChangesByType(changes, Type.ORIGINAL);
    assertThat(originals, hasSize(1));

    assertRuleChange(originals.get(0), Type.ORIGINAL, new UUID(0, 1), new UUID(0, 2),
            new String[]{"VOICE", "CME", "ED", "US", "INDEX"}, Collections.singletonMap("Rate", "1.1"),
            NOW.plus(Period.ofWeeks(2)), NOW.plus(Period.ofWeeks(4)).minusMillis(1L));

    final List<RuleChange> newChanges = getChangesByType(changes, Type.NEW);
    assertThat(newChanges, hasSize(1));

    assertRuleChange(newChanges.get(0), Type.NEW, null, new UUID(0, 2),
            new String[]{"VOICE", "CME", "ED", "US", "INDEX"}, Collections.singletonMap("Rate", "1.1"),
            NOW.plus(Period.ofWeeks(2)), NOW.plus(Period.ofWeeks(3)));
}
 
Example 10
Project: openjdk-jdk10   File: TCKPeriod.java   Source Code and License 6 votes vote down vote up
public void test_equals() {
    assertEquals(Period.of(1, 0, 0).equals(Period.ofYears(1)), true);
    assertEquals(Period.of(0, 1, 0).equals(Period.ofMonths(1)), true);
    assertEquals(Period.of(0, 0, 1).equals(Period.ofDays(1)), true);
    assertEquals(Period.of(1, 2, 3).equals(Period.of(1, 2, 3)), true);

    assertEquals(Period.ofYears(1).equals(Period.ofYears(1)), true);
    assertEquals(Period.ofYears(1).equals(Period.ofYears(2)), false);

    assertEquals(Period.ofMonths(1).equals(Period.ofMonths(1)), true);
    assertEquals(Period.ofMonths(1).equals(Period.ofMonths(2)), false);

    assertEquals(Period.ofDays(1).equals(Period.ofDays(1)), true);
    assertEquals(Period.ofDays(1).equals(Period.ofDays(2)), false);

    assertEquals(Period.of(1, 2, 3).equals(Period.of(0, 2, 3)), false);
    assertEquals(Period.of(1, 2, 3).equals(Period.of(1, 0, 3)), false);
    assertEquals(Period.of(1, 2, 3).equals(Period.of(1, 2, 0)), false);
}
 
Example 11
Project: swblocks-decisiontree   File: RuleGroupChangeBuilderTest.java   Source Code and License 6 votes vote down vote up
private void assertOriginalSegmentsRemoved(final List<RuleChange> originals) {
    assertRuleChange(originals.get(0), Type.ORIGINAL, new UUID(0, 1), new UUID(0, 2),
            new String[]{"VOICE", GroupDriver.VG_PREFIX + GROUP_ID, "ED", "US", "INDEX"},
            Collections.singletonMap("Rate1", "1.1 "),
            NOW.plus(Period.ofWeeks(2)), NOW.plus(Period.ofWeeks(4)));

    assertRuleChange(originals.get(1), Type.ORIGINAL, new UUID(0, 2), new UUID(0, 2),
            new String[]{"EMAIL", GroupDriver.VG_PREFIX + GROUP_ID, "ED", "US", "INDEX"},
            Collections.singletonMap("Rate1", "1.2"),
            NOW.plus(Period.ofWeeks(4)), NOW.plus(Period.ofWeeks(6)));

    assertRuleChange(originals.get(2), Type.ORIGINAL, new UUID(0, 3), new UUID(0, 2),
            new String[]{"ELECTRONIC", GroupDriver.VG_PREFIX + GROUP_ID, "ED", "US", "INDEX"},
            Collections.singletonMap("Rate1", "1.3"),
            NOW.plus(Period.ofWeeks(6)), NOW.plus(Period.ofWeeks(8)));
}
 
Example 12
Project: swblocks-decisiontree   File: ValueGroupChangeTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testConstruction() {
    final UUID id = new UUID(0, 1);
    final Instant start = Instant.now().minus(Period.ofWeeks(-1));
    final Instant end = start.plus(Period.ofWeeks(5));
    final DateRange range = new DateRange(start, end);
    final List<String> drivers = Arrays.asList("Test1", "Test2", "Test3");
    final ValueGroup valueGroup = new ValueGroup(id, "TestValueGroup", drivers, range);

    final ValueGroupChange change = new ValueGroupChange(Type.NEW, valueGroup);

    setBean(change);

    this.injectedValues.put("type", Type.NEW);
    this.injectedValues.put("valueGroup", valueGroup);

    JblTestClassUtils.assertGetterCorrectForConstructorInjection(this.injectedValues, getBean());
}
 
Example 13
Project: swblocks-decisiontree   File: DatedTreeNodeTest.java   Source Code and License 6 votes vote down vote up
@Test
public void addNodeUpdatesDateRangeEnd() {
    final TreeNode root = createDatedTreeNode("Root", Instant.MIN, Instant.MAX);

    final Instant start = NOW.minus(Period.ofWeeks(5));
    final Instant end = NOW.plus(Period.ofWeeks(5));

    final TreeNode node = createDatedTreeNode("Test1", start, end);
    root.addNode(node);

    final TreeNode other = createDatedTreeNode("Test1", start, Instant.MAX);
    root.addNode(other);
    assertEquals(node, root.getExactNode(node).get());

    final Range<Instant> range = new Range<>(start, Instant.MAX);
    assertEquals(range, node.getDateRange());
}
 
Example 14
Project: swblocks-decisiontree   File: TimeSliceCacheConcurrencyTest.java   Source Code and License 6 votes vote down vote up
@Test
@Concurrent(count = 20)
@Repeating(repetition = 200)
public void cacheAccess() {
    final Instant now = Instant.now();
    final int start = (int) (Math.random() * 100);
    final int end = start + (int) (Math.random() * 100);

    final Range<Instant> dateRange = new Range<>(now.plus(Period.ofWeeks(start)), now.plus(Period.ofWeeks(end)));
    final TreeNode node = NodeSupplier.createTreeNode(
            new StringDriver(UUID.randomUUID().toString()), NodeSupplier.ROOT_NODE_LEVEL).get();

    final Optional<TreeNode> treeNode = Optional.of(node);
    this.cache.put(dateRange, treeNode);

    for (final Range<Instant> dr : this.cache.keys()) {
        this.cache.get(Optional.of(dr));
    }

    this.cache.get(Optional.of(dateRange));
}
 
Example 15
Project: openjdk-jdk10   File: TCKDateTimeParseResolver.java   Source Code and License 6 votes vote down vote up
@Test(dataProvider="resolveSecondOfDay")
public void test_resolveSecondOfDay(ResolverStyle style, long value, Integer expectedSecond, int expectedDays) {
    String str = Long.toString(value);
    DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(SECOND_OF_DAY).toFormatter();

    if (expectedSecond != null) {
        TemporalAccessor accessor = f.withResolverStyle(style).parse(str);
        assertEquals(accessor.query(TemporalQueries.localDate()), null);
        assertEquals(accessor.query(TemporalQueries.localTime()), LocalTime.ofSecondOfDay(expectedSecond));
        assertEquals(accessor.query(DateTimeFormatter.parsedExcessDays()), Period.ofDays(expectedDays));
    } else {
        try {
            f.withResolverStyle(style).parse(str);
            fail();
        } catch (DateTimeParseException ex) {
            // expected
        }
    }
}
 
Example 16
Project: swblocks-decisiontree   File: RuleChangeBuilderTest.java   Source Code and License 6 votes vote down vote up
@Test
public void createsChangeUsingDefaultPeriod() {
    addChange(null, NOW.plus(Period.ofWeeks(1)), true, true);

    final List<RuleChange> ruleChanges = this.builder.build();
    assertThat(ruleChanges, hasSize(4));

    final List<RuleChange> originals = getChangesByType(ruleChanges, Type.ORIGINAL);
    assertThat(originals, hasSize(3));

    assertOriginalSegmentsRemoved(originals);

    final List<RuleChange> newChanges = getChangesByType(ruleChanges, Type.NEW);
    assertThat(newChanges, hasSize(1));

    assertRuleChange(newChanges.get(0), Type.NEW, null, new UUID(0, 2),
            new String[]{"VOICE", "CME", "ED", "UK", "INDEX"}, Collections.singletonMap("Rate", "2.0"),
            null, DecisionTreeRule.MAX);
}
 
Example 17
Project: jdk8u-jdk   File: TCKDateTimeParseResolver.java   Source Code and License 6 votes vote down vote up
@Test(dataProvider="resolveFourToTime")
public void test_resolveThreeToTime(ResolverStyle style,
                                   long hour, long min, long sec, long nano, LocalTime expectedTime, Period excessPeriod) {
    DateTimeFormatter f = new DateTimeFormatterBuilder()
            .parseDefaulting(HOUR_OF_DAY, hour)
            .parseDefaulting(MINUTE_OF_HOUR, min)
            .parseDefaulting(SECOND_OF_MINUTE, sec).toFormatter();

    ResolverStyle[] styles = (style != null ? new ResolverStyle[] {style} : ResolverStyle.values());
    for (ResolverStyle s : styles) {
        if (expectedTime != null) {
            TemporalAccessor accessor = f.withResolverStyle(s).parse("");
            assertEquals(accessor.query(TemporalQueries.localDate()), null, "ResolverStyle: " + s);
            assertEquals(accessor.query(TemporalQueries.localTime()), expectedTime.minusNanos(nano), "ResolverStyle: " + s);
            assertEquals(accessor.query(DateTimeFormatter.parsedExcessDays()), excessPeriod, "ResolverStyle: " + s);
        } else {
            try {
                f.withResolverStyle(style).parse("");
                fail();
            } catch (DateTimeParseException ex) {
                // expected
            }
        }
    }
}
 
Example 18
Project: swblocks-decisiontree   File: RuleChangeBuilderTest.java   Source Code and License 6 votes vote down vote up
@Test
public void changeAddedToSecondSegmentAtStartAndFinishesWithinSecondSegmentUsesExistingOutputs() {
    addChange(NOW.plus(Period.ofWeeks(4)), NOW.plus(Period.ofWeeks(5)), true, false);
    final List<RuleChange> ruleChanges = this.builder.build();
    assertThat(ruleChanges, hasSize(3));

    final List<RuleChange> originals = getChangesByType(ruleChanges, Type.ORIGINAL);
    assertThat(originals, hasSize(1));

    assertRuleChange(originals.get(0), Type.ORIGINAL, new UUID(0, 2), new UUID(0, 2),
            new String[]{"EMAIL", "CME", "ED", "US", "INDEX"}, Collections.singletonMap("Rate", "1.2"),
            NOW.plus(Period.ofWeeks(4)), NOW.plus(Period.ofWeeks(6)));

    final List<RuleChange> newChanges = getChangesByType(ruleChanges, Type.NEW);
    assertThat(newChanges, hasSize(2));

    assertRuleChange(newChanges.get(0), Type.NEW, null, new UUID(0, 2),
            new String[]{"VOICE", "CME", "ED", "UK", "INDEX"}, Collections.singletonMap("Rate", "1.2"),
            NOW.plus(Period.ofWeeks(4)), NOW.plus(Period.ofWeeks(5)));

    assertRuleChange(newChanges.get(1), Type.NEW, null, new UUID(0, 2),
            new String[]{"EMAIL", "CME", "ED", "US", "INDEX"}, Collections.singletonMap("Rate", "1.2"),
            NOW.plus(Period.ofWeeks(5)), NOW.plus(Period.ofWeeks(6)));
}
 
Example 19
Project: swblocks-decisiontree   File: RuleChangeBuilderTest.java   Source Code and License 6 votes vote down vote up
@Test
public void changeAddedToSecondSegmentAfterStartAndFinishesAtSecondSegmentEnd() {
    addChange(NOW.plus(Period.ofWeeks(5)), NOW.plus(Period.ofWeeks(6)), true, true);
    final List<RuleChange> ruleChanges = this.builder.build();
    assertThat(ruleChanges, hasSize(3));

    final List<RuleChange> originals = getChangesByType(ruleChanges, Type.ORIGINAL);
    assertThat(originals, hasSize(1));

    assertRuleChange(originals.get(0), Type.ORIGINAL, new UUID(0, 2), new UUID(0, 2),
            new String[]{"EMAIL", "CME", "ED", "US", "INDEX"}, Collections.singletonMap("Rate", "1.2"),
            NOW.plus(Period.ofWeeks(4)), NOW.plus(Period.ofWeeks(6)));

    final List<RuleChange> newChanges = getChangesByType(ruleChanges, Type.NEW);
    assertThat(newChanges, hasSize(2));

    assertRuleChange(newChanges.get(0), Type.NEW, null, new UUID(0, 2),
            new String[]{"EMAIL", "CME", "ED", "US", "INDEX"}, Collections.singletonMap("Rate", "1.2"),
            NOW.plus(Period.ofWeeks(4)), NOW.plus(Period.ofWeeks(5)));

    assertRuleChange(newChanges.get(1), Type.NEW, null, new UUID(0, 2),
            new String[]{"VOICE", "CME", "ED", "UK", "INDEX"}, Collections.singletonMap("Rate", "2.0"),
            NOW.plus(Period.ofWeeks(5)), NOW.plus(Period.ofWeeks(6)));
}
 
Example 20
Project: swblocks-decisiontree   File: DatedEvaluatorTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testFourRules() {
    final Builder<RuleSetBuilder, DecisionTreeRuleSet> ruleSetBuilder = ruleSetBuilder();
    final Instant now = Instant.now();
    final Instant start = now.minus(Period.ofWeeks(1));
    final Instant finish = now.plus(Period.ofWeeks(4));

    CommisionRuleSetSupplier.addRule(ruleSetBuilder, "*", "CME", "*", "*", "INDEX", start, finish, 1L, "1.1");
    CommisionRuleSetSupplier.addRule(ruleSetBuilder, "*", "CME", "S&P", "*", "INDEX", start, finish, 2L, "1.2");
    CommisionRuleSetSupplier.addRule(ruleSetBuilder, "VOICE", "CME", "ED", "*", "RATE", start, finish, 3L, "1.4");
    CommisionRuleSetSupplier.addRule(ruleSetBuilder, "VOICE", "*", "*", "US", "*", start, finish, 4L, "1.5");

    final DecisionTreeRuleSet ruleSet = ruleSetBuilder.build();
    final TreeNode node = constructTree(ruleSet);
    Assert.assertNotNull(node);

    checkMatch(inputA, now, node, 3L);
    checkMatch(inputB, now, node, 4L);
    checkMatch(inputC, now, node, 4L);

    checkNoMatch(inputD, now, node);
    checkNoMatch(inputE, now, node);
    checkNoMatch(inputF, now, node);
}
 
Example 21
Project: mot-public-api   File: MotrReadServiceTest.java   Source Code and License 5 votes vote down vote up
@Test
public void getLatestMotTestByRegistration_ValidRegistration_ReturnsVehicle_WithoutManufactureDate() {

    final String registration = "AA00AAA";
    final LocalDateTime expiryDateTime = LocalDateTime.now().plus(Period.ofMonths(6));
    final Date expiryDate = Date.from(expiryDateTime.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.setMake(make);
    backendVehicle.setModel(model);
    backendVehicle.setPrimaryColour(primaryColour);
    backendVehicle.setSecondaryColour(secondaryColour);

    final MotTest backendTest = new MotTest();
    backendTest.setExpiryDate(expiryDate);
    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());
    assertNull("Manufacturing year was made up", 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());

}
 
Example 22
Project: bson-codecs-jsr310   File: PeriodCodec.java   Source Code and License 5 votes vote down vote up
@Override
public Period decode(
        BsonReader reader,
        DecoderContext decoderContext) {

    return parse(reader.readString());
}
 
Example 23
Project: swblocks-decisiontree   File: RuleGroupChangeBuilderTest.java   Source Code and License 5 votes vote down vote up
private void createRuleMapWithSingleRuleAndValueGroup(final Set<ValueGroup> groups) {
    final Builder<RuleSetBuilder, DecisionTreeRuleSet> ruleSetBuilder = RuleSetBuilder.creator("commissions",
            Arrays.asList("EXMETHOD", "EXCHANGE", "PRODUCT", "REGION", "ASSET"));
    ruleSetBuilder.with(RuleSetBuilder::groups, groups);

    ruleSetBuilder.with(RuleSetBuilder::rule, RuleBuilder.creator()
            .with(RuleBuilder::setId, new UUID(0, 1))
            .with(RuleBuilder::setCode, RULE_CODE)
            .with(RuleBuilder::input, Arrays.asList("VOICE", GroupDriver.VG_PREFIX + GROUP_ID, "ED", "US", "INDEX"))
            .with(RuleBuilder::output, Collections.singletonMap("Rate1", "1.1 "))
            .with(RuleBuilder::start, NOW.plus(Period.ofWeeks(2)))
            .with(RuleBuilder::end, NOW.plus(Period.ofWeeks(4))));

    ruleSetBuilder.with(RuleSetBuilder::rule, RuleBuilder.creator()
            .with(RuleBuilder::setId, new UUID(0, 2))
            .with(RuleBuilder::setCode, RULE_CODE)
            .with(RuleBuilder::input, Arrays.asList("EMAIL", GroupDriver.VG_PREFIX + GROUP_ID, "ED", "US", "INDEX"))
            .with(RuleBuilder::output, Collections.singletonMap("Rate1", "1.2"))
            .with(RuleBuilder::start, NOW.plus(Period.ofWeeks(4)))
            .with(RuleBuilder::end, NOW.plus(Period.ofWeeks(6))));

    ruleSetBuilder.with(RuleSetBuilder::rule, RuleBuilder.creator()
            .with(RuleBuilder::setId, new UUID(0, 3))
            .with(RuleBuilder::setCode, RULE_CODE)
            .with(RuleBuilder::input,
                    Arrays.asList("ELECTRONIC", GroupDriver.VG_PREFIX + GROUP_ID, "ED", "US", "INDEX"))
            .with(RuleBuilder::output, Collections.singletonMap("Rate1", "1.3"))
            .with(RuleBuilder::start, NOW.plus(Period.ofWeeks(6)))
            .with(RuleBuilder::end, NOW.plus(Period.ofWeeks(8))));

    ruleSetBuilder.with(RuleSetBuilder::rule, RuleBuilder.creator()
            .with(RuleBuilder::setId, new UUID(0, 4))
            .with(RuleBuilder::setCode, new UUID(2, 2))
            .with(RuleBuilder::input, Arrays.asList("EMAIL", "CME", "ED", "US", "INDEX"))
            .with(RuleBuilder::output, Collections.singletonMap("Rate1", "1.3"))
            .with(RuleBuilder::start, NOW.plus(Period.ofWeeks(2)))
            .with(RuleBuilder::end, NOW.plus(Period.ofWeeks(8))));

    this.ruleSet = ruleSetBuilder.build();
}
 
Example 24
Project: GitHub   File: PeriodTest.java   Source Code and License 5 votes vote down vote up
public void test_for_issue() throws Exception {
    VO vo = new VO();
    vo.setDate(Period.of(3, 2, 11));
    
    String text = JSON.toJSONString(vo);
    System.out.println(text);
    
    VO vo1 = JSON.parseObject(text, VO.class);
    
    Assert.assertEquals(vo.getDate(), vo1.getDate());
}
 
Example 25
Project: swblocks-decisiontree   File: ValueGroupRangeChangeBuilderTest.java   Source Code and License 5 votes vote down vote up
@Test(expected = IllegalStateException.class)
public void triesToAmendStartAndEndDateOfValueGroupDatesNotInChronologicalOrder() {
    builder.with(ValueGroupChangeBuilder::changeRange, new DateRange(NOW.plus(Period.ofWeeks(4)),
            NOW.plus(Period.ofWeeks(2))));

    builder.build();
}
 
Example 26
Project: openjdk-jdk10   File: TCKPeriod.java   Source Code and License 5 votes vote down vote up
@Test(dataProvider="between")
public void factory_between_LocalDate(int y1, int m1, int d1, int y2, int m2, int d2, int ye, int me, int de) {
    LocalDate start = LocalDate.of(y1, m1, d1);
    LocalDate end = LocalDate.of(y2, m2, d2);
    Period test = Period.between(start, end);
    assertPeriod(test, ye, me, de);
    //assertEquals(start.plus(test), end);
}
 
Example 27
Project: openjdk-jdk10   File: TCKChronoPeriod.java   Source Code and License 5 votes vote down vote up
@Test(dataProvider="calendars", expectedExceptions=DateTimeException.class)
public void test_plus_wrongChrono(Chronology chrono) {
    ChronoPeriod period = chrono.period(1, 2, 3);
    ChronoPeriod isoPeriod = Period.of(2, 3, 4);
    ChronoPeriod thaiPeriod = ThaiBuddhistChronology.INSTANCE.period(2, 3, 4);
    // one of these two will fail
    period.plus(isoPeriod);
    period.plus(thaiPeriod);
}
 
Example 28
Project: swblocks-decisiontree   File: ChangeTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testConstruction() {
    final Set<RuleChange> ruleChanges = new HashSet<>(1);

    final Instant start = NOW.minus(Period.ofWeeks(-1));
    final Instant end = start.plus(Period.ofWeeks(5));
    final DateRange range = new DateRange(start, end);
    final InputDriver[] drivers = getInputDriverArray("Test1", "Test2", "Test3");
    final Map<String, String> outputs = Collections.singletonMap("outputDriver", "result");
    final DecisionTreeRule rule =
            new DecisionTreeRule(BASE_ID, new UUID(0, 2), drivers, outputs, start, end);
    final RuleChange ruleChange = new RuleChange(Type.ORIGINAL, rule);

    ruleChanges.add(ruleChange);

    final Set<ValueGroupChange> valueGroupChanges = new HashSet<>();

    final List<String> valueGroupDrivers = Arrays.asList("Test1", "Test2", "Test3");
    final ValueGroup valueGroup = new ValueGroup(BASE_ID, "TestValueGroup", valueGroupDrivers, range);
    final ValueGroupChange valueGroupChange = new ValueGroupChange(Type.ORIGINAL, valueGroup);

    valueGroupChanges.add(valueGroupChange);

    final UUID id = new UUID(0, 2);
    final Instant initiatorTime = NOW;
    final Instant authoriserTime = initiatorTime.plus(Period.ofWeeks(1));

    final Audit audit = new Audit("USER1", initiatorTime, "USER2", authoriserTime);
    final Change change = new Change(id, "TEST-RULESET", NOW, CHANGE_RANGE, audit, ruleChanges, valueGroupChanges);
    setBean(change);

    this.injectedValues.put("id", id);
    this.injectedValues.put("ruleSetName", "TEST-RULESET");
    this.injectedValues.put("ruleChanges", ruleChanges);
    this.injectedValues.put("valueGroupChanges", valueGroupChanges);
    this.injectedValues.put("activationTime", NOW);
    this.injectedValues.put("changeRange", CHANGE_RANGE);

    JblTestClassUtils.assertGetterCorrectForConstructorInjection(this.injectedValues, getBean());
}
 
Example 29
Project: daelic   File: GroupByV1Context.java   Source Code and License 5 votes vote down vote up
GroupByV1Context(Integer timeout, Integer priority, String queryId, Boolean useCache, Boolean populateCache,
                 Boolean bySegment, Boolean finalize, Period chunkPeriod, Boolean groupByIsSingleThreaded,
                 Integer maxIntermediateRows, Integer maxResults, Boolean useOffHeap) {

    super(timeout, priority, queryId, useCache, populateCache, bySegment, finalize, chunkPeriod);

    this.groupByIsSingleThreaded = groupByIsSingleThreaded;
    this.maxIntermediateRows = maxIntermediateRows;
    this.maxResults = maxResults;
    this.useOffHeap = useOffHeap;
}
 
Example 30
Project: sentry   File: TimeMappingUtil.java   Source Code and License 5 votes vote down vote up
public String periodToString(Period in) {
    if (in == null) {
        return "";
    } else {
        return in.toString();
    }
}
 
Example 31
Project: openjdk-jdk10   File: TCKLocalDate.java   Source Code and License 5 votes vote down vote up
@Test(dataProvider="until")
public void test_periodUntil_LocalDate(int y1, int m1, int d1, int y2, int m2, int d2, int ye, int me, int de) {
    LocalDate start = LocalDate.of(y1, m1, d1);
    LocalDate end = LocalDate.of(y2, m2, d2);
    Period test = start.until(end);
    assertEquals(test.getYears(), ye);
    assertEquals(test.getMonths(), me);
    assertEquals(test.getDays(), de);
}
 
Example 32
Project: openjdk-jdk10   File: TCKPeriod.java   Source Code and License 5 votes vote down vote up
@Test
public void factory_ofWeeks_int() {
    assertPeriod(Period.ofWeeks(0), 0, 0, 0);
    assertPeriod(Period.ofWeeks(1), 0, 0, 7);
    assertPeriod(Period.ofWeeks(234), 0, 0, 234 * 7);
    assertPeriod(Period.ofWeeks(-100), 0, 0, -100 * 7);
    assertPeriod(Period.ofWeeks(Integer.MAX_VALUE / 7), 0, 0, (Integer.MAX_VALUE / 7) * 7);
    assertPeriod(Period.ofWeeks(Integer.MIN_VALUE / 7), 0, 0, (Integer.MIN_VALUE / 7) * 7);
}
 
Example 33
Project: openjdk-jdk10   File: TCKPeriod.java   Source Code and License 5 votes vote down vote up
@Test
public void test_plusMonths() {
    assertPeriod(Period.of(1, 2, 3).plusMonths(0), 1, 2, 3);
    assertPeriod(Period.of(1, 2, 3).plusMonths(10), 1, 12, 3);
    assertPeriod(Period.of(1, 2, 3).plusMonths(-10), 1, -8, 3);
    assertPeriod(Period.of(1, 2, 3).plusMonths(-2), 1, 0, 3);

    assertPeriod(Period.of(1, 2, 3).plus(Period.ofMonths(0)), 1, 2, 3);
    assertPeriod(Period.of(1, 2, 3).plus(Period.ofMonths(10)), 1, 12, 3);
    assertPeriod(Period.of(1, 2, 3).plus(Period.ofMonths(-10)), 1, -8, 3);
    assertPeriod(Period.of(1, 2, 3).plus(Period.ofMonths(-2)), 1, 0, 3);
}
 
Example 34
Project: openjdk-jdk10   File: TCKPeriod.java   Source Code and License 5 votes vote down vote up
@Test
public void factory_of_ints() {
    assertPeriod(Period.of(1, 2, 3), 1, 2, 3);
    assertPeriod(Period.of(0, 2, 3), 0, 2, 3);
    assertPeriod(Period.of(1, 0, 0), 1, 0, 0);
    assertPeriod(Period.of(0, 0, 0), 0, 0, 0);
    assertPeriod(Period.of(-1, -2, -3), -1, -2, -3);
}
 
Example 35
Project: openjdk-jdk10   File: TCKPeriod.java   Source Code and License 5 votes vote down vote up
@DataProvider(name="toStringAndParse")
Object[][] data_toString() {
    return new Object[][] {
            {Period.ZERO, "P0D"},
            {Period.ofDays(0), "P0D"},
            {Period.ofYears(1), "P1Y"},
            {Period.ofMonths(1), "P1M"},
            {Period.ofDays(1), "P1D"},
            {Period.of(1, 2, 0), "P1Y2M"},
            {Period.of(0, 2, 3), "P2M3D"},
            {Period.of(1, 2, 3), "P1Y2M3D"},
    };
}
 
Example 36
Project: swblocks-decisiontree   File: ChangeTest.java   Source Code and License 5 votes vote down vote up
@Test
public void removeValueGroup() {
    testConstruction();
    final Instant start = NOW.minus(Period.ofWeeks(-1));
    final Instant end = start.plus(Period.ofWeeks(5));
    final DateRange range = new DateRange(start, end);
    final List<String> drivers = Arrays.asList("Test5", "Test6", "Test7");
    final ValueGroup valueGroup = new ValueGroup(ADDED_ID, "TestValueGroup", drivers, range);
    final ValueGroupChange valueGroupChange = new ValueGroupChange(Type.NEW, valueGroup);

    getBean().addValueGroupChange(valueGroupChange);

    ValueGroup valueGroupForTest = new ValueGroup(UNKNOWN_ID, "TestValueGroup", drivers, range);
    ValueGroupChange valueGroupChangeForTest = new ValueGroupChange(Type.NEW, valueGroupForTest);
    getBean().removeValueGroupChange(valueGroupChangeForTest);
    assertThat(getBean().getValueGroupChanges(), hasSize(2));
    assertThat(getBean().getRuleChanges(), hasSize(1));

    valueGroupForTest = new ValueGroup(UNKNOWN_ID, "TestValueGroup", drivers, range);
    valueGroupChangeForTest = new ValueGroupChange(Type.ORIGINAL, valueGroupForTest);
    getBean().removeValueGroupChange(valueGroupChangeForTest);
    assertThat(getBean().getValueGroupChanges(), hasSize(2));
    assertThat(getBean().getRuleChanges(), hasSize(1));

    valueGroupForTest = new ValueGroup(ADDED_ID, "TestValueGroup", drivers, range);
    valueGroupChangeForTest = new ValueGroupChange(Type.ORIGINAL, valueGroupForTest);
    getBean().removeValueGroupChange(valueGroupChangeForTest);
    assertThat(getBean().getValueGroupChanges(), hasSize(2));
    assertThat(getBean().getRuleChanges(), hasSize(1));

    valueGroupForTest = new ValueGroup(ADDED_ID, "TestValueGroup", drivers, range);
    valueGroupChangeForTest = new ValueGroupChange(Type.NEW, valueGroupForTest);
    getBean().removeValueGroupChange(valueGroupChangeForTest);
    assertThat(getBean().getValueGroupChanges(), hasSize(1));
    assertThat(getBean().getRuleChanges(), hasSize(1));
}
 
Example 37
Project: OpenJSharp   File: Parsed.java   Source Code and License 5 votes vote down vote up
private void updateCheckConflict(LocalTime timeToSet, Period periodToSet) {
    if (time != null) {
        if (time.equals(timeToSet) == false) {
            throw new DateTimeException("Conflict found: Fields resolved to different times: " + time + " " + timeToSet);
        }
        if (excessDays.isZero() == false && periodToSet.isZero() == false && excessDays.equals(periodToSet) == false) {
            throw new DateTimeException("Conflict found: Fields resolved to different excess periods: " + excessDays + " " + periodToSet);
        } else {
            excessDays = periodToSet;
        }
    } else {
        time = timeToSet;
        excessDays = periodToSet;
    }
}
 
Example 38
Project: jdk8u-jdk   File: TCKChronoPeriod.java   Source Code and License 5 votes vote down vote up
@Test(dataProvider="calendars", expectedExceptions=DateTimeException.class)
public void test_minus_wrongChrono(Chronology chrono) {
    ChronoPeriod period = chrono.period(1, 2, 3);
    ChronoPeriod isoPeriod = Period.of(2, 3, 4);
    ChronoPeriod thaiPeriod = ThaiBuddhistChronology.INSTANCE.period(2, 3, 4);
    // one of these two will fail
    period.minus(isoPeriod);
    period.minus(thaiPeriod);
}
 
Example 39
Project: swblocks-decisiontree   File: ChangeBuilderTest.java   Source Code and License 5 votes vote down vote up
static DecisionTreeRuleSet getRuleSet(final Instant now) {
    final Builder<RuleSetBuilder, DecisionTreeRuleSet> ruleSetBuilder = RuleSetBuilder.creator("commissions",
            Arrays.asList("VOICE", "CME", "ED", "US", "Rate"));
    ruleSetBuilder.with(RuleSetBuilder::rule, RuleBuilder.creator()
            .with(RuleBuilder::setId, new UUID(0, 1))
            .with(RuleBuilder::setCode, new UUID(0, 2))
            .with(RuleBuilder::input, Arrays.asList("VOICE", "CME", "ED", "US", "INDEX"))
            .with(RuleBuilder::output, Collections.singletonMap("Rate", "1.1"))
            .with(RuleBuilder::start, now.plus(Period.ofWeeks(2)))
            .with(RuleBuilder::end, now.plus(Period.ofWeeks(4)).minusMillis(1L)));

    ruleSetBuilder.with(RuleSetBuilder::rule, RuleBuilder.creator()
            .with(RuleBuilder::setId, new UUID(0, 2))
            .with(RuleBuilder::setCode, new UUID(0, 2))
            .with(RuleBuilder::input, Arrays.asList("EMAIL", "CME", "ED", "US", "INDEX"))
            .with(RuleBuilder::output, Collections.singletonMap("Rate", "1.2"))
            .with(RuleBuilder::start, now.plus(Period.ofWeeks(4)))
            .with(RuleBuilder::end, now.plus(Period.ofWeeks(6)).minusMillis(1L)));

    ruleSetBuilder.with(RuleSetBuilder::rule, RuleBuilder.creator()
            .with(RuleBuilder::setId, new UUID(0, 3))
            .with(RuleBuilder::setCode, new UUID(0, 2))
            .with(RuleBuilder::input, Arrays.asList("ELECTRONIC", "CME", "ED", "US", "INDEX"))
            .with(RuleBuilder::output, Collections.singletonMap("Rate", "1.3"))
            .with(RuleBuilder::start, now.plus(Period.ofWeeks(6)))
            .with(RuleBuilder::end, now.plus(Period.ofWeeks(8))));

    return ruleSetBuilder.build();
}
 
Example 40
Project: openjdk-jdk10   File: TCKYear.java   Source Code and License 5 votes vote down vote up
@DataProvider(name="plusInvalidUnit")
Object[][] data_plusInvalidUnit() {
    return new Object[][] {
            {Period.of(0, 1, 0)},
            {Period.of(0, 0, 1)},
            {Period.of(0, 1, 1)},
            {Period.of(1, 1, 1)},
            {Duration.ofDays(1)},
            {Duration.ofHours(1)},
            {Duration.ofMinutes(1)},
            {Duration.ofSeconds(1)},
    };
}