BaseTbResourceServiceTest, BaseDeviceServiceTest: Rule ExpectedException refactored with AssertJ Exception Assertions

This commit is contained in:
Oleksandra Matviienko 2023-03-13 23:08:19 +01:00
parent 5cb1b7d275
commit 3841deae24
2 changed files with 8 additions and 18 deletions

View File

@ -19,10 +19,8 @@ import com.datastax.oss.driver.api.core.uuid.Uuids;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.rules.ExpectedException;
import org.springframework.beans.factory.annotation.Autowired;
import org.thingsboard.server.common.data.EntityInfo;
import org.thingsboard.server.common.data.ResourceType;
@ -46,6 +44,7 @@ import java.util.Base64;
import java.util.Collections;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@DaoSqlTest
@ -116,10 +115,6 @@ public class BaseTbResourceServiceTest extends AbstractControllerTest {
.andExpect(status().isOk());
}
@SuppressWarnings("deprecation")
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test
public void testSaveResourceWithMaxSumDataSizeOutOfLimit() throws Exception {
loginSysAdmin();
@ -138,9 +133,9 @@ public class BaseTbResourceServiceTest extends AbstractControllerTest {
Assert.assertEquals(1, resourceService.sumDataSizeByTenantId(tenantId));
try {
thrown.expect(DataValidationException.class);
thrown.expectMessage(String.format("Failed to create the tb resource, files size limit is exhausted %d bytes!", limit));
createResource("test1", 1 + DEFAULT_FILE_NAME);
assertThatThrownBy(() -> createResource("test1", 1 + DEFAULT_FILE_NAME))
.isInstanceOf(DataValidationException.class)
.hasMessageContaining("Failed to create the tb resource, files size limit is exhausted %d bytes!", limit);
} finally {
defaultTenantProfile.getProfileData().setConfiguration(DefaultTenantProfileConfiguration.builder().maxResourcesInBytes(0).build());
loginSysAdmin();

View File

@ -19,10 +19,8 @@ import com.datastax.oss.driver.api.core.uuid.Uuids;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.rules.ExpectedException;
import org.thingsboard.server.common.data.Customer;
import org.thingsboard.server.common.data.Device;
import org.thingsboard.server.common.data.DeviceInfo;
@ -47,6 +45,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.thingsboard.server.common.data.ota.OtaPackageType.FIRMWARE;
import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID;
@ -72,10 +71,6 @@ public abstract class BaseDeviceServiceTest extends AbstractServiceTest {
tenantProfileService.deleteTenantProfiles(anotherTenantId);
}
@SuppressWarnings("deprecation")
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test
public void testSaveDevicesWithoutMaxDeviceLimit() {
Device device = this.saveDevice(tenantId, "My device");
@ -244,9 +239,9 @@ public abstract class BaseDeviceServiceTest extends AbstractServiceTest {
savedDevice.setFirmwareId(savedFirmware.getId());
thrown.expect(DataValidationException.class);
thrown.expectMessage("Can't assign firmware with different deviceProfile!");
deviceService.saveDevice(savedDevice);
assertThatThrownBy(() -> deviceService.saveDevice(savedDevice))
.isInstanceOf(DataValidationException.class)
.hasMessageContaining("Can't assign firmware with different deviceProfile!");
}
@Test