Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
ARSnova Backend
Manage
Activity
Members
Labels
Plan
Issues
27
Issue boards
Milestones
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Privacy
Imprint
Contact
Snippets
Groups
Projects
Show more breadcrumbs
ARSnova
ARSnova Backend
Commits
dfa6f77e
Commit
dfa6f77e
authored
10 years ago
by
Jan Sladek
Browse files
Options
Downloads
Patches
Plain Diff
Implemented JUnit-Test for ImageUtils.java. Closes #15369. Fixed StringIndexOutOfBoundsException.
parent
012bf13e
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/de/thm/arsnova/ImageUtils.java
+3
-0
3 additions, 0 deletions
src/main/java/de/thm/arsnova/ImageUtils.java
src/test/java/de/thm/arsnova/ImageUtilsTest.java
+63
-0
63 additions, 0 deletions
src/test/java/de/thm/arsnova/ImageUtilsTest.java
with
66 additions
and
0 deletions
src/main/java/de/thm/arsnova/ImageUtils.java
+
3
−
0
View file @
dfa6f77e
...
...
@@ -134,6 +134,9 @@ public class ImageUtils {
else
{
final
int
extensionStartIndex
=
IMAGE_PREFIX_START
.
length
();
final
int
extensionEndIndex
=
maybeImage
.
indexOf
(
IMAGE_PREFIX_MIDDLE
);
if
(
extensionEndIndex
<
0
)
{
return
null
;
}
final
String
imageWithoutPrefix
=
maybeImage
.
substring
(
extensionEndIndex
);
...
...
This diff is collapsed.
Click to expand it.
src/test/java/de/thm/arsnova/ImageUtilsTest.java
0 → 100644
+
63
−
0
View file @
dfa6f77e
package
de.thm.arsnova
;
import
static
de
.
thm
.
arsnova
.
ImageUtils
.
isBase64EncodedImage
;
import
static
de
.
thm
.
arsnova
.
ImageUtils
.
extractImageInfo
;
import
static
de
.
thm
.
arsnova
.
ImageUtils
.
IMAGE_PREFIX_START
;
import
static
de
.
thm
.
arsnova
.
ImageUtils
.
IMAGE_PREFIX_MIDDLE
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
org.junit.Test
;
public
class
ImageUtilsTest
{
@Test
public
void
testNullIsNoValidBase64String
()
{
assertFalse
(
"\"null\" is no valid Base64 String."
,
isBase64EncodedImage
(
null
));
}
@Test
public
void
testEmptyStringIsNoValidBase64String
()
{
assertFalse
(
"The empty String is no valid Base64 String."
,
isBase64EncodedImage
(
""
));
}
@Test
public
void
testWrongStringIsNoValidBase64String
()
{
final
String
[]
fakeStrings
=
new
String
[]
{
"data:picture/png;base64,IMAGE-DATA"
,
"data:image/png;base63,IMAGE-DATA"
};
for
(
String
fakeString
:
fakeStrings
)
{
assertFalse
(
String
.
format
(
"The String %s is not a valid Base64 String."
,
fakeString
),
isBase64EncodedImage
(
fakeString
)
);
}
}
@Test
public
void
testValidBase64String
()
{
final
String
imageString
=
String
.
format
(
"%spng%sIMAGE-DATA"
,
IMAGE_PREFIX_START
,
IMAGE_PREFIX_MIDDLE
);
assertTrue
(
isBase64EncodedImage
(
imageString
));
}
@Test
public
void
testImageInfoExtraction
()
{
final
String
extension
=
"png"
;
final
String
imageData
=
"IMAGE-DATA"
;
final
String
imageString
=
String
.
format
(
"%s%s%s%s"
,
IMAGE_PREFIX_START
,
extension
,
IMAGE_PREFIX_MIDDLE
,
imageData
);
final
String
[]
imageInfo
=
extractImageInfo
(
imageString
);
assertNotNull
(
imageInfo
);
assertEquals
(
"Extracted information doesn't match its specification."
,
2
,
imageInfo
.
length
);
assertEquals
(
"Extracted extension is invalid."
,
extension
,
imageInfo
[
0
]);
assertEquals
(
"Extracted Base64-Image String is invalid."
,
imageData
,
imageInfo
[
1
]);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment