Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
monticore
EmbeddedMontiArc
generators
EMAM2Wasm
Commits
0ab3d1a9
Verified
Commit
0ab3d1a9
authored
Apr 13, 2018
by
Stefan Brunecker
Browse files
Add WasmJsNameProvider test
parent
c6b9eabe
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/main/java/de/monticore/lang/monticar/emam2wasm/wasm/WasmJsNameProvider.java
View file @
0ab3d1a9
package
de.monticore.lang.monticar.emam2wasm.wasm
;
import
static
de
.
monticore
.
lang
.
monticar
.
contract
.
Precondition
.
requiresNotNull
;
import
java.nio.file.Path
;
import
org.apache.commons.io.FilenameUtils
;
import
org.springframework.stereotype.Component
;
...
...
@@ -11,7 +13,7 @@ public class WasmJsNameProvider implements WasmNameProvider {
@Override
public
String
getName
(
Path
cppFile
)
{
return
FilenameUtils
.
getBaseName
(
cppFile
.
toString
());
return
FilenameUtils
.
getBaseName
(
requiresNotNull
(
cppFile
)
.
toString
());
}
@Override
...
...
src/test/java/de/monticore/lang/monticar/emam2wasm/wasm/WasmJsNameProviderTest.java
0 → 100644
View file @
0ab3d1a9
package
de.monticore.lang.monticar.emam2wasm.wasm
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThatExceptionOfType
;
import
de.monticore.lang.monticar.contract.Precondition.PreconditionViolationException
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Nested
;
import
org.junit.jupiter.api.Test
;
class
WasmJsNameProviderTest
{
private
static
final
Path
NULL_PATH
=
null
;
private
static
final
Path
SOME_CPP_FILE_PATH
=
Paths
.
get
(
"some_file.cpp"
);
private
static
final
Path
SOME_CPP_RELATIVE_PATH
=
Paths
.
get
(
"some/directory/some_file.cpp"
);
private
static
final
Path
SOME_CPP_ABSOLUTE_PATH
=
Paths
.
get
(
"some/directory/some_file.cpp"
)
.
toAbsolutePath
();
private
static
final
String
EXPECTED_NAME
=
"some_file"
;
private
static
final
Path
EXPECTED_FILE_PATH
=
Paths
.
get
(
"some_file.js"
);
private
WasmJsNameProvider
nameProvider
;
@BeforeEach
void
setUp
()
{
nameProvider
=
new
WasmJsNameProvider
();
}
@Nested
class
GetName
{
@Nested
class
ShouldThrowPreconditionViolationException
{
@Test
void
whenPathIsNull
()
{
assertThatExceptionOfType
(
PreconditionViolationException
.
class
)
.
isThrownBy
(()
->
nameProvider
.
getName
(
NULL_PATH
));
}
}
@Nested
class
ShouldReturnBaseName
{
@Test
void
whenOnlyFileName
()
{
assertThat
(
nameProvider
.
getName
(
SOME_CPP_FILE_PATH
)).
isEqualTo
(
EXPECTED_NAME
);
}
@Test
void
whenRelativePath
()
{
assertThat
(
nameProvider
.
getName
(
SOME_CPP_RELATIVE_PATH
)).
isEqualTo
(
EXPECTED_NAME
);
}
@Test
void
whenAbsolutePath
()
{
assertThat
(
nameProvider
.
getName
(
SOME_CPP_ABSOLUTE_PATH
)).
isEqualTo
(
EXPECTED_NAME
);
}
}
}
@Nested
class
GetFilePath
{
@Nested
class
ShouldThrowPreconditionViolationException
{
@Test
void
whenPathIsNull
()
{
assertThatExceptionOfType
(
PreconditionViolationException
.
class
)
.
isThrownBy
(()
->
nameProvider
.
getName
(
NULL_PATH
));
}
}
@Nested
class
ShouldReturnFilePath
{
@Test
void
whenOnlyFileName
()
{
assertThat
(
nameProvider
.
getFilePath
(
SOME_CPP_FILE_PATH
)).
isEqualTo
(
EXPECTED_FILE_PATH
);
}
@Test
void
whenRelativePath
()
{
assertThat
(
nameProvider
.
getFilePath
(
SOME_CPP_RELATIVE_PATH
)).
isEqualTo
(
EXPECTED_FILE_PATH
);
}
@Test
void
whenAbsolutePath
()
{
assertThat
(
nameProvider
.
getFilePath
(
SOME_CPP_ABSOLUTE_PATH
)).
isEqualTo
(
EXPECTED_FILE_PATH
);
}
}
}
}
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment