Skip to content

Commit

Permalink
Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
johncarl81 committed May 26, 2016
1 parent d98ba71 commit 4129455
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 1 deletion.
Expand Up @@ -51,7 +51,7 @@ public boolean inherits(ASTType astType, ASTType inheritable) {
if (astType == null) {
return false;
}
if(inheritable.equals(OBJECT_TYPE)){
if(inheritable == null || inheritable.equals(OBJECT_TYPE)){
return true;
}
if (astType.equals(inheritable)) {
Expand Down
@@ -0,0 +1,87 @@
package org.androidtransfuse.adapter;

import org.androidtransfuse.adapter.classes.ASTClassFactory;
import org.junit.*;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

/**
* @author John Ericksen
*/
public class ASTUtilsTest {

public static class A extends B{}
public static class B extends C implements D{}
public interface D{}
public static class C implements E{}
public interface E extends F, G {}
public interface F {}
public interface G {}
public static class H{}
public interface I{}

private ASTType a;
private ASTType b;
private ASTType c;
private ASTType d;
private ASTType e;
private ASTType f;
private ASTType g;
private ASTType h;
private ASTType i;
private ASTType objectType;

private ASTUtils astUtils;

@Before
public void setup() {
ASTClassFactory classFactory = new ASTClassFactory();
a = classFactory.getType(A.class);
b = classFactory.getType(B.class);
c = classFactory.getType(C.class);
d = classFactory.getType(D.class);
e = classFactory.getType(E.class);
f = classFactory.getType(F.class);
g = classFactory.getType(G.class);
h = classFactory.getType(H.class);
i = classFactory.getType(I.class);
objectType = classFactory.getType(Object.class);

astUtils = ASTUtils.getInstance();
}

@Test
public void testExtends() {
assertTrue(astUtils.inherits(a, b));
assertTrue(astUtils.inherits(a, c));
assertFalse(astUtils.inherits(a, h));
assertTrue(astUtils.inherits(a, objectType));
assertFalse(astUtils.inherits(b, a));
assertFalse(astUtils.inherits(c, a));
}

@Test
public void testInherits() {
assertTrue(astUtils.inherits(a, d));
assertTrue(astUtils.inherits(a, e));
assertTrue(astUtils.inherits(a, f));
assertTrue(astUtils.inherits(a, g));
assertTrue(astUtils.inherits(e, f));
assertTrue(astUtils.inherits(e, g));
assertFalse(astUtils.inherits(e, h));
assertFalse(astUtils.inherits(d, e));
assertFalse(astUtils.inherits(a, i));
}

@Test
public void testNull() {
assertTrue(astUtils.inherits(a, null));
assertFalse(astUtils.inherits(null, null));
}

@Test
public void testSelf() {
assertTrue(astUtils.inherits(a, a));
}
}

0 comments on commit 4129455

Please sign in to comment.