diff --git a/src/main/java/ru/ulstu/is/cbapp/Lab2/domain/Calculate.java b/src/main/java/ru/ulstu/is/cbapp/Lab2/domain/Calculate.java index 7f1ce19..537e3f5 100644 --- a/src/main/java/ru/ulstu/is/cbapp/Lab2/domain/Calculate.java +++ b/src/main/java/ru/ulstu/is/cbapp/Lab2/domain/Calculate.java @@ -1,8 +1,8 @@ package ru.ulstu.is.cbapp.Lab2.domain; public interface Calculate { - Object add(T a, T b); - Object sut(T a, T b); - Object len(T a); - Object inv(T a); + T add(T a, T b); + T sut(T a, T b); + Integer len(T a); + T inv(T a); } diff --git a/src/main/java/ru/ulstu/is/cbapp/Lab2/domain/StringCalculate.java b/src/main/java/ru/ulstu/is/cbapp/Lab2/domain/StringCalculate.java index e482c09..02361f2 100644 --- a/src/main/java/ru/ulstu/is/cbapp/Lab2/domain/StringCalculate.java +++ b/src/main/java/ru/ulstu/is/cbapp/Lab2/domain/StringCalculate.java @@ -16,8 +16,8 @@ public class StringCalculate implements Calculate { } @Override - public String len(String a) { - return "Длина = "+a.length(); + public Integer len(String a) { + return a.length(); } @Override diff --git a/src/main/java/ru/ulstu/is/cbapp/Lab2/service/ServiceCalculate.java b/src/main/java/ru/ulstu/is/cbapp/Lab2/service/ServiceCalculate.java index e69e95b..56d41dc 100644 --- a/src/main/java/ru/ulstu/is/cbapp/Lab2/service/ServiceCalculate.java +++ b/src/main/java/ru/ulstu/is/cbapp/Lab2/service/ServiceCalculate.java @@ -30,8 +30,8 @@ public class ServiceCalculate { catch (Exception ex){ return new Errors(400, ex.getMessage()); } - } + public Object sut(Object a, Object b, String type){ Calculate calculate = (Calculate)applicationContext.getBean(type); if (a==null || a.equals("") || b==null || b.equals("")){ diff --git a/src/test/java/ru/ulstu/is/cbapp/CbappApplicationTests.java b/src/test/java/ru/ulstu/is/cbapp/CbappApplicationTests.java index e7896d2..701a75a 100644 --- a/src/test/java/ru/ulstu/is/cbapp/CbappApplicationTests.java +++ b/src/test/java/ru/ulstu/is/cbapp/CbappApplicationTests.java @@ -1,13 +1,52 @@ package ru.ulstu.is.cbapp; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import ru.ulstu.is.cbapp.Lab2.service.ServiceCalculate; @SpringBootTest class CbappApplicationTests { + @Autowired + ServiceCalculate serviceCalculate; + @Test - void contextLoads() { + void stringSum() { + Assertions.assertEquals("testData",serviceCalculate.add("test","Data","string")); + Assertions.assertEquals("1022",serviceCalculate.add("102","2","string")); + } + @Test + void numberSum() { + Assertions.assertEquals(104,serviceCalculate.add("102","2","number")); + } + @Test + void stringSut() { + Assertions.assertEquals("tt",serviceCalculate.sut("test","es","string")); + Assertions.assertEquals("10",serviceCalculate.sut("102","2","string")); + } + @Test + void numberSut() { + Assertions.assertEquals(100,serviceCalculate.sut(102,2,"number")); + } + @Test + void stringLen() { + Assertions.assertEquals("Длина = 4",serviceCalculate.len("test","string")); + } + @Test + void numberLen() { + Assertions.assertEquals(3,serviceCalculate.len(305,"number")); + Assertions.assertEquals(2,serviceCalculate.len(24,"number")); + } + @Test + void stringInv() { + Assertions.assertEquals("gnirts",serviceCalculate.inv("string","string")); + } + @Test + void numberInv() { + Assertions.assertEquals(-102,serviceCalculate.inv(102,"number")); + Assertions.assertEquals(12,serviceCalculate.inv(-12,"number")); } }