parent
b43b04e37e
commit
80d9fc8263
@ -0,0 +1,11 @@ |
||||
package de.kreth.vaadin.clubhelper; |
||||
|
||||
import org.junit.platform.runner.JUnitPlatform; |
||||
import org.junit.platform.suite.api.SelectPackages; |
||||
import org.junit.runner.RunWith; |
||||
|
||||
@RunWith(JUnitPlatform.class) |
||||
@SelectPackages("de.kreth.vaadin.clubhelper") |
||||
public class AllTests { |
||||
|
||||
} |
||||
@ -0,0 +1,12 @@ |
||||
package de.kreth.vaadin.clubhelper; |
||||
|
||||
import org.junit.platform.runner.JUnitPlatform; |
||||
import org.junit.platform.suite.api.ExcludeTags; |
||||
import org.junit.platform.suite.api.SelectPackages; |
||||
import org.junit.runner.RunWith; |
||||
|
||||
@RunWith(JUnitPlatform.class) |
||||
@SelectPackages("de.kreth.vaadin.clubhelper") |
||||
@ExcludeTags("spring") |
||||
public class FastTestsOnly { |
||||
} |
||||
@ -0,0 +1,48 @@ |
||||
package de.kreth.vaadin.clubhelper.vaadinclubhelper.business; |
||||
|
||||
import static org.junit.Assert.assertNotNull; |
||||
import static org.junit.jupiter.api.Assertions.assertEquals; |
||||
|
||||
import java.time.ZoneId; |
||||
import java.time.ZonedDateTime; |
||||
import java.time.temporal.ChronoField; |
||||
import java.util.Calendar; |
||||
import java.util.Date; |
||||
import java.util.GregorianCalendar; |
||||
|
||||
import org.junit.jupiter.api.BeforeEach; |
||||
import org.junit.jupiter.api.Test; |
||||
|
||||
class ZonedDateTimeAttributeConverterTest { |
||||
|
||||
private ZonedDateTimeAttributeConverter converter; |
||||
|
||||
@BeforeEach |
||||
void setUp() throws Exception { |
||||
this.converter = new ZonedDateTimeAttributeConverter(); |
||||
} |
||||
|
||||
@Test |
||||
void testZonedToDate() { |
||||
ZonedDateTime zonedDatetime = ZonedDateTime.of(2019, 4, 25, 21, 43, 13, 0, ZoneId.systemDefault()); |
||||
Date actualDate = converter.convertToDatabaseColumn(zonedDatetime); |
||||
GregorianCalendar calendar = new GregorianCalendar(); |
||||
calendar.setTime(actualDate); |
||||
assertEquals(21, calendar.get(Calendar.HOUR_OF_DAY)); |
||||
assertEquals(43, calendar.get(Calendar.MINUTE)); |
||||
assertEquals(13, calendar.get(Calendar.SECOND)); |
||||
assertEquals(0, calendar.get(Calendar.MILLISECOND)); |
||||
} |
||||
|
||||
@Test |
||||
void testDateToZoned() { |
||||
GregorianCalendar calendar = new GregorianCalendar(); |
||||
ZonedDateTime zonedDateTime = converter.convertToEntityAttribute(calendar.getTime()); |
||||
assertNotNull(zonedDateTime); |
||||
assertEquals(calendar.get(Calendar.HOUR_OF_DAY), zonedDateTime.get(ChronoField.HOUR_OF_DAY)); |
||||
assertEquals(calendar.get(Calendar.MINUTE), zonedDateTime.get(ChronoField.MINUTE_OF_HOUR)); |
||||
assertEquals(calendar.get(Calendar.SECOND), zonedDateTime.get(ChronoField.SECOND_OF_MINUTE)); |
||||
assertEquals(calendar.get(Calendar.MILLISECOND), zonedDateTime.get(ChronoField.MILLI_OF_SECOND)); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,43 @@ |
||||
package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components; |
||||
|
||||
import static org.junit.Assert.assertTrue; |
||||
import static org.junit.jupiter.api.Assertions.assertFalse; |
||||
|
||||
import java.util.ArrayList; |
||||
|
||||
import org.junit.jupiter.api.BeforeEach; |
||||
import org.junit.jupiter.api.Test; |
||||
|
||||
import com.vaadin.data.ValidationResult; |
||||
|
||||
import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.GroupDef; |
||||
import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Person; |
||||
|
||||
class PersonGroupValidatorTest { |
||||
|
||||
private PersonGroupValidator validator; |
||||
|
||||
private Person person; |
||||
|
||||
@BeforeEach |
||||
void setUp() throws Exception { |
||||
validator = new PersonGroupValidator(); |
||||
person = new Person(); |
||||
} |
||||
|
||||
@Test |
||||
void testError() { |
||||
ValidationResult result = validator.apply(person, null); |
||||
assertTrue(result.isError()); |
||||
} |
||||
|
||||
@Test |
||||
void testOk() { |
||||
GroupDef group = new GroupDef(); |
||||
group.setPersongroups(new ArrayList<>()); |
||||
person.add(group); |
||||
ValidationResult result = validator.apply(person, null); |
||||
assertFalse(result.isError()); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,53 @@ |
||||
package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components; |
||||
|
||||
import static org.junit.Assert.assertNotNull; |
||||
import static org.junit.Assert.assertNull; |
||||
import static org.junit.jupiter.api.Assertions.assertEquals; |
||||
import static org.junit.jupiter.api.Assertions.assertFalse; |
||||
|
||||
import java.time.LocalDate; |
||||
import java.time.ZonedDateTime; |
||||
import java.time.temporal.ChronoField; |
||||
|
||||
import org.junit.jupiter.api.BeforeEach; |
||||
import org.junit.jupiter.api.Test; |
||||
|
||||
import com.vaadin.data.Result; |
||||
|
||||
class ZonedDateTimeConverterTest { |
||||
|
||||
private ZonedDateTimeConverter converter; |
||||
|
||||
@BeforeEach |
||||
void setUp() throws Exception { |
||||
converter = new ZonedDateTimeConverter(); |
||||
} |
||||
|
||||
@Test |
||||
void testConvertToModelNull() { |
||||
Result<ZonedDateTime> result = converter.convertToModel(null, null); |
||||
assertNotNull(result); |
||||
assertFalse(result.isError()); |
||||
assertNull(result.getOrThrow(msg -> new RuntimeException(msg))); |
||||
} |
||||
|
||||
@Test |
||||
void testConvertToModel() { |
||||
LocalDate now = LocalDate.now(); |
||||
Result<ZonedDateTime> result = converter.convertToModel(now, null); |
||||
assertNotNull(result); |
||||
assertFalse(result.isError()); |
||||
ZonedDateTime actual = result.getOrThrow(msg -> new RuntimeException(msg)); |
||||
assertEquals(0, actual.get(ChronoField.HOUR_OF_DAY)); |
||||
assertEquals(0, actual.get(ChronoField.MINUTE_OF_DAY)); |
||||
assertEquals(0, actual.get(ChronoField.SECOND_OF_MINUTE)); |
||||
assertEquals(0, actual.get(ChronoField.MILLI_OF_SECOND)); |
||||
} |
||||
|
||||
@Test |
||||
void testConvertToPresentation() { |
||||
ZonedDateTime now = ZonedDateTime.now(); |
||||
assertEquals(now.toLocalDate(), converter.convertToPresentation(now, null)); |
||||
} |
||||
|
||||
} |
||||
Loading…
Reference in new issue