forked from rgushel/protobuf-converter
-
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.
include declared fields of domain subclasses while converting
- Loading branch information
Showing
6 changed files
with
719 additions
and
6 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
29 changes: 29 additions & 0 deletions
29
src/test/java/net/badata/protobuf/converter/ConverterIncludeSubClassFieldsTest.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,29 @@ | ||
package net.badata.protobuf.converter; | ||
|
||
|
||
import net.badata.protobuf.converter.domain.Coffee; | ||
import net.badata.protobuf.converter.proto.LiquidProto; | ||
import org.junit.Test; | ||
|
||
import static junit.framework.Assert.assertEquals; | ||
|
||
|
||
public class ConverterIncludeSubClassFieldsTest { | ||
|
||
@Test | ||
public void testDomainToProtobuf() { | ||
Coffee coffee = new Coffee(); | ||
coffee.setMlVolume(100); | ||
coffee.setTemperature(40); | ||
coffee.setSwirling(true); | ||
coffee.setClockwise(false); | ||
|
||
LiquidProto.Coffee coffeeProto = Converter.create().toProtobuf(LiquidProto.Coffee.class,coffee); | ||
|
||
assertEquals(coffee.getMlVolume(), coffeeProto.getMlVolume()); | ||
assertEquals(coffee.getTemperature(), coffeeProto.getTemperature()); | ||
assertEquals(coffee.isSwirling(),coffeeProto.getSwirling()); | ||
assertEquals(coffee.isClockwise(), coffeeProto.getClockwise()); | ||
|
||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/test/java/net/badata/protobuf/converter/domain/Coffee.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,29 @@ | ||
package net.badata.protobuf.converter.domain; | ||
|
||
import net.badata.protobuf.converter.annotation.ProtoClass; | ||
import net.badata.protobuf.converter.annotation.ProtoField; | ||
import net.badata.protobuf.converter.proto.LiquidProto; | ||
|
||
@ProtoClass(LiquidProto.Coffee.class) | ||
public class Coffee extends Liquid { | ||
@ProtoField | ||
private boolean swirling; | ||
@ProtoField | ||
private boolean clockwise; | ||
|
||
public boolean isSwirling() { | ||
return swirling; | ||
} | ||
|
||
public void setSwirling(boolean swirling) { | ||
this.swirling = swirling; | ||
} | ||
|
||
public boolean isClockwise() { | ||
return clockwise; | ||
} | ||
|
||
public void setClockwise(boolean clockwise) { | ||
this.clockwise = clockwise; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/test/java/net/badata/protobuf/converter/domain/Liquid.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,27 @@ | ||
package net.badata.protobuf.converter.domain; | ||
|
||
|
||
import net.badata.protobuf.converter.annotation.ProtoField; | ||
|
||
public class Liquid { | ||
@ProtoField | ||
private int mlVolume; | ||
@ProtoField | ||
private float temperature; | ||
|
||
public int getMlVolume() { | ||
return mlVolume; | ||
} | ||
|
||
public void setMlVolume(int mlVolume) { | ||
this.mlVolume = mlVolume; | ||
} | ||
|
||
public float getTemperature() { | ||
return temperature; | ||
} | ||
|
||
public void setTemperature(float temperature) { | ||
this.temperature = temperature; | ||
} | ||
} |
Oops, something went wrong.