PermissionEntityDataMapper { public Permission transform(PermissionEntity permissionEntity) { if (permissionEntity == null) { return null; } return Permission.builder() .permission(permissionEntity.getPermission()) .rationaleTitle(permissionEntity.getRationaleTitle()) .rationaleMessage(permissionEntity.getRationaleMessage()) .deniedMessage(permissionEntity.getDeniedMessage()) .build(); } @Inject  PermissionEntityDataMapper(); Permission transform(PermissionEntity permissionEntity); Collection<Permission> transform(Collection<PermissionEntity> permissionEntities); PermissionEntity transformInverse(Permission permission); Collection<PermissionEntity> transformInverse(Collection<Permission> permissions);  }
@Test public void shouldReturnNullValueGivenANullPermissionEntity() throws Exception { PermissionEntity permissionEntity = null; Permission permission = permissionEntityDataMapper.transform(permissionEntity); assertThat(permission, nullValue()); }
@Test public void shouldProperlyMapPermissionEntityIntoPermission() throws Exception { PermissionEntity permissionCameraEntity = new PermissionEntity.Builder() .permission("CAMERA") .rationaleTitle("Permission Request") .rationaleMessage("You should allow this permission") .deniedMessage("You must allow this permission in order for this feature to work") .build(); Permission permissionCamera = permissionEntityDataMapper.transform(permissionCameraEntity); assertThat(permissionCamera, notNullValue()); assertThat(permissionCamera, instanceOf(Permission.class)); assertThat(permissionCamera.permission(), notNullValue()); assertThat(permissionCamera.permission(), is("CAMERA")); assertThat(permissionCamera.rationaleTitle(), notNullValue()); assertThat(permissionCamera.rationaleTitle(), is("Permission Request")); assertThat(permissionCamera.rationaleMessage(), notNullValue()); assertThat(permissionCamera.rationaleMessage(), is("You should allow this permission")); assertThat(permissionCamera.deniedMessage(), notNullValue()); assertThat(permissionCamera.deniedMessage(), is("You must allow this permission in order for this feature to work")); }
@Test public void shouldProperlyMapPermissionEntityCollectionIntoPermissionCollection() throws Exception { PermissionEntity cameraPermissionEntity = new PermissionEntity.Builder() .permission("CAMERA") .rationaleTitle("Permission Request") .rationaleMessage("You should allow this permission") .deniedMessage("You must allow this permission in order for this feature to work") .build(); PermissionEntity contactsPermissionEntity = new PermissionEntity.Builder() .permission("CONTACTS") .rationaleTitle("Permission Request") .rationaleMessage("You should allow this permission") .deniedMessage("You must allow this permission") .build(); ArrayList<PermissionEntity> permissionEntities = new ArrayList<>(); permissionEntities.add(cameraPermissionEntity); permissionEntities.add(contactsPermissionEntity); Collection<Permission> permissions = permissionEntityDataMapper.transform(permissionEntities); assertThat(permissions, notNullValue()); assertThat(permissions.size(), is(2)); Permission permission1 = (Permission) permissions.toArray()[0]; assertThat(permission1, notNullValue()); assertThat(permission1.permission(), is("CAMERA")); Permission permission2 = (Permission) permissions.toArray()[1]; assertThat(permission2, notNullValue()); assertThat(permission2.permission(), is("CONTACTS")); }