2017-05-10 4 views
1

Ich entwickle gerade eine Java 8-Anwendung in IntelliJ IDE. Ich kam in JetBrains annotations und ich begann sie wie folgt verwendet:org.jetbrains: Anmerkungen funktionieren nicht, wenn Maven-Tests manuell ausgeführt werden

public class ClassA { 
    public ClassA(@NotNull ClassB classB, @NotNull ClassC classC) { 
     ... 
    } 
} 

und Testdatei wie folgt aus:

public class ClassATest { 
    @Test(expected = IllegalArgumentException.class) 
    public void testConstructorNull1() { 
     new ClassA(null, null); 
    } 
} 

Solange ich Anwendung leite/Tests von IDE Anmerkungen arbeiten, aber wenn ich laufen z.B mvn tests von der Befehlszeile, bekomme ich eine Menge von NullPointerException anstelle der erwarteten IllegalArgumentException beim Testen null Argumente. Es scheint, dass die Anmerkungen ignoriert werden.

Ich gehe davon aus Problem irgendwo in eine falsche Konfiguration von pom.xml die wie folgt aussieht:

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>...</groupId> 
    <artifactId>...</artifactId> 
    <version>...</version> 

    <name>...</name> 
    <description>...</description> 

    <properties> 
     <java.version>1.8</java.version> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    </properties> 

    <dependencies> 
     <dependency> 
      <groupId>com.google.code.gson</groupId> 
      <artifactId>gson</artifactId> 
      <version>2.8.0</version> 
     </dependency> 

     <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>4.12</version> 
      <scope>test</scope> 
     </dependency> 

     <dependency> 
      <groupId>log4j</groupId> 
      <artifactId>log4j</artifactId> 
      <version>1.2.17</version> 
     </dependency> 

     <dependency> 
      <groupId>org.mockito</groupId> 
      <artifactId>mockito-core</artifactId> 
      <version>2.7.22</version> 
      <scope>test</scope> 
     </dependency> 

     <dependency> 
      <groupId>org.antlr</groupId> 
      <artifactId>antlr4</artifactId> 
      <version>4.7</version> 
     </dependency> 

     <dependency> 
      <groupId>org.apache.commons</groupId> 
      <artifactId>commons-lang3</artifactId> 
      <version>3.5</version> 
     </dependency> 

     <dependency> 
      <groupId>org.jetbrains</groupId> 
      <artifactId>annotations</artifactId> 
      <version>15.0</version> 
     </dependency> 

     <dependency> 
      <groupId>com.google.guava</groupId> 
      <artifactId>guava</artifactId> 
      <version>19.0</version> 
     </dependency> 
    </dependencies> 

    <build> 
     <finalName>...</finalName> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>3.6.1</version> 
       <configuration> 
        <source>${java.version}</source> 
        <target>${java.version}</target> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 
</project> 

Haben Sie eine Ahnung, was ich falsch gemacht habe? Vielen Dank.

Plattform: GNU/Linux (Kubuntu 16.04)
Java: OpenJDK 1.8.0_121
Maven: 3.3.9

Antwort

0

Es wird funktionieren, wenn Sie Maven Plugin hinzufügen:

<pluginRepositories> 
    <pluginRepository> 
     <id>repository.jetbrains.com</id> 
     <name>repository.jetbrains.com-all</name> 
     <url>http://repository.jetbrains.com/all</url> 
     <snapshots> 
      <enabled>true</enabled> 
     </snapshots> 
    </pluginRepository> 
</pluginRepositories> 

<build> 
    <plugins> 
     <plugin> 
      <groupId>com.intellij</groupId> 
      <artifactId>notnull-instrumenter-maven-plugin</artifactId> 
      <version>1.0-SNAPSHOT</version> 
      <executions> 
       <execution> 
        <goals> 
         <goal>instrument</goal> 
         <goal>tests-instrument</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build> 
Verwandte Themen