@ExportedProperty public void testClassWithBadConstructor() { try { ClassWithBadConstructor clazz = new ClassWithBadConstructor("foo", "bar"); PouchDocumentMapper.fromJson( PouchDocumentMapper.toJson(clazz), ClassWithBadConstructor.class); Assert.fail("expected an exception"); } catch (RuntimeException expected) { // expected this } }
public void testBasic() { Person person = new Person(); person.setName("Nolan Lawson"); person.setDystopianBarcodeId(4430823408L); person.setNumberOfPetsOwned(3); person.setBelieber(false); // I give names to my GameBoys. Haters gonna hate. person.setGameBoys( Arrays.asList( new GameBoy("Rudy", "GameBoy Pocket"), new GameBoy("Roger", "GameBoy Color"))); String asJson = PouchDocumentMapper.toJson(person); Person fromJson = PouchDocumentMapper.fromJson(asJson, Person.class); assertEquals(person, fromJson); assertNull(person.getPouchId()); assertNull(person.getPouchRev()); assertNull(fromJson.getPouchId()); assertNull(fromJson.getPouchRev()); // now set the pouch id/rev and make sure everything jives person.setPouchId("myId"); person.setPouchRev("myRev"); asJson = PouchDocumentMapper.toJson(person); fromJson = PouchDocumentMapper.fromJson(asJson, Person.class); assertEquals(person, fromJson); assertEquals(person.getPouchId(), "myId"); assertEquals(person.getPouchRev(), "myRev"); assertEquals(fromJson.getPouchId(), "myId"); assertEquals(fromJson.getPouchRev(), "myRev"); }