use of net.morimekta.test.providence.core.calculator.Operation in project providence by morimekta.
the class ProvidenceHelperTest method testFromJsonResource_named.
@Test
public void testFromJsonResource_named() throws IOException {
Operation op = net.morimekta.providence.util.ProvidenceHelper.fromJsonResource("/json/calculator/named.json", Operation.kDescriptor);
Operation expected = Operation.builder().setOperator(Operator.MULTIPLY).addToOperands(Operand.builder().setOperation(Operation.builder().setOperator(Operator.ADD).addToOperands(Operand.builder().setNumber(1234).build()).addToOperands(Operand.builder().setNumber(4.321).build()).build()).build()).addToOperands(Operand.builder().setImaginary(Imaginary.builder().setV(1.7).setI(-2.0).build()).build()).build();
assertEquals(op, expected);
}
use of net.morimekta.test.providence.core.calculator.Operation in project providence by morimekta.
the class FileMessageRWTest method testService.
@Test
public void testService() throws IOException {
String content = "[\"calculate\",\"call\",44,{\"op\":{\"operator\":\"ADD\",\"operands\":[]}}]";
File test = writeContentTo(content, tmp.newFile());
PServiceCall<Operation, Operation._Field> call = null;
try (FileMessageReader reader = new FileMessageReader(test, new JsonSerializer())) {
call = reader.read(Calculator.kDescriptor);
}
File result = tmp.newFile();
try (FileMessageWriter writer = new FileMessageWriter(result, new JsonSerializer().named())) {
writer.write(call);
}
assertThat(new String(Files.readAllBytes(result.toPath()), StandardCharsets.UTF_8), is(equalTo(content)));
}
use of net.morimekta.test.providence.core.calculator.Operation in project providence by morimekta.
the class PrettySerializerTest method testParse.
@Test
public void testParse() throws IOException {
PrettySerializer serializer = new PrettySerializer();
Operation actual = serializer.deserialize(getClass().getResourceAsStream("/json/calculator/pretty.cfg"), Operation.kDescriptor);
assertEquals(mOperation, actual);
}
Aggregations