PermissionEntityDataMapper { public PermissionEntity transformInverse(Permission permission) { if (permission == null) { return null; } return new PermissionEntity.Builder() .permission(permission.permission()) .rationaleTitle(permission.rationaleTitle()) .rationaleMessage(permission.rationaleMessage()) .deniedMessage(permission.deniedMessage()) .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 shouldReturnNullValueGivenANullPermission() throws Exception { Permission permission = null; PermissionEntity permissionEntity = permissionEntityDataMapper.transformInverse(permission); assertThat(permissionEntity, nullValue()); }
@Test public void shouldProperlyMapPermissionIntoPermissionEntity() throws Exception { Permission permissionCamera = Permission.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 permissionCameraEntity = permissionEntityDataMapper.transformInverse(permissionCamera); assertThat(permissionCameraEntity, notNullValue()); assertThat(permissionCameraEntity, instanceOf(PermissionEntity.class)); assertThat(permissionCameraEntity.getPermission(), notNullValue()); assertThat(permissionCameraEntity.getPermission(), is("CAMERA")); assertThat(permissionCameraEntity.getRationaleTitle(), notNullValue()); assertThat(permissionCameraEntity.getRationaleTitle(), is("Permission Request")); assertThat(permissionCameraEntity.getRationaleMessage(), notNullValue()); assertThat(permissionCameraEntity.getRationaleMessage(), is("You should allow this permission")); assertThat(permissionCameraEntity.getDeniedMessage(), notNullValue()); assertThat(permissionCameraEntity.getDeniedMessage(), is("You must allow this permission in order for this feature to work")); }
@Test public void shouldProperlyMapPermissionCollectionIntoPermissionEntityCollection() throws Exception { Permission cameraPermission = Permission.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 contactsPermission = Permission.builder() .permission("CONTACTS") .rationaleTitle("Permission Request") .rationaleMessage("You should allow this permission") .deniedMessage("You must allow this permission") .build(); ArrayList<Permission> permissions = new ArrayList<>(); permissions.add(cameraPermission); permissions.add(contactsPermission); Collection<PermissionEntity> permissionEntities = permissionEntityDataMapper.transformInverse(permissions); assertThat(permissionEntities, notNullValue()); assertThat(permissionEntities.size(), is(2)); PermissionEntity permissionEntity1 = (PermissionEntity) permissionEntities.toArray()[0]; assertThat(permissionEntity1, notNullValue()); assertThat(permissionEntity1.getPermission(), is("CAMERA")); PermissionEntity permissionEntity2 = (PermissionEntity) permissionEntities.toArray()[1]; assertThat(permissionEntity2.getPermission(), is("CONTACTS")); }