Skip to content

Commit

Permalink
Add unit test for Version conversion.
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1823573 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
bosschaert committed Feb 8, 2018
1 parent 1673d2c commit 12041a6
Showing 1 changed file with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.osgi.framework.Version;
import org.osgi.util.converter.MyDTO.Count;
import org.osgi.util.converter.MyEmbeddedDTO.Alpha;

Expand All @@ -89,6 +90,15 @@ public void tearDown() {
converter = null;
}

@Test
public void testVersion() {
Version v =new Version(1,2,3,"qualifier");
Converter c = Converters.standardConverter();
String s = c.convert(v).to(String.class);
Version v2 = c.convert(s).to(Version.class);
assertEquals(v, v2);
}

@Test
public void testSimpleConversions() {
// Conversions to String
Expand Down Expand Up @@ -752,9 +762,9 @@ public void testDTOWithGenerics() {
@Test
public void testMapToDTOWithGenerics() {
Map<String, Object> dto = new HashMap<>();

dto.put("longList", Arrays.asList((short)999, "1000"));

Map<String, Object> dtoMap = new LinkedHashMap<>();
dto.put("dtoMap", dtoMap);

Expand Down Expand Up @@ -798,14 +808,14 @@ public void testMapToDTOWithGenericVariables() {
dto.put("set", new HashSet<>(Arrays.asList("foo", (int) 'o', 'o')));
dto.put("raw", "1234");
dto.put("array", Arrays.asList("foo", (int) 'o', 'o'));
MyGenericDTOWithVariables<Character> converted =

MyGenericDTOWithVariables<Character> converted =
converter.convert(dto).to(new TypeReference<MyGenericDTOWithVariables<Character>>() {});
assertEquals(Character.valueOf('1'), converted.raw);
assertArrayEquals(new Character[] {'f', 'o', 'o'}, converted.array);
assertEquals(new HashSet<Character>(Arrays.asList('f', 'o')), converted.set);
}

@Test
public void testMapToDTOWithSurplusMapFiels() {
Map<String, String> m = new HashMap<>();
Expand Down Expand Up @@ -1191,7 +1201,7 @@ public void testLongArrayToLongCollection() {
assertEquals(la[i], it.next());
}
}

@Test
public void testMapToInterfaceWithGenerics() {
Map<String, Object> dto = new HashMap<>();
Expand All @@ -1207,8 +1217,8 @@ public void testMapToInterfaceWithGenericVariables() {
dto.put("set", new HashSet<>(Arrays.asList("foo", (int) 'o', 'o')));
dto.put("raw", "1234");
dto.put("array", Arrays.asList("foo", (int) 'o', 'o'));
MyGenericInterfaceWithVariables<Character> converted =

MyGenericInterfaceWithVariables<Character> converted =
converter.convert(dto).to(new TypeReference<MyGenericInterfaceWithVariables<Character>>() {});
assertEquals(Character.valueOf('1'), converted.raw());
assertArrayEquals(new Character[] {'f', 'o', 'o'}, converted.array());
Expand Down

0 comments on commit 12041a6

Please sign in to comment.