gradle junit和错误:找不到符号

时间:2015-11-07 10:13:21

标签: java gradle junit compiler-errors

我正在尝试从gradle上运行一个简单的junit测试,我已编译并部署到aws lambda的概念证明类。类# fake some data into states_2 # # Cor metric K Q Category gamma # 0.33 APD 2s 0.4mu 64spp -0.25282382 # 0.23 APD 2s 0.4mu 64spp -0.653438937 # 0.21 APD 2s 0.4mu 64spp 0.799639202 # 0.14 APD 2s 0.4mu 64spp 1.039215902 # 0.37 APD 2s 0.4mu 64spp 0.207669854 # n <- 100 cor <- rnorm(n,0.25) me <- sample(c("APD","APE","APF"),n,replace=T) kk <- sample(c("2s","3t","4u"),n,replace=T) qq <- sample(c("0.2mu","0.3mu","0.4mu","0.5mu","0.6mu"),n,replace=T) ca <- sample(c("64spp","80spp"),n,replace=T) ga <- rnorm(n,0.5,2) states_2 <- data.frame(Cor=cor,metric=me,K=kk,Q=qq,Category=ca,gamma=ga) # plot it plot_2 <- ggplot(data=states_2)+ ggtitle("TBD ")+xlab("q")+ylab("cor")+ geom_point(aes(x=Q , y= Cor, color=metric, size=gamma, alpha=0.5))+ geom_smooth( aes(x=Q,y=Cor, color=metric,group=(metric)), method="lm",se=FALSE)+ guides(alpha=F) print(plot_2) 使用单个属性Auth.java获取POJO。它可以自行编译并在aws上运行。但是,当我跑:

email

我收到以下错误:

gradle build

如果我Auth.java:6: error: cannot find symbol System.out.println(payload.email); symbol: variable email location: variable payload of type Object 1 error :compileJava FAILED 内的System.out.println(payload.email);我可以访问该对象的属性没问题。我在这里没有掌握一些关键的java或gradle概念吗?我已经用5种不同的方式重构了这个东西,但是,我总是收到这个找不到符号的错误。有人有什么想法吗?这是我的简化代码。

./ SRC /主/爪哇/ Auth.java

TestAuth.java

./ SRC /测试/ JAVA / TestAuth.java

package works.valt.api;

public class Auth {

    public Auth(Object payload) {
        System.out.println(payload.email);
    }

}

}

的build.gradle

import org.junit.Test;
import org.junit.Before;
import static org.junit.Assert.assertEquals;
import works.valt.api.Auth;

public class TestAuth {

    public class Payload {
      public String email = "test@testing.com";
    }

    private Payload payload;

    // create payload
    @Before
    public void setUp() {
      this.payload = new Payload();
    }    

   @Test
   public void testResponse() {
      Auth response = new Auth(this.payload);
   }

3 个答案:

答案 0 :(得分:1)

这是Auth

的构造函数
public Auth(Object payload) {
    System.out.println(payload.email);
}

payload参数的类型为Object,因此在Object类定义中找不到字段email,这就是编译器抱怨的内容:

Auth.java:6: error: cannot find symbol
System.out.println(payload.email);
symbol:   variable email
location:
variable payload of type Object

您可以将参数类型更改为Payload,也可以在构造函数中转换引用并松散一些编译时类型的安全性

答案 1 :(得分:1)

already_printed的构造函数具有Object类型的参数。并且Auth类没有名为Object的变量。将参数类型更改为email

答案 2 :(得分:0)

问题是有效载荷是一个对象而不是有效载荷

为了访问该属性,您必须实际说它是有效负载:

package works.valt.api;

public class Auth {

    public Auth(TestAuth.Payload payload) {
        System.out.println(payload.email);
    }

}