Skip to content

Commit

Permalink
Add tests for auto-detecting mybatis-typehandlers-jsr310
Browse files Browse the repository at this point in the history
  • Loading branch information
kazuki43zoo committed Jan 5, 2017
1 parent 7232c7e commit 8fc78a7
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-typehandlers-jsr310</artifactId>
<version>1.0.2</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* Copyright 2009-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.ibatis.type.usesjava8;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.type.*;
import org.hamcrest.core.IsInstanceOf;
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.*;
import static org.hamcrest.core.IsInstanceOf.*;

/**
* Tests for auto-detect type handlers of mybatis-typehandlers-jsr310.
*
* @author Kazuki Shimizu
*/
public class Jsr310TypeHandlerRegistryTest {

private TypeHandlerRegistry typeHandlerRegistry;

@Before
public void setup() {
typeHandlerRegistry = new TypeHandlerRegistry();
}

@Test
public void testFor_v1_0_0() throws ClassNotFoundException {
assertThat(getTypeHandler("java.time.Instant"), instanceOf(InstantTypeHandler.class));
assertThat(getTypeHandler("java.time.LocalDateTime"), instanceOf(LocalDateTimeTypeHandler.class));
assertThat(getTypeHandler("java.time.LocalDate"), instanceOf(LocalDateTypeHandler.class));
assertThat(getTypeHandler("java.time.LocalTime"), instanceOf(LocalTimeTypeHandler.class));
assertThat(getTypeHandler("java.time.OffsetDateTime"), instanceOf(OffsetDateTimeTypeHandler.class));
assertThat(getTypeHandler("java.time.OffsetTime"), instanceOf(OffsetTimeTypeHandler.class));
assertThat(getTypeHandler("java.time.ZonedDateTime"), instanceOf(ZonedDateTimeTypeHandler.class));
}

@Test
public void testFor_v1_0_1() throws ClassNotFoundException {
assertThat(getTypeHandler("java.time.Month"), instanceOf(MonthTypeHandler.class));
assertThat(getTypeHandler("java.time.Year"), instanceOf(YearTypeHandler.class));
}

@Test
public void testFor_v1_0_2() throws ClassNotFoundException {
assertThat(getTypeHandler("java.time.YearMonth"), instanceOf(YearMonthTypeHandler.class));
assertThat(getTypeHandler("java.time.chrono.JapaneseDate"), instanceOf(JapaneseDateTypeHandler.class));
}

private TypeHandler<?> getTypeHandler(String fqcn) throws ClassNotFoundException {
return typeHandlerRegistry.getTypeHandler(Resources.classForName(fqcn));
}

}

0 comments on commit 8fc78a7

Please sign in to comment.