/
javapractice
/
JavaPractice
Обзор
Документация
Войти
/
javapractice
/
JavaPractice
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
2
CI/CD
Аналитика
develop
ApachePOI/src/test/java/entities/CellPhoneTest.java
83 строки
3 KB
Zexa91x0
Apache POI - PriceGetterMegafon
24 май 2021, 21:09
24 май 2021, 21:09
8756120
Код
Авторство
О чём код?
package entities; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.junit.Assert; import org.junit.Test; import org.junit.jupiter.api.Assertions; import utils.AllocationsDB; import utils.XLSXLoader; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.List; import static org.junit.Assert.*; public class CellPhoneTest { public CellPhone cellPhone1 = new CellPhone(932_104_1000L, "Megafon"); public CellPhone cellPhone2 = new CellPhone(921_125_8220L, "MTS"); public CellPhone cellPhone3 = new CellPhone(932_104_1000L, "Megafon"); public Department department = new Department("g61", "General_C", "IT"); public Allocation allocation = new Allocation( new ArrayList<Owner>(List.of( new Owner("x123456", "Vasil", "Neuminz").setDepartment(department))), cellPhone1); String filePath = "D:\\Skills\\_Repository\\JavaPractice\\ApachePOI\\src\\main\\resources\\test.xlsx"; AllocationsDB allocationsDB = this.allocationsDB = new AllocationsDB(new XLSXLoader(new File(filePath)).getWorkbook().getSheetAt(0), 241);; public CellPhoneTest() throws IOException, InvalidFormatException { } // можно так проверить получение исключения но нужно удалить Try совсем // @Test(expected = IllegalArgumentException.class) @Test public void setNumber() { try { cellPhone1.setNumber(123L); } catch (IllegalArgumentException thrown) { Assert.assertNotEquals("Тест прошел успешно", thrown.getMessage()); System.err.println("(так должно быть) получено исключение с текстом: " + thrown); } assertNotEquals(900_000_0000L, (long) cellPhone1.getNumber()); cellPhone1.setNumber(900_000_0000L); assertEquals(900_000_0000L, (long) cellPhone1.getNumber()); } @Test public void setOperator() throws Exception { assertNotEquals("MTS", cellPhone1.getOperator()); cellPhone1.setOperator("MTS"); assertEquals("MTS", cellPhone1.getOperator()); } @Test public void compareTo() { Assertions.assertAll(() -> assertTrue(cellPhone1.compareTo(cellPhone2) > 0), () -> assertTrue(cellPhone1.compareTo(cellPhone3) == 0), () -> assertTrue(cellPhone2.compareTo(cellPhone3) < 0)); } @Test public void testEquals() { assertNotEquals(cellPhone1, cellPhone2); assertEquals(cellPhone1, cellPhone3); } @Test public void testHashCode() { assertNotEquals(cellPhone1.hashCode(), cellPhone2.hashCode()); assertEquals(cellPhone1.hashCode(), cellPhone3.hashCode()); } }