### Question:
CalendarPeriod { public static CalendarPeriod.Field fromUnitString(String udunit) { udunit = udunit.trim(); udunit = udunit.toLowerCase(); if (udunit.equals("s")) return Field.Second; if (udunit.equals("ms")) return Field.Millisec; if (udunit.endsWith("s")) udunit = udunit.substring(0, udunit.length() - 1); switch (udunit) { case "second": case "sec": return Field.Second; case "millisecond": case "millisec": case "msec": return Field.Millisec; case "minute": case "min": return Field.Minute; case "hour": case "hr": case "h": return Field.Hour; case "day": case "d": return Field.Day; case "month": case "mon": return Field.Month; case "year": case "yr": return Field.Year; default: throw new IllegalArgumentException("cant convert " + udunit + " to CalendarPeriod"); } } private  CalendarPeriod(int value, Field field); static CalendarPeriod.Field fromUnitString(String udunit); static CalendarPeriod of(int value, Field field); static CalendarPeriod of(String udunit); @Deprecated static CalendarPeriod of(TimeDuration td); CalendarPeriod multiply(int value); int getValue(); Field getField(); @Deprecated double getConvertFactor(CalendarPeriod from); @Deprecated double getValueInMillisecs(); @Deprecated int subtract(CalendarDate start, CalendarDate end); int getOffset(CalendarDate start, CalendarDate end); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); static final CalendarPeriod Hour; }### Answer:
@Test public void testFromUnitString() { CalendarPeriod.Field fld = CalendarPeriod.fromUnitString("days"); assertThat(fld).isEqualTo(Field.Day); CalendarPeriod period1 = CalendarPeriod.of("days"); assertThat(period1.getField()).isEqualTo(Field.Day); assertThat(period1.getValue()).isEqualTo(1); CalendarPeriod period = CalendarPeriod.of("11 months"); assertThat(period.getField()).isEqualTo(Field.Month); assertThat(period.getValue()).isEqualTo(11); String val = null; assertThat(CalendarPeriod.of(val)).isNull(); assertThat(CalendarPeriod.of("")).isNull(); assertThat(CalendarPeriod.of("11 months from now")).isNull(); assertThat(CalendarPeriod.of("months from now")).isNull(); }