Source:
<code>public void testStarringOrganization() { final ApiClient webClientUser2 = getWebClient(USER_2_USERNAME); final ApiClient webClientAdminUser = getWebClient(ADMIN_USERNAME); OrganizationsApi organizationsApiAdmin = new OrganizationsApi(webClientAdminUser); OrganizationsApi organizationsApi = new OrganizationsApi(webClientUser2); Organization organization = createOrg(organizationsApi); UsersApi usersApi = new UsersApi(webClientUser2); User user = usersApi.getUser(); List<User> users = new ArrayList<>(); users.add(user); StarRequest body = new StarRequest(); body.setStar(false); boolean throwsError = false; try { organizationsApi.starOrganization(organization.getId(), body); } catch (ApiException ex) { throwsError = true; } if (!throwsError) { fail("Was able to star an unapproved organization."); } organizationsApiAdmin.approveOrganization(organization.getId()); organizationsApi.starOrganization(organization.getId(), body); assertEquals(1, organizationsApi.getStarredUsersForApprovedOrganization(organization.getId()).size()); <START> assertEquals(USER_2_USERNAME, organizationsApi.getStarredUsersForApprovedOrganization(organization.getId()).get(0).getUsername()); <END> throwsError = false; try { organizationsApi.starOrganization(organization.getId(), body); } catch (ApiException ex) { throwsError = true; } if (!throwsError) { fail("Was able to star an already starred organization"); } organizationsApi.unstarOrganization(organization.getId()); assertEquals(0, organizationsApi.getStarredUsersForApprovedOrganization(organization.getId()).size()); throwsError = false; try { organizationsApi.unstarOrganization(organization.getId()); } catch (ApiException ex) { throwsError = true; } if (!throwsError) { fail("Was able to unstar an already unstarred organization"); } organization.setStarredUsers(users); assertEquals(1, organization.getStarredUsers().size()); assertEquals(user.getUsername(), organization.getStarredUsers().get(0).getUsername()); users.remove(user); organization.setStarredUsers(users); assertEquals(0, organization.getStarredUsers().size()); }</code><technical_language>easier throw a fail() this get rid of throwsError entirely</technical_language>

Target:
public void testStarringOrganization() { final ApiClient webClientUser2 = getWebClient(USER_2_USERNAME); final ApiClient webClientAdminUser = getWebClient(ADMIN_USERNAME); OrganizationsApi organizationsApiAdmin = new OrganizationsApi(webClientAdminUser); OrganizationsApi organizationsApi = new OrganizationsApi(webClientUser2); Organization organization = createOrg(organizationsApi); UsersApi usersApi = new UsersApi(webClientUser2); User user = usersApi.getUser(); List<User> users = new ArrayList<>(); users.add(user); StarRequest body = new StarRequest(); body.setStar(false); try { organizationsApi.starOrganization(organization.getId(), body); Assert.fail(); } catch (ApiException ex) { Assert.assertEquals("Organization not found", ex.getMessage()); } organizationsApiAdmin.approveOrganization(organization.getId()); organizationsApi.starOrganization(organization.getId(), body); assertEquals(1, organizationsApi.getStarredUsersForApprovedOrganization(organization.getId()).size()); assertEquals(USER_2_USERNAME, organizationsApi.getStarredUsersForApprovedOrganization(organization.getId()).get(0).getUsername()); try { organizationsApi.starOrganization(organization.getId(), body); Assert.fail(); } catch (ApiException ex) { Assert.assertTrue(ex.getMessage().contains("You cannot star the organization")); } organizationsApi.unstarOrganization(organization.getId()); assertEquals(0, organizationsApi.getStarredUsersForApprovedOrganization(organization.getId()).size()); try { organizationsApi.unstarOrganization(organization.getId()); Assert.fail(); } catch (ApiException ex) { Assert.assertTrue(ex.getMessage().contains("You cannot unstar the organization")); } organization.setStarredUsers(users); assertEquals(1, organization.getStarredUsers().size()); assertEquals(user.getUsername(), organization.getStarredUsers().get(0).getUsername()); users.remove(user); organization.setStarredUsers(users); assertEquals(0, organization.getStarredUsers().size()); }