-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace multiapps-common test JAR with a new module
Using the mentioned test JAR was bad practice, since it included actual tests too.
- Loading branch information
Showing
32 changed files
with
187 additions
and
136 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>multiapps-common-test</artifactId> | ||
<packaging>jar</packaging> | ||
<name>MultiApps Common Test</name> | ||
|
||
<parent> | ||
<groupId>org.cloudfoundry.multiapps</groupId> | ||
<artifactId>multiapps-parent</artifactId> | ||
<version>2.2.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-api</artifactId> | ||
<scope>compile</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-params</artifactId> | ||
<scope>compile</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-core</artifactId> | ||
<scope>compile</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.commons</groupId> | ||
<artifactId>commons-lang3</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>commons-io</groupId> | ||
<artifactId>commons-io</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.cloudfoundry.multiapps</groupId> | ||
<artifactId>multiapps-common</artifactId> | ||
</dependency> | ||
</dependencies> | ||
</project> |
3 changes: 2 additions & 1 deletion
3
...s/common/util/GenericArgumentMatcher.java → ...s/common/test/GenericArgumentMatcher.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
132 changes: 67 additions & 65 deletions
132
...undry/multiapps/common/util/TestUtil.java → ...undry/multiapps/common/test/TestUtil.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,65 +1,67 @@ | ||
package org.cloudfoundry.multiapps.common.util; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
import org.cloudfoundry.multiapps.common.ParsingException; | ||
|
||
public class TestUtil { | ||
|
||
public static InputStream getResourceAsInputStream(String resource, Class<?> resourceClass) { | ||
return resourceClass.getResourceAsStream(resource); | ||
} | ||
|
||
public static String getResourceAsStringWithoutCarriageReturns(String resource, Class<?> resourceClass) { | ||
String resourceString = getResourceAsString(resource, resourceClass); | ||
return removeCarriageReturns(resourceString); | ||
} | ||
|
||
public static String getResourceAsString(String resource, Class<?> resourceClass) { | ||
try (InputStream resourceStream = getResourceAsInputStream(resource, resourceClass)) { | ||
return IOUtils.toString(resourceStream, StandardCharsets.UTF_8); | ||
} catch (IOException e) { | ||
throw new IllegalStateException(e.getMessage(), e); | ||
} | ||
} | ||
|
||
public static String removeCarriageReturns(String string) { | ||
return string.replaceAll("\\r|\\\\r", ""); | ||
} | ||
|
||
public static Map<String, Object> getMap(String file, Class<?> clazz) throws ParsingException { | ||
if (isYAMLFile(file)) { | ||
YamlParser yamlParser = new YamlParser(); | ||
return yamlParser.convertYamlToMap(clazz.getResourceAsStream(file)); | ||
} | ||
if (isJSONFile(file)) { | ||
return JsonUtil.convertJsonToMap(clazz.getResourceAsStream(file)); | ||
} | ||
return null; | ||
} | ||
|
||
public static List<Object> getList(String file, Class<?> clazz) throws ParsingException { | ||
if (isYAMLFile(file)) { | ||
YamlParser yamlParser = new YamlParser(); | ||
return yamlParser.convertYamlToList(clazz.getResourceAsStream(file)); | ||
} | ||
if (isJSONFile(file)) { | ||
return JsonUtil.convertJsonToList(clazz.getResourceAsStream(file)); | ||
} | ||
return null; | ||
} | ||
|
||
public static boolean isYAMLFile(String filename) { | ||
return filename != null && (filename.endsWith(".yaml") || filename.endsWith(".mtaext")); | ||
} | ||
|
||
public static boolean isJSONFile(String filename) { | ||
return filename != null && filename.endsWith(".json"); | ||
} | ||
|
||
} | ||
package org.cloudfoundry.multiapps.common.test; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
import org.cloudfoundry.multiapps.common.ParsingException; | ||
import org.cloudfoundry.multiapps.common.util.JsonUtil; | ||
import org.cloudfoundry.multiapps.common.util.YamlParser; | ||
|
||
public class TestUtil { | ||
|
||
public static InputStream getResourceAsInputStream(String resource, Class<?> resourceClass) { | ||
return resourceClass.getResourceAsStream(resource); | ||
} | ||
|
||
public static String getResourceAsStringWithoutCarriageReturns(String resource, Class<?> resourceClass) { | ||
String resourceString = getResourceAsString(resource, resourceClass); | ||
return removeCarriageReturns(resourceString); | ||
} | ||
|
||
public static String getResourceAsString(String resource, Class<?> resourceClass) { | ||
try (InputStream resourceStream = getResourceAsInputStream(resource, resourceClass)) { | ||
return IOUtils.toString(resourceStream, StandardCharsets.UTF_8); | ||
} catch (IOException e) { | ||
throw new IllegalStateException(e.getMessage(), e); | ||
} | ||
} | ||
|
||
public static String removeCarriageReturns(String string) { | ||
return string.replaceAll("\\r|\\\\r", ""); | ||
} | ||
|
||
public static Map<String, Object> getMap(String file, Class<?> clazz) throws ParsingException { | ||
if (isYAMLFile(file)) { | ||
YamlParser yamlParser = new YamlParser(); | ||
return yamlParser.convertYamlToMap(clazz.getResourceAsStream(file)); | ||
} | ||
if (isJSONFile(file)) { | ||
return JsonUtil.convertJsonToMap(clazz.getResourceAsStream(file)); | ||
} | ||
return null; | ||
} | ||
|
||
public static List<Object> getList(String file, Class<?> clazz) throws ParsingException { | ||
if (isYAMLFile(file)) { | ||
YamlParser yamlParser = new YamlParser(); | ||
return yamlParser.convertYamlToList(clazz.getResourceAsStream(file)); | ||
} | ||
if (isJSONFile(file)) { | ||
return JsonUtil.convertJsonToList(clazz.getResourceAsStream(file)); | ||
} | ||
return null; | ||
} | ||
|
||
public static boolean isYAMLFile(String filename) { | ||
return filename != null && (filename.endsWith(".yaml") || filename.endsWith(".mtaext")); | ||
} | ||
|
||
public static boolean isJSONFile(String filename) { | ||
return filename != null && filename.endsWith(".json"); | ||
} | ||
|
||
} |
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 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 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 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 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
Oops, something went wrong.