Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Annotations Writing Your Own Annotation Putting It All Together

yaser ABDSI
PLUS
yaser ABDSI
Courses Plus Student 517 Points

no way!

please help

Test.java
import java.lang.annotation.ElementType;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;


@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Test {

  String username() default " ";
  String[] param() default {};


}
SocialNetworkTest.java
public class SocialNetworkTest {
  @Test(username = "Yaser", param = {"1","2"})
  public void testTweet() {

  }
  @Test(username = "Yaser", param = {"1","2"})
  public void testInsta() { 

  }
  @Test(username = "Yaser", param = {"1","2"})
  public void testFacebook() { 

  }

  public void testPinterest() { 

  }

  public void testSnapchat() { 

  }
}
TestAnalyzer.java
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

public class TestAnalyzer {
  /**
   *  Counts the number of methods in the class given by `clazz` that have been annotated
   *  with the @Test annotation.
   */
  public static int getNumAnnotatedMethods(Class<?> clazz) {
    if(Class.getAnnotation(clazz).equals(Test.class)){
    return clazz.getDeclaredMethods().length;  }
  }
}

1 Answer

What part are you stuck on?

Use the Title slot to give a brief overview of your problem. This will increase your chances of getting help. Putting "no way!" and "please help" is too vague and people will be unlikely to answer.