Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: a1e575f7083d8e89b089b9bcab04a17091d388bd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*******************************************************************************
 * Copyright (c) 2018 Remain Software
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     wim.jongman@remainsoftware.com - initial API and implementation
 *******************************************************************************/
package org.eclipse.tips.core;

import static org.junit.Assert.assertTrue;

import org.eclipse.core.runtime.AssertionFailedException;
import org.junit.Test;

public class TipImageBas64Test {

	private static final String BASE64 = "data:image/png;base64,thequickbrownfox";
	private static final String BASE64WRONG = "date:image/png;base64,thequickbrownfox";
	private static final String BASE64WRONG2 = "data:image/plip ;base64,thequickbrownfox";

	private TipImage getTipImage() {
		return new TipImage(BASE64);
	}

	@Test(expected = AssertionFailedException.class)
	public void testAssertHeight() {
		new TipImage(BASE64).setAspectRatio(1000, 0, false);
	}

	@Test(expected = AssertionFailedException.class)
	public void testAssertWidth() {
		new TipImage(BASE64).setAspectRatio(0, 100, false);
	}

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

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

	@Test
	public void testGetIMGAttributes() {
		String result = getTipImage().setAspectRatio(1.5).getIMGAttributes(740, 370).trim();
		assertTrue(result, result.equalsIgnoreCase("width=\"555\" height=\"370\""));
	}

	@Test
	public void testGetBase64() {
		assertTrue(getTipImage().getBase64Image().equals(BASE64));
	}

	@Test
	public void testSetAspectRatioDouble() {
		String result = getTipImage().setAspectRatio(1.5).getIMGAttributes(740, 370).trim();
		assertTrue(result, result.equalsIgnoreCase("width=\"555\" height=\"370\""));
	}

	@Test
	public void testSetAspectRatioIntIntFalse() {
		String result = getTipImage().setAspectRatio(200, 50, false).getIMGAttributes(100, 100).trim();
		assertTrue(result, result.equalsIgnoreCase("width=\"100\" height=\"25\""));
	}

	@Test
	public void testSetAspectRatioIntIntTrue() {
		String result = getTipImage().setAspectRatio(400, 300, true).getIMGAttributes(740, 370).trim();
		assertTrue(result, result.equalsIgnoreCase("width=\"400\" height=\"300\""));
	}

	@Test
	public void testSetMaxHeight() {
		String imgAttributes = new TipImage(BASE64).setAspectRatio(2).setMaxHeight(300).getIMGAttributes(200, 200);
		assertTrue(imgAttributes, imgAttributes.trim().equalsIgnoreCase("width=\"200\" height=\"100\""));
	}

	@Test
	public void testSetMaxWidth() {
		String imgAttributes = new TipImage(BASE64).setAspectRatio(1.6).setMaxWidth(200).getIMGAttributes(400, 300);
		assertTrue(imgAttributes, imgAttributes.trim().equalsIgnoreCase("width=\"200\" height=\"125\""));
	}

	public void testTipImage() {
		new TipImage(BASE64);
	}

	@Test
	public void testTipImage2() {
		getTipImage();
	}

	@Test(expected = RuntimeException.class)
	public void testTipImage3() {
		new TipImage(BASE64WRONG);
	}

	public void testTipImage4() {
		TipImage tipImage = new TipImage(BASE64WRONG2);
		assertTrue(tipImage.getIMGAttributes(1, 1).contains("plip"));
	}
}

Back to the top