-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7322001
commit d03b6d9
Showing
11 changed files
with
129 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
core/src/test/java/org/unitsheet/test/DummyTypeConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.unitsheet.test; | ||
|
||
import org.unitsheet.api.types.TypeConverter; | ||
|
||
public class DummyTypeConverter implements TypeConverter { | ||
|
||
@Override | ||
public <T> T convert(Object source, Class<T> destinationClass) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
core/src/test/java/org/unitsheet/types/ObjectConverterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package org.unitsheet.types; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.runners.MockitoJUnitRunner; | ||
import org.unitsheet.api.types.TypeConverter; | ||
import org.unitsheet.types.typeconverters.BooleanTypeConverter; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.fest.assertions.Assertions.assertThat; | ||
import static org.mockito.Mockito.when; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class ObjectConverterTest { | ||
|
||
@InjectMocks | ||
private ObjectConverter underTest; | ||
|
||
@Mock private TypeConverterRegistry typeConverterRegistry; | ||
private List<TypeConverter> typeConverters = new ArrayList<>(); | ||
|
||
@Before | ||
public void setUp() { | ||
typeConverters.clear(); | ||
when(typeConverterRegistry.getTypeConverters()).thenReturn(typeConverters); | ||
} | ||
|
||
@Test | ||
public void checkConvertTypeIgnoresNull() { | ||
// given | ||
String convertFrom = null; | ||
|
||
// when | ||
Number result = underTest.convertType(convertFrom, Number.class); | ||
|
||
// then | ||
assertThat(result).isNull(); | ||
} | ||
|
||
@Test | ||
public void checkConvertTypeToSameTypeWorksForUnregisteredType() { | ||
/* | ||
given | ||
*/ | ||
class Banana {} | ||
Banana convertFrom = new Banana(); | ||
|
||
// when | ||
Banana result = underTest.convertType(convertFrom, Banana.class); | ||
|
||
// then | ||
assertThat(result).isInstanceOf(Banana.class); | ||
} | ||
|
||
@Test | ||
public void checkConvertUsingRealTypeConverterReturnsResult() { | ||
/* | ||
given | ||
*/ | ||
typeConverters.add(new BooleanTypeConverter()); | ||
String convertFrom = "true"; | ||
|
||
// when | ||
Boolean result = underTest.convertType(convertFrom, Boolean.class); | ||
|
||
// then | ||
assertThat(result).isTrue(); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
core/src/test/java/org/unitsheet/types/PluginTypeConverterLoaderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.unitsheet.types; | ||
|
||
import org.junit.Test; | ||
import org.unitsheet.api.types.TypeConverter; | ||
import org.unitsheet.test.DummyTypeConverter; | ||
|
||
import java.util.List; | ||
|
||
import static org.fest.assertions.Assertions.assertThat; | ||
|
||
public class PluginTypeConverterLoaderTest { | ||
|
||
private PluginTypeConverterLoader underTest = new PluginTypeConverterLoader(); | ||
|
||
@Test | ||
public void checkLoadTypeConvertersFromPluginsFindDummyTypeConverter() { | ||
List<TypeConverter> typeConverters = underTest.loadTypeConvertersFromPlugins(); | ||
|
||
assertThat(typeConverters).hasSize(1); | ||
assertThat(typeConverters.get(0)).isInstanceOf(DummyTypeConverter.class); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
core/src/test/resources/META-INF/services/org.unitsheet.api.types.TypeConverter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.unitsheet.test.DummyTypeConverter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters