Skip to content

Commit

Permalink
Add tests for NativeMappedConverter#defaultValue
Browse files Browse the repository at this point in the history
  • Loading branch information
koraktor committed Aug 30, 2018
1 parent 720a0e0 commit 21f2b31
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
26 changes: 26 additions & 0 deletions test/com/sun/jna/NativeMappedTestClass.java
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;
}
}
37 changes: 37 additions & 0 deletions test/com/sun/jna/NativedMappedConverterTest.java
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;
}
}

}

0 comments on commit 21f2b31

Please sign in to comment.