-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
287 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
36 changes: 36 additions & 0 deletions
36
common/src/test/java/de/xab/porter/common/test/json/Entity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package de.xab.porter.common.test.json; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* class for JSON test | ||
*/ | ||
public class Entity { | ||
private List<String> field1; | ||
private String field2; | ||
private int field3; | ||
|
||
public List<String> getField1() { | ||
return field1; | ||
} | ||
|
||
public void setField1(List<String> field1) { | ||
this.field1 = field1; | ||
} | ||
|
||
public String getField2() { | ||
return field2; | ||
} | ||
|
||
public void setField2(String field2) { | ||
this.field2 = field2; | ||
} | ||
|
||
public int getField3() { | ||
return field3; | ||
} | ||
|
||
public void setField3(int field3) { | ||
this.field3 = field3; | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
common/src/test/java/de/xab/porter/common/test/json/JSONTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package de.xab.porter.common.test.json; | ||
|
||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import de.xab.porter.common.util.Jsons; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.*; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
/** | ||
* tests for JSON utils | ||
*/ | ||
public class JSONTest { | ||
private final String json = "{\"field2\":\"field2\",\"field3\":0}"; | ||
private final String jsonList = "[{\"field2\":\"field2\",\"field3\":0}]"; | ||
private final String jsonSet = "[{\"field2\":\"field2\",\"field3\":0}]"; | ||
private final String jsonMap = "{\"key\":{\"field2\":\"field2\",\"field3\":0}}"; | ||
private Entity entity; | ||
|
||
@BeforeEach | ||
public void before() { | ||
entity = new Entity(); | ||
entity.setField2("field2"); | ||
} | ||
|
||
@Test | ||
public void testObjectSerialization() { | ||
String json = Jsons.toJson(entity); | ||
assertEquals(this.json, json); | ||
} | ||
|
||
@Test | ||
public void testObjectDeserialization() { | ||
Entity fromJson = Jsons.fromJson(this.json, Entity.class); | ||
assertEquals(fromJson.getField1(), entity.getField1()); | ||
assertEquals(fromJson.getField2(), entity.getField2()); | ||
assertEquals(fromJson.getField3(), entity.getField3()); | ||
} | ||
|
||
@Test | ||
public void testListSerialization() { | ||
List<Entity> entities = new ArrayList<>(); | ||
entities.add(entity); | ||
String json = Jsons.toJson(entities); | ||
assertEquals(json, jsonList); | ||
} | ||
|
||
@Test | ||
public void testListDeserialization() { | ||
List<Entity> entities = Jsons.fromJson(jsonList, new TypeReference<>() { | ||
}); | ||
Entity entity = entities.get(0); | ||
assertEquals(entity.getField1(), this.entity.getField1()); | ||
assertEquals(entity.getField2(), this.entity.getField2()); | ||
assertEquals(entity.getField3(), this.entity.getField3()); | ||
} | ||
|
||
@Test | ||
public void testSetSerialization() { | ||
Set<Entity> entities = new HashSet<>(); | ||
entities.add(entity); | ||
String json = Jsons.toJson(entities); | ||
assertEquals(json, jsonSet); | ||
} | ||
|
||
@Test | ||
public void testSetDeserialization() { | ||
Set<Entity> entities = Jsons.fromJson(jsonSet, new TypeReference<>() { | ||
}); | ||
Entity entity = (Entity) entities.toArray()[0]; | ||
assertEquals(entity.getField1(), this.entity.getField1()); | ||
assertEquals(entity.getField2(), this.entity.getField2()); | ||
assertEquals(entity.getField3(), this.entity.getField3()); | ||
} | ||
|
||
@Test | ||
public void testMapSerialization() { | ||
Map<String, Entity> entities = new HashMap<>(); | ||
entities.put("key", entity); | ||
String json = Jsons.toJson(entities); | ||
assertEquals(json, jsonMap); | ||
} | ||
|
||
@Test | ||
public void testMapDeserialization() { | ||
Map<String, Entity> entities = Jsons.fromJson(jsonMap, new TypeReference<>() { | ||
}); | ||
Entity entity = entities.get("key"); | ||
assertEquals(entity.getField1(), this.entity.getField1()); | ||
assertEquals(entity.getField2(), this.entity.getField2()); | ||
assertEquals(entity.getField3(), this.entity.getField3()); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
common/src/test/java/de/xab/porter/common/test/spi/SPITest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package de.xab.porter.common.test.spi; | ||
|
||
import de.xab.porter.api.exception.PorterException; | ||
import de.xab.porter.common.spi.ExtensionLoader; | ||
import de.xab.porter.common.test.spi.service.MockService; | ||
import de.xab.porter.common.test.spi.service.UnregisteredService; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
/** | ||
* test class for porter SPI | ||
*/ | ||
public class SPITest { | ||
@Test | ||
public void testExists() { | ||
MockService impl = ExtensionLoader.getExtensionLoader().loadExtension("impl", MockService.class); | ||
assertEquals("hello world", impl.mock()); | ||
} | ||
|
||
@Test | ||
public void testNotExists() { | ||
assertThrows(PorterException.class, () -> | ||
ExtensionLoader.getExtensionLoader().loadExtension("none", MockService.class)); | ||
} | ||
|
||
@Test | ||
public void testTypoImpl() { | ||
assertThrows(PorterException.class, () -> | ||
ExtensionLoader.getExtensionLoader().loadExtension("typo", MockService.class)); | ||
} | ||
|
||
@Test | ||
public void testNoImplemented() { | ||
assertThrows(PorterException.class, () -> | ||
ExtensionLoader.getExtensionLoader().loadExtension("noimpl", MockService.class)); | ||
} | ||
|
||
@Test | ||
public void testNoneRegistered() { | ||
assertThrows(PorterException.class, () -> | ||
ExtensionLoader.getExtensionLoader().loadExtension("any", UnregisteredService.class)); | ||
} | ||
} |
4 changes: 3 additions & 1 deletion
4
...orter/common/service/MockServiceImpl.java → ...common/test/spi/impl/MockServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ter/common/service/NoImplServiceImpl.java → ...mmon/test/spi/impl/NoImplServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package de.xab.porter.common.service; | ||
package de.xab.porter.common.test.spi.impl; | ||
|
||
/** | ||
* not a service | ||
|
4 changes: 3 additions & 1 deletion
4
...orter/common/service/TypoServiceImpl.java → ...common/test/spi/impl/TypoServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
...mmon/service/UnregisteredServiceImpl.java → ...est/spi/impl/UnregisteredServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ab/porter/common/service/MockService.java → .../common/test/spi/service/MockService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package de.xab.porter.common.service; | ||
package de.xab.porter.common.test.spi.service; | ||
|
||
/** | ||
* mock service | ||
|
2 changes: 1 addition & 1 deletion
2
...r/common/service/UnregisteredService.java → ...test/spi/service/UnregisteredService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
common/src/test/java/de/xab/porter/common/test/string/StringTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package de.xab.porter.common.test.string; | ||
|
||
import de.xab.porter.common.util.Strings; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
|
||
/** | ||
* test class for Strings util | ||
*/ | ||
public class StringTest { | ||
@Test | ||
public void testNull() { | ||
String str = null; | ||
assertFalse(Strings.notNullOrEmpty(str)); | ||
} | ||
|
||
@Test | ||
public void testEmpty() { | ||
String str = ""; | ||
assertFalse(Strings.notNullOrEmpty(str)); | ||
} | ||
|
||
@Test | ||
public void testNotNullOrEmpty() { | ||
String str = "abc"; | ||
Assertions.assertTrue(Strings.notNullOrEmpty(str)); | ||
} | ||
|
||
@Test | ||
public void testLongEmpty() { | ||
String str = " "; | ||
assertFalse(Strings.notNullOrEmpty(str)); | ||
} | ||
} |
Oops, something went wrong.