0

I have two really simple interfaces

public interface Decoder {
    public void decode() throws Exception;
}


public interface Encoder {
    public void Encode() throws Exception;
}

How can I test these two interfaces using mockito?

Jeroen Vannevel
  • 43,651
  • 22
  • 107
  • 170
  • 9
    What do you want to test? There is nothing to test with an interface.. – Jeroen Vannevel Apr 20 '14 at 17:43
  • I have an encoding/decoding project that is meant to have 100% test coverage. I assume I am even being asked to test something as simple as interfaces. – prodigylover Apr 20 '14 at 17:55
  • @prodigylover: But an interface has no functionality. There are no code paths to test. – Oliver Charlesworth Apr 20 '14 at 17:55
  • 1
    You have to test the implementations of your interfaces. Or test the classes that have a field of type `Decoder`/`Encoder` and mock these interfaces. But not the interface itself, that doesn't make sense. – Jeroen Vannevel Apr 20 '14 at 17:56
  • @JeroenVannevel do you mind if I ask you something via your facebook account? – prodigylover Apr 20 '14 at 18:00
  • @prodigylover: I don't mind, but it might be better if you do it on [the chat](http://chat.stackoverflow.com/rooms/139/java) instead. Other people will be able to chime in then. – Jeroen Vannevel Apr 20 '14 at 18:03
  • maybe related http://stackoverflow.com/questions/1087339/using-mockito-to-test-abstract-classes http://www.rallydev.com/community/engineering/easy-way-test-abstract-classes-mockito http://www.java-producties.nl/testing/unit-testing-a-abstract-class-with-mockito/ – Ray Tayek Apr 20 '14 at 21:56

1 Answers1

1

As Jeroen mentioned in the comments:

What do you want to test? There is nothing to test with an interface.

Instead:

You have to test the implementations of your interfaces. Or test the classes that have a field of type Decoder/Encoder and mock these interfaces. But not the interface itself, that doesn't make sense.

Jeff Bowman
  • 90,959
  • 16
  • 217
  • 251