Skip to content

Commit

Permalink
Fixes setExtension of TipImage.java in org.eclipse.tips.tests eclipse…
Browse files Browse the repository at this point in the history
…-platform#525

In this commit the tests setExtension and setExtension2 are reactivated and changed. For this the method setExtension of TipImage.java is corrected to properly change the extension. Now if setExtension is called, not only the field fExtension is updated but also the field fBase64Image. Mind that for this change the field fBase64Image can't be final. Contributes to eclipse-platform#525.
  • Loading branch information
Michael5601 committed Sep 25, 2023
1 parent efe0dce commit 991d97c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
19 changes: 11 additions & 8 deletions ua/org.eclipse.tips.core/src/org/eclipse/tips/core/TipImage.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class TipImage {
private final URL fURL;
private double fAspectRatio = THREE_TO_TWO;

private final String fBase64Image;
private String fBase64Image;

/**
* Creates a new TipImage with the specified URL which gets read into a base 64
Expand Down Expand Up @@ -82,7 +82,6 @@ public boolean isURLSet() {
*
* @param base64Image
* the non-null base64 encoded image according to RFC-2397.
*
* @throws RuntimeException
* if the string is not valid
* @see TipImage
Expand All @@ -98,7 +97,6 @@ public TipImage(String base64Image) {
int from = base64Image.indexOf('/') + 1;
int to = base64Image.indexOf(';');
setExtension(base64Image.substring(from, to).trim());
setExtension(base64Image.substring(from, to).trim());
} else {
int length = base64Image.length();
throw new RuntimeException(Messages.TipImage_5 + base64Image.substring(0, length < 50 ? length : 50));
Expand Down Expand Up @@ -205,15 +203,16 @@ public TipImage setAspectRatio(double aspectRatio) {

/**
* Changes the default value "null" to the passed value which commonly is "png",
* "gif" and such.
* "gif" and updates the URL if the URL constructor was used or updates the
* Base64Image if the base64 constructor was used.
*
* @param extension
* the extension of this file
* @param newExtension the new extension of this file
* @return this
* @see #getExtension()
*/
public TipImage setExtension(String extension) {
fExtension = extension;
public TipImage setExtension(String newExtension) {
fBase64Image = fBase64Image.replaceAll("/.*;", "/" + newExtension + ";"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
fExtension = newExtension;
return this;
}

Expand Down Expand Up @@ -292,4 +291,8 @@ private String getExtension() {
}
return fExtension;
}

public URL getURL() {
return fURL;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,12 @@ public void testAssertWidth() {

@Test
public void testSetExtension() {
// assertTrue(getTipImage().getIMGAttributes(19, 10).contains("png"));
assertTrue(getTipImage().getBase64Image().contains("png"));
}

@Test
public void testSetExtension2() {
// assertTrue(getTipImage().setExtension("bmp").getBase64Image().contains("bmp"));
// assertTrue(getTipImage().getIMGAttributes(19, 10).contains("png"));
assertTrue(getTipImage().setExtension("bmp").getBase64Image().contains("bmp"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,12 @@ public void testGetIMGAttributes() throws IOException {
}

@Test
public void testSetExtension() {
// assertTrue(getTipImage().getIMGAttributes(19, 10).contains("png"));
public void testSetExtension() throws IOException {
assertTrue(getTipImage().getBase64Image().contains("png"));
}

@Test
public void testSetExtension2() {
// assertTrue(getTipImage().setExtension("bmp").getBase64Image().contains("bmp"));
// assertTrue(getTipImage().getIMGAttributes(19, 10).contains("png"));
public void testSetExtension2() throws IOException {
assertTrue(getTipImage().setExtension("bmp").getBase64Image().contains("bmp"));
}
}

0 comments on commit 991d97c

Please sign in to comment.