Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for ball logic in image resolver page #141

Merged
merged 21 commits into from
Dec 11, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"java.configuration.updateBuildConfiguration": "automatic"
"java.configuration.updateBuildConfiguration": "automatic",
"java.debug.settings.onBuildFailureProceed": true
}
10 changes: 6 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,12 @@
<artifactId>ionicons-api</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<version>2.13.0</version>

<scope>test</scope>
</dependency>
Okhan-coder marked this conversation as resolved.
Show resolved Hide resolved
</dependencies>

<dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package org.jenkinsci.plugins.badge;



import org.junit.ClassRule;
import hudson.model.BallColor;

import org.junit.Test;


import org.jvnet.hudson.test.JenkinsRule;

import org.mockito.Mockito;
import org.mockito.Spy;
Okhan-coder marked this conversation as resolved.
Show resolved Hide resolved

import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.mock;

import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.lessThan;

import java.io.IOException;

public class ImageResolverTest {
@ClassRule
public static JenkinsRule jenkinsRule = new JenkinsRule();

@Test
public void TestGetDefault32x32Ball() throws Exception {
ImageResolver ImageTester = new ImageResolver();
String style="ball-null"; // should give default due to url being null
String status = null;
String subject = null;
String colorName=null;
String fileName = "images/32x32/blue.png";
BallColor ball = mock(BallColor.class);
//default
Mockito.when(ball.getImageOf("null")).thenReturn(null);
Mockito.when(ball.getImageOf("32x32")).thenReturn(fileName);
Mockito.when(ball.noAnime()).thenCallRealMethod();
StatusImage TestImage = ImageTester.getImage(ball, style,subject,status, colorName, null, null);
assertThat(TestImage.getEtag(), containsString(fileName));


}
@Test
public void TestGetNonDefaultBall() throws Exception {
ImageResolver ImageTester = new ImageResolver();
String style="ball-16x16"; // should give url
String status = null;
String subject = null;
String colorName=null;
String fileName = "images/16x16/red.png";
BallColor ball = mock(BallColor.class);
//default
Mockito.when(ball.getImageOf("null")).thenReturn(null);
Mockito.when(ball.getImageOf("16x16")).thenReturn(fileName);
Mockito.when(ball.noAnime()).thenCallRealMethod();
StatusImage TestImage = ImageTester.getImage(ball, style,subject,status, colorName, null, null);
assertThat(TestImage.getEtag(), containsString(fileName));


}
@Test
public void testShouldReturnEmpty() throws Exception {
ImageResolver ImageTester = new ImageResolver();
String style="ball-42x45"; // should throw exception
String status = null;
String subject = null;
String colorName=null;
String fileName = "DoesNotExist";;
BallColor ball = mock(BallColor.class);
//default
Mockito.when(ball.getImageOf("null")).thenReturn(null);
Mockito.when(ball.getImageOf("42x45")).thenReturn(fileName);
Mockito.when(ball.noAnime()).thenCallRealMethod();
StatusImage TestImage = ImageTester.getImage(ball, style,subject,status, colorName, null, null);
assertThat(TestImage.getEtag(), containsString("empty"));


}
}