Skip to content

Commit

Permalink
added junit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Michail Plushnikov committed Apr 17, 2016
1 parent 856fab9 commit 34b038c
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 12 deletions.
Expand Up @@ -128,7 +128,7 @@ private OrderEntry findLombokEntry(@NotNull ModuleRootManager moduleRootManager)
} }


@Nullable @Nullable
private String parseLombokVersion(@Nullable OrderEntry orderEntry) { protected String parseLombokVersion(@Nullable OrderEntry orderEntry) {
String result = null; String result = null;
if (null != orderEntry) { if (null != orderEntry) {
final String presentableName = orderEntry.getPresentableName(); final String presentableName = orderEntry.getPresentableName();
Expand All @@ -141,26 +141,25 @@ private String parseLombokVersion(@Nullable OrderEntry orderEntry) {
return result; return result;
} }


private int compareVersionString(@NotNull String versionOne, @NotNull String versionTwo) { protected int compareVersionString(@NotNull String firstVersionOne, @NotNull String secondVersion) {
String[] thisParts = versionOne.split("\\."); String[] firstVersionParts = firstVersionOne.split("\\.");
String[] thatParts = versionTwo.split("\\."); String[] secondVersionParts = secondVersion.split("\\.");
int length = Math.max(thisParts.length, thatParts.length); int length = Math.max(firstVersionParts.length, secondVersionParts.length);
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
int thisPart = i < thisParts.length ? int firstPart = i < firstVersionParts.length && !firstVersionParts[i].isEmpty() ?
Integer.parseInt(thisParts[i]) : 0; Integer.parseInt(firstVersionParts[i]) : 0;
int thatPart = i < thatParts.length ? int secondPart = i < secondVersionParts.length && !secondVersionParts[i].isEmpty() ?
Integer.parseInt(thatParts[i]) : 0; Integer.parseInt(secondVersionParts[i]) : 0;
if (thisPart < thatPart) { if (firstPart < secondPart) {
return -1; return -1;
} }
if (thisPart > thatPart) { if (firstPart > secondPart) {
return 1; return 1;
} }
} }
return 0; return 0;
} }



/** /**
* Simple {@link NotificationListener.Adapter} that opens Settings Page for correct dialog. * Simple {@link NotificationListener.Adapter} that opens Settings Page for correct dialog.
*/ */
Expand Down
@@ -0,0 +1,75 @@
package de.plushnikov.intellij.plugin;

import com.intellij.openapi.roots.OrderEntry;
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class LombokPluginProjectValidatorComponentTest {

private LombokPluginProjectValidatorComponent component;
private OrderEntry orderEntry;

@Before
public void setUp() throws Exception {
component = new LombokPluginProjectValidatorComponent(null);
orderEntry = mock(OrderEntry.class);
}

@Test
public void parseLombokVersionFromGradle() throws Exception {
when(orderEntry.getPresentableName()).thenReturn("Gradle: org.projectlombok:lombok:1.16.8");
assertEquals("1.16.8", component.parseLombokVersion(orderEntry));
}

@Test
public void parseLombokVersionFromMaven() throws Exception {
when(orderEntry.getPresentableName()).thenReturn("Maven: org.projectlombok:lombok:1.16.6");
assertEquals("1.16.6", component.parseLombokVersion(orderEntry));
}

@Test
public void parseLombokVersionFromUnknown() throws Exception {
when(orderEntry.getPresentableName()).thenReturn("lombok");
assertNull(component.parseLombokVersion(orderEntry));
}

@Test
public void compareVersionString1_2() throws Exception {
assertEquals(-1, component.compareVersionString("1", "2"));
}

@Test
public void compareVersionString__2() throws Exception {
assertEquals(-1, component.compareVersionString("", "2"));
}

@Test
public void compareVersionString123_121() throws Exception {
assertEquals(1, component.compareVersionString("1.2.3", "1.2.1"));
}

@Test
public void compareVersionString1166_1168() throws Exception {
assertEquals(-1, component.compareVersionString("1.16.6", "1.16.8"));
}

@Test
public void compareVersionString1168_1168() throws Exception {
assertEquals(0, component.compareVersionString("1.16.8", "1.16.8"));
}

@Test
public void compareVersionString0102_1168() throws Exception {
assertEquals(-1, component.compareVersionString("0.10.2", "1.16.8"));
}

@Test
public void compareVersionString1169_1168() throws Exception {
assertEquals(1, component.compareVersionString("1.16.9", "1.16.8"));
}
}

0 comments on commit 34b038c

Please sign in to comment.