-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for NativeMappedConverter#defaultValue
- Loading branch information
Showing
2 changed files
with
63 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.sun.jna; | ||
|
||
class NativeMappedTestClass implements NativeMapped { | ||
|
||
private String name; | ||
|
||
public NativeMappedTestClass() {} | ||
|
||
@Override | ||
public Object fromNative(Object nativeValue, FromNativeContext context) { | ||
NativeMappedTestClass object = new NativeMappedTestClass(); | ||
object.name = (String) nativeValue; | ||
|
||
return object; | ||
} | ||
|
||
@Override | ||
public Object toNative() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public Class<?> nativeType() { | ||
return String.class; | ||
} | ||
} |
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,37 @@ | ||
package com.sun.jna; | ||
|
||
import junit.framework.TestCase; | ||
|
||
public class NativedMappedConverterTest extends TestCase { | ||
|
||
public void testDefaultValueForClass() { | ||
NativeMappedConverter converter = new NativeMappedConverter(NativeMappedTestClass.class); | ||
|
||
assertTrue(converter.defaultValue() instanceof NativeMappedTestClass); | ||
} | ||
|
||
public void testDefaultValueForEnum() { | ||
NativeMappedConverter converter = new NativeMappedConverter(TestEnum.class); | ||
|
||
assertSame(converter.defaultValue(), TestEnum.VALUE1); | ||
} | ||
|
||
private enum TestEnum implements NativeMapped { VALUE1, VALUE2; | ||
|
||
@Override | ||
public Object fromNative(Object nativeValue, FromNativeContext context) { | ||
return values()[(Integer) nativeValue]; | ||
} | ||
|
||
@Override | ||
public Object toNative() { | ||
return ordinal(); | ||
} | ||
|
||
@Override | ||
public Class<?> nativeType() { | ||
return Integer.class; | ||
} | ||
} | ||
|
||
} |