
рдЬреИрд╕рд╛ рдХрд┐ рдЖрдкрдиреЗ рджрд╛рдИрдВ рдУрд░ рдХреА рддрд╕реНрд╡реАрд░ рд╕реЗ рдЕрдиреБрдорд╛рди рд▓рдЧрд╛рдпрд╛ рд╣реИ, рд╣рдо рд╕реНрд╡рдЪрд╛рд▓рд┐рдд рдкрд░реАрдХреНрд╖рдг рдХреЗ рдмрд╛рд░реЗ рдореЗрдВ рдмрд╛рдд рдХрд░реЗрдВрдЧреЗред рдореИрдЪрд░реНрд╕ рдХреЗ рд░реВрдк рдореЗрдВ рдРрд╕реА рддрдХрдиреАрдХ рдХреЗ рдмрд╛рд░реЗ рдореЗрдВ рдЕрдзрд┐рдХ рд╕рдЯреАрдХ рд░реВрдк рд╕реЗред рд╡реЗ рдХреЛрдб рдбреБрдкреНрд▓реАрдХреЗрд╢рди рдХреЛ рдЧрдВрднреАрд░рддрд╛ рд╕реЗ рдХрдо рдХрд░рдиреЗ рдФрд░ рдзрд╛рд░рдгрд╛ рдХреЗ рд▓рд┐рдП рдкрд░реАрдХреНрд╖рдг рдХреЛрдб рдХреЛ рд╕рд░рд▓ рдмрдирд╛рдиреЗ рдореЗрдВ рдорджрдж рдХрд░рддреЗ рд╣реИрдВ, рдФрд░ рдореИрдЪрд░реНрд╕ рдХрд╛ рдирд┐рд░реНрдорд╛рдг рдФрд░ рдЙрдкрдпреЛрдЧ рдХрд░рдирд╛ рдХрд╛рдлреА рд╕рд░рд▓ рд╣реИред
рдореИрдЪрд░реНрд╕ рдХреА рддрдХрдиреАрдХ рдЕрдкрдиреЗ рдЖрдк рдореЗрдВ рдирдИ рдирд╣реАрдВ рд╣реИ - рдЕрдкрдиреЗ рд╡рд░реНрддрдорд╛рди рд╕реНрд╡рд░реВрдк рдореЗрдВ рдЗрд╕реЗ рдЬреБрд▓рд╛рдИ 2012 рдореЗрдВ рд░рд┐рдкреЙрдЬрд┐рдЯрд░реА рдореЗрдВ рдЕрдкрд▓реЛрдб рдХрд┐рдпрд╛ рдЧрдпрд╛ рдерд╛, рдФрд░ рдпрд╣ рдкрд╣рд▓реЗ рднреА рджрд┐рдЦрд╛рдИ рджреА рдереАред рд▓реЗрдХрд┐рди, рдЗрд╕рдХреЗ рдмрд╛рд╡рдЬреВрдж, рдХрдИ рдиреЗ рдЕрднреА рднреА рдЗрд╕рдХреЗ рдмрд╛рд░реЗ рдореЗрдВ рдирд╣реАрдВ рд╕реБрдирд╛ рд╣реИ, рдпрд╛ рдХрд┐рд╕реА рдХрд╛рд░рдг рд╕реЗ рдЗрд╕рд╕реЗ рдмрдЪреЗрдВред рд╣рдо рдЖрдкрдХреЛ рдпрд╣ рдмрддрд╛рдирд╛ рдЪрд╛рд╣рддреЗ рд╣реИрдВ рдХрд┐ рдЗрд╕рдХреЗ рдЙрдкрдпреЛрдЧ рд╕реЗ рд▓рд╛рдн рдкреНрд░рд╛рдкреНрдд рдХрд░рдирд╛ рдХрд┐рддрдирд╛ рдЖрд╕рд╛рди рд╣реИ, рдФрд░ рдЖрдкрдХреЗ рд╕рд╛рде рд╣рдорд╛рд░реА рд▓рд╛рдЗрдмреНрд░реЗрд░реА рдСрдлрд╝ рдореИрдЪрд░реНрд╕ рд╕рд╛рдЭрд╛ рдХрд░рдирд╛ рд╣реИред
рдорд╛рди рд▓реАрдЬрд┐рдП рдХрд┐ рд╣рдорд╛рд░реЗ рдкрд╛рд╕ рдХреБрдЫ рдлрд▓реЛрдВ рдХрд╛ рдПрдХ рд╕реЗрдЯ рд╣реИред рдЙрдирдореЗрдВ рд╕реЗ, рд╕рдмрд╕реЗ рдЖрдо рджреМрд░, рдирд╛рд░рдВрдЧреА рдФрд░ рдореАрдард╛ред
public class Fruit { ... public Color getColor() {...} public boolean isSweet() {...} public Shape getShape() {...} }
рдпрд╣ рдЬреНрдЮрд╛рдд рд╣реИ рдХрд┐ рдПрдХ рдирд╛рд░рдВрдЧреА рдРрд╕реА рд╕реНрдерд┐рддрд┐рдпреЛрдВ рдХреЛ рд╕рдВрддреБрд╖реНрдЯ рдХрд░рддрд╛ рд╣реИред рдлрд▓реЛрдВ рдХреЗ рдЕрд▓рд╛рд╡рд╛, рд╣рдорд╛рд░реЗ рдкрд╛рд╕ рдПрдХ рдХрдиреНрд╡реЗрдпрд░ рднреА рд╣реИ рдЬрд┐рд╕рдХреЗ рдорд╛рдзреНрдпрдо рд╕реЗ рдРрд╕реЗ рдлрд▓реЛрдВ рдХреЛ рдкрд╛рд░рд┐рдд рдХрд┐рдпрд╛ рдЬрд╛ рд╕рдХрддрд╛ рд╣реИред рдХрдиреНрд╡реЗрдпрд░ рдХреЗ рд▓рд┐рдП рдПрдХ рдХрд╛рд░реНрдп рднреА рд╣реИ - рдкрд░реАрдХреНрд╖рдгреЛрдВ рдХреА рдПрдХ рд╢реНрд░реГрдВрдЦрд▓рд╛ рдХрд╛ рдЖрдпреЛрдЬрди рдХрд░рдХреЗ рд╕рдВрддрд░реЗ рдХреЛ рдирд╣реАрдВ рдирд┐рдЪреЛрдбрд╝рдирд╛ред
рдФрд░ рд╕реМрднрд╛рдЧреНрдп - рд╣рдорд╛рд░реЗ рдкрд╛рд╕ рдмрд╕ рдПрдХ рдРрд╕рд╛ рдЙрдкрдХрд░рдг рдерд╛ рдЬреЛ рдпрд╣ рдирд┐рд░реНрдзрд╛рд░рд┐рдд рдХрд░ рд╕рдХрддрд╛ рдерд╛ рдХрд┐ рдХреЛрдИ рдлрд▓ рдореАрдард╛ рдерд╛ рдФрд░ рдЙрд╕рдХрд╛ рд░рдВрдЧ рдХреИрд╕рд╛ рдерд╛, рдЙрд╕рдХреЗ рдЖрдХрд╛рд░ рдХреА рддреБрд▓рдирд╛ рдХрдИ рдкреНрд░рд╕рд┐рджреНрдз рд▓реЛрдЧреЛрдВ рдХреЗ рд╕рд╛рде рдХрд░реЗрдВ рдФрд░ рдХрдИ рдФрд░ рдЬрд╛рдБрдЪ рдХрд░реЗрдВред рдЗрд╕ рдЙрдкрдХрд░рдг рдХреЛ
JUnit рдХрд╣рд╛ рдЬрд╛рддрд╛ рд╣реИред
рдкрд░реАрдХреНрд╖рдг рд╢реБрд░реВ рд╣реЛрдиреЗ рд╕реЗ рдкрд╣рд▓реЗ, рдПрдХ рдирдпрд╛ рдлрд▓ рдХрдиреНрд╡реЗрдпрд░ рдкрд░ рдкрдбрд╝рддрд╛ рд╣реИред
@Before public void setUp() throws Exception { someFruit = getNextFruit(); }
рдкрд╣рд▓реЗ рд╣рдо рдпрд╣ рдирд┐рд░реНрдзрд╛рд░рд┐рдд рдХрд░рддреЗ рд╣реИрдВ рдХрд┐ рдлрд▓ рдЧреЛрд▓ рд╣реИред
@Test public void orangeIsRound() { assertEquals("Expected shape - " + Shape.ROUND + ", but was - " + someFruit.getShape(), someFruit.getShape(), Shape.ROUND); }
рддрдм рд╡рд╣ рдлрд▓ рдореАрдард╛ рд╣реЛрддрд╛ рд╣реИред
@Test public void orangeIsSweet() { assertTrue("Fruit should be sweet - expected TRUE", someFruit.isSweet()); }
рдФрд░ рдЕрдВрдд рдореЗрдВ, рдЗрд╕рдХреЗ рд░рдВрдЧ рдХреЛ рджреЗрдЦреЗрдВред
@Test public void orangeHasOrangeColor() { assertEquals("Orange has orange color, but was - " + someFruit.getColor(), someFruit.getColor(), Color.ORANGE); }
рддреБрд░рдВрдд рд╕реНрдкрд╖реНрдЯ рдХреНрдпрд╛ рд╣реИрдВ? рд╕рдмрд╕реЗ рдкрд╣рд▓реЗ, рдкреНрд░рддреНрдпреЗрдХ рдЪреЗрдХ рдореЗрдВ рдЕрдкреЗрдХреНрд╖рд┐рдд рдореВрд▓реНрдп, рд╡рд╛рд╕реНрддрд╡рд┐рдХ рдореВрд▓реНрдп, рдЕрддрд┐рд░рд┐рдХреНрдд рд╢реЛрдзрди рдХреЗ рдореВрд▓реНрдп рдФрд░ рд╡рд┐рднрд┐рдиреНрди рдЕрдиреБрдорд╛рдиреЛрдВ рдХреЗ рд╕рд╛рде рдПрдХ рдЯрд┐рдкреНрдкрдгреА рдХреЛ рдЧреЛрдВрдж рдХрд░рдирд╛ рдЖрд╡рд╢реНрдпрдХ рдерд╛ред рдпрд╣рд╛рдВ рддрдХ тАЛтАЛрдХрд┐ рдЗрд╕ рд╕реВрдЪреА рдХрд╛ рд╡рд░реНрдгрди рдердХрд╛рдК рд╣реИред
рджреВрд╕рд░реЗ, рдХрд▓реНрдкрдирд╛ рдХреАрдЬрд┐рдП рдХрд┐ рд╣рдордиреЗ рд╕рдВрддрд░реЗ рдХреА рдХрд┐рд╕реНрдо рдХреЛ рднреА рдирд┐рд░реНрдзрд╛рд░рд┐рдд рдХрд░рдиреЗ рдХрд╛ рдлреИрд╕рд▓рд╛ рдХрд┐рдпрд╛ рд╣реИ, рдЗрд╕рдХреЗ рд▓рд┐рдП рдПрдХ рд╡рд┐рд╢реЗрд╖ "рдЯрд╕реНрдЯрд░" рдЬреЛрдбрд╝рд╛ рд╣реИ, рдФрд░ рдЙрд╕рд╕реЗ рдХрд╣рд╛: "рдХреЗрд╡рд▓ рд╡рд╛рд▓реЗрдВрд╕рд┐рдпрд╛ рдХрд┐рд╕реНрдо рдХреЛ рд╕реНрд╡реАрдХрд╛рд░ рдХрд░реЗрдВред" рд▓реЗрдХрд┐рди "рддреЗрдЬрд╝" рдХреЛ рдирд╣реАрдВ рдкрддрд╛ рд╣реИ рдХрд┐ рдкрд░реАрдХреНрд╖рдг рдорд╢реАрди рдиреЗ рдХреНрдпрд╛ рдлреИрд╕рд▓рд╛ рдХрд┐рдпрд╛ рд╣реИ, рдЕрдЧрд░ рд╡рд╣ рдЦреБрдж рд╕реЗ рдирд╣реАрдВ рдкреВрдЫрддрд╛ рд╣реИ, рддреЛ рдорд╢реАрди рдмрд╛рддреВрдиреА рдирд╣реАрдВ рд╣реИред рдЕрдВрдд рдореЗрдВ, рд╡рд╣ рдПрдХ рдкрдВрдХреНрддрд┐ рдореЗрдВ рд╕рдм рдХреБрдЫ рдХрд░рдиреЗ рдХреА рдХреЛрд╢рд┐рд╢ рдХрд░реЗрдЧрд╛ред рдПрдХ рдЧреЗрдВрдж рдХреЗ рд╕рд╛рде "рдЯрд╕реНрдЯрд░" рдХреЛ рдЬрд╣рд░ рди рджреЗрдиреЗ рдХреЗ рд▓рд┐рдП, рдХреНрдпреЛрдВрдХрд┐ рдЙрдирдХреЗ рдкрд╛рд╕ рдорд┐рдард╛рд╕ рдХреА рдЬрд╛рдВрдЪ рдХрд░рдиреЗ рдХрд╛ рд╕рдордп рдирд╣реАрдВ рдерд╛, рдЖрдкрдХреЛ рдЙрд╕реЗ рд╕рдм рдХреБрдЫ рдЕрдирджреЗрдЦрд╛ рдХрд░рдирд╛ рд╕рд┐рдЦрд╛рдирд╛ рд╣реЛрдЧрд╛ред рдРрд╕рд╛ рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП, рдЙрд╕реЗ рдорд╢реАрди рд╕реЗ рдЕрд▓рдЧ рдФрд░ рд╕реНрд╡рддрдВрддреНрд░ рд░реВрдк рд╕реЗ рдкреВрдЫрдиреЗ рдХреА рдЬрд░реВрд░рдд рд╣реИ, рдЬрд┐рд╕рдХреЗ рдмрд╛рдж рд╕рднреА рдЦрд╛рд░рд┐рдЬ рдХрд┐рдП рдЧрдП рд▓реЛрдЧреЛрдВ рдХреЛ рдЕрд▓рдЧ рд░рдЦрд╛ рдЬрд╛рдирд╛ рдЪрд╛рд╣рд┐рдП рдФрд░ рдЕрдм рд╕реНрдкрд░реНрд╢ рдирд╣реАрдВ рдХрд░рдирд╛ рдЪрд╛рд╣рд┐рдПред
"рдЬрд╕реНрдЯрд░" рд╣рдорд╛рд░реЗ JUnit рдбрд┐рд╡рд╛рдЗрд╕ рдореЗрдВ рд╕рд┐рд░реНрдл рдПрдХ рдФрд░ рдкрд░реАрдХреНрд╖рдг рд╣реИ, рдЗрд╕рд▓рд┐рдП рдЖрдкрдХреЛ рдкрд░реАрдХреНрд╖рдг рдХреЛ рдорд╛рдирдиреЗ рдХреЗ рд▓рд┐рдП рдЕрдВрддрд░реНрдирд┐рд╣рд┐рдд рд░рдирдЯрд╛рдЗрдо рддрдВрддреНрд░ рдХрд╛ рдЙрдкрдпреЛрдЧ рдХрд░рдирд╛ рдЪрд╛рд╣рд┐рдПред рдлрд┐рд░ рдЪрдЦрдиреЗ рдХреА рд╢реБрд░реБрдЖрдд рдХрд╛ рдкрд░рд┐рджреГрд╢реНрдп рдЗрд╕ рддрд░рд╣ рджрд┐рдЦрд╛рдИ рджреЗрдЧрд╛ред
@Test public void degusto() { assumeTrue("Expected shape - " + Shape.ROUND + ", but was - " + someFruit.getShape(), someFruit.getShape().equals(Shape.ROUND)); assumeTrue("Fruit should be sweet - expected TRUE", someFruit.isSweet()); assumeTrue("Orange has orange color, but was - " + someFruit.getColor(), someFruit.getColor().equals(Color.ORANGE));
рдпрд╣ рд╕реНрдкрд╖реНрдЯ рд░реВрдк рд╕реЗ рджреЗрдЦрд╛ рдЧрдпрд╛ рд╣реИ рдХрд┐ рд╕реНрдХреНрд░рд┐рдкреНрдЯ рдХреЗ рдЗрд╕ рд╡рд┐рд╡рд░рдг рдХреЗ рд╕рд╛рде рдкреНрд░рддреНрдпреЗрдХ рдирдП "рдЯрд╕реНрдЯрд░" рдХреЗ рджреЛ рддрд░реАрдХреЗ рд╣реИрдВ - рд╕реНрдХреНрд░рд┐рдкреНрдЯ рдХреА рдХреЙрдкреА-рдкреЗрд╕реНрдЯ рдХрд░реЗрдВ рдпрд╛ рдкреНрд░реА-рдЪреЗрдХ рдХреЗ рдкреНрд░рддреНрдпреЗрдХ рд╕реЗрдЯ рдХреЗ рд▓рд┐рдП рдПрдХ рдирдИ рд╡рд┐рдзрд┐ рдмрдирд╛рдПрдВред рдФрд░ рдкреНрд░рддреНрдпреЗрдХ рдкреНрд░реА-рдЪреЗрдХ рдореЗрдВ рдлрд┐рд░ рд╕реЗ, рдЖрдкрдХреЛ рдЦреБрдж рдХреЛ рдЕрд╕реНрд╡реАрдХреГрддрд┐ рдХреЗ рдХрд╛рд░рдг рдХреЗ рдмрд╛рд░реЗ рдореЗрдВ рдПрдХ рд╕рдВрджреЗрд╢ рд╕рдВрдХрд▓рд┐рдд рдХрд░рдиреЗ рдХреА рдЖрд╡рд╢реНрдпрдХрддрд╛ рд╣реИред рдЗрдирдореЗрдВ рд╕реЗ рдХреЛрдИ рднреА рд╡рд┐рдХрд▓реНрдк рдмрдирд╛рдП рд░рдЦрдирд╛ рдореБрд╢реНрдХрд┐рд▓ рд╣реИ рдФрд░ рдпрд╣ рджреЗрдЦрдиреЗ рдореЗрдВ рдмрд╣реБрдд рдбрд░рд╛рд╡рдирд╛ рд╣реИред
рдЙрд╕рдХреЗ рд╢реАрд░реНрд╖ рдкрд░, рдЖрдкрдХреЛ
assertEquals
,
assertNotEquals
,
assertNotNull
,
assertArrayEquals
, рдЗрддреНрдпрд╛рджрд┐ рдХреЛ
assertArrayEquals
ред рдорд╛рдирдХ JUnit рдкреИрдХреЗрдЬ рдореЗрдВ, рдпреЗ рдЬреЛрд░ * рд▓рдЧрднрдЧ рдХрд┐рд╕реА рднреА рддреБрдЪреНрдЫ рдорд╛рдорд▓реЗ рдХреЗ рд▓рд┐рдП рд╣реИрдВред рдФрд░ рдХреБрдЫ рдФрд░, рдкреНрд░рддреНрдпреЗрдХ рдкреНрд░рдХрд╛рд░ рдХреЗ рддрд░реНрдХ рдХреЗ рд▓рд┐рдПред рдЕрд░реНрдерд╛рддреН, рд╕рддреНрдпрд╛рдкрди рддрд░реНрдХ рд╡рд┐рдзрд┐ рдХреЗ рдирд╛рдо рдкрд░ рдирд┐рд╣рд┐рдд рд╣реИ рдФрд░ рдЗрд╕рдХреЗ рдХрд╛рд░реНрдпрд╛рдиреНрд╡рдпрди рдХреЗ рд▓рд┐рдП рд╕рдЦреНрддреА рд╕реЗ рдмрдВрдзрд╛ рд╣реБрдЖ рд╣реИред рдЕрдм рдХрд▓реНрдкрдирд╛ рдХрд░реЗрдВ рдХрд┐ рдкреНрд░рддреНрдпреЗрдХ рдЖрдВрд╕рд░ * рдХреЗ рд▓рд┐рдП рдХрд┐рддрдирд╛ рдХреЛрдб рдбреБрдкреНрд▓рд┐рдХреЗрдЯ рдФрд░ рдмрдирд╛рдП рд░рдЦрдиреЗ рдХреА рдЖрд╡рд╢реНрдпрдХрддрд╛ рд╣реЛрдЧреА * рдЖрдкрдХреЛ рдПрдХ рд╕рдорд╛рди рдзрд╛рд░рдгрд╛ рдмрдирд╛рдирд╛ рд╣реЛрдЧрд╛ *ред
рдЗрд╕рд▓рд┐рдП, рдЖрдкрдХреЛ рд╕рддреНрдпрд╛рдкрди рдХреЗ рддрд░реНрдХ, рд╡рд┐рд╡рд░рдг рдХреЗ рдЖрдЙрдЯрдкреБрдЯ рдФрд░ рдирд┐рд░реНрдгрдп рд▓реЗрдиреЗ рдХреЗ рдХрд╛рд░реНрдп рдХреЛ рдЕрд▓рдЧ рдХрд░рдиреЗ рдХреА рдЖрд╡рд╢реНрдпрдХрддрд╛ рд╣реИ:
- рдЕрд╕реНрд╡реАрдХрд╛рд░ - рдореБрдЦрд░,
- рдЕрдирджреЗрдЦрд╛ - рдЧреНрд░рд╣рдг рдХрд░рдирд╛
- рдЫрд╛рдирдиреЗ рдХреЗ рд╕рд╛рде-рд╕рд╛рде рд╕рд╣реА рд▓реЛрдЧреЛрдВ рдХреА рддрд▓рд╛рд╢ рдХрд░рдирд╛, рд╢рд┐рдлреНрдЯ рдХрд░рдирд╛, рдмрджрд▓рдирд╛ рдЖрджрд┐ред
рдпрд╣ рд╡рд╣ рдЬрдЧрд╣ рд╣реИ рдЬрд╣рд╛рдБ рдореИрдЪ рдЦреЗрд▓рдиреЗ рд╡рд╛рд▓реЗ рдЖрддреЗ рд╣реИрдВ - рдЫреЛрдЯреА-рдЫреЛрдЯреА рд╡рд╕реНрддреБрдПрдБ рдЬрд┐рдирдореЗрдВ рдирд┐рд░реНрдгрдп рд▓реЗрдиреЗ рдХрд╛ рддрд░реНрдХ рд╣реЛрддрд╛ рд╣реИ, рд╡реЗ рдЬрд╛рдирддреЗ рд╣реИрдВ рдХрд┐ рдЙрдиреНрд╣реЗрдВ рдХрд┐рд╕ рдЪреАрдЬрд╝ рдХрд╛ рдЗрдВрддрдЬрд╝рд╛рд░ рд╣реИ рдФрд░ рдЙрдиреНрд╣реЗрдВ рдХреНрдпрд╛ рдорд┐рд▓рд╛ рд╣реИ, рдЬреЛ рд╡реЗ рд╕реНрд╡рддрдВрддреНрд░ рд░реВрдк рд╕реЗ рд░рд┐рдкреЛрд░реНрдЯ рдХрд░рддреЗ рд╣реИрдВред рдореИрдЪрд░реНрд╕ рдХреА рдорджрдж рд╕реЗ рдкрд╣рд▓реЗ рддреАрди рдЪреЗрдХ рд▓рдЧрднрдЧ рдХрд╛рд░реНрд░рд╡рд╛рдИ рдХрд╛ рд╡рд░реНрдгрди рдХрд░рддреЗ рд╣реИрдВред рдФрд░ рдЬреЛ рдХреЛрдИ рдЬрд╛рдирдирд╛ рдЪрд╛рд╣рддрд╛ рд╣реИ рдХрд┐ рд╕реНрдХреНрд░рд┐рдкреНрдЯ рдХреНрдпрд╛ рдХрд░ рд░рд╣реА рд╣реИ рд╡рд╣ рдЗрд╕реЗ рдкрдврд╝ рд╕рдХрддрд╛ рд╣реИред
@Test public void orangeIsRoundWithMatcher() { assertThat(someFruit, is(round())); } @Test public void orangeIsSweetWithMatcher() { assertThat(someFruit, is(sweet())); } @Test public void orangeHasColorWithMatcher() { assertThat(someFruit, hasColor(Color.ORANGE)); }
рдРрд╕реА рд╕реБрдВрджрд░рддрд╛ рдХреЗ рд▓рд┐рдП, рдПрдХ рд╡рд┐рд╢реЗрд╖
рд╣реИрдорд░реЗрд╕реНрдЯ рдкреБрд╕реНрддрдХрд╛рд▓рдп рд╣реИред рдЗрд╕рдореЗрдВ рдХрд╛рд░реНрдпрд╛рдиреНрд╡рдпрди рдХреЗ рд▓рд┐рдП рдПрдХ рдЗрдВрдЯрд░рдлрд╝реЗрд╕ рд╣реЛрддрд╛ рд╣реИ, рдФрд░
рдПрд╕реЗрд░рдЯреИрдЯ рдФрд░
рдПрд╕реЗрдердЯреИрдЯ рдореЗрдердбреНрд╕ (рдЙрддреНрддрд░рд╛рд░реНрджреНрдз, рд╡рд╛рд╕реНрддрд╡ рдореЗрдВ, JUnit рдХреЗ рдЕрдВрджрд░ рд╣реЛрддрд╛ рд╣реИ, рд▓реЗрдХрд┐рди Hamcrest рд╕реЗ рдЗрдВрдЯрд░рдлрд╝реЗрд╕ рдХрд╛ рдЙрдкрдпреЛрдЧ рдХрд░рддрд╛ рд╣реИ)ред рд╡реЗ рдЧреЗрдорд░ рд╕реЗ рд╡рд╕реНрддреБ рдХреЗ рдмрд╛рд░реЗ рдореЗрдВ рдкреВрдЫрддреЗ рд╣реИрдВ, рдирд┐рд░реНрдгрдп рд▓реЗрддреЗ рд╣реИрдВред
рд╕рдВрд╕реНрдХрд░рдг 4.11 рдХреЗ рд╕рд╛рде рд╢реБрд░реВ, рдЬреНрдпреВрдирд┐рдЯ рдирд┐рд░реНрднрд░рддрд╛рдУрдВ рдореЗрдВ, рд╣реИрдорд░реЗрд╕реНрдЯ рд▓рд╛рдЗрдмреНрд░реЗрд░реА рдХрд╛ рд╕рдВрд╕реНрдХрд░рдг 1.3 рд╕реЗ рдХрдо рдирд╣реАрдВ рд╣реИред рд╡рд╣ рд╡рд╣ рдереА рдЬрд┐рд╕рдиреЗ рдЗрдВрдЯрд░рдлрд╝реЗрд╕ рдкреЗрд╢ рдХрд┐рдпрд╛ рдерд╛ рдЬрд┐рд╕рдореЗрдВ рдЖрдЧреЗ рд╡рд░реНрдгрд┐рдд рд╕рдм рдХреБрдЫ рд▓рд╛рдЧреВ рдХрд┐рдпрд╛ рдЧрдпрд╛ рд╣реИред рдЗрд╕рд▓рд┐рдП, рдорд╛рд╡реЗрди рдХрд╛ рдЙрдкрдпреЛрдЧ рдХрд░рддреЗ рд╣реБрдП, рдпрд╣ JUnit 4.11 рдХреЛ рдЬреЛрдбрд╝рдиреЗ рдХреЗ рд▓рд┐рдП рдкрд░реНрдпрд╛рдкреНрдд рд╣реИ, рдФрд░ рдЙрдкрдХрд░рдг рдХрд╛ рдиреНрдпреВрдирддрдо рдЖрд╡рд╢реНрдпрдХ рд╕реЗрдЯ рдЙрдкрдпреЛрдЧ рдХреЗ рд▓рд┐рдП рддреИрдпрд╛рд░ рд╣реИред рдФрд░ рд╣реИрдорд░реЗрд╕реНрдЯ рдбрд┐рд▓реАрд╡рд░реА рд╕реЗ рд╕рднреА рдЙрдкрд▓рдмреНрдз рдЦрд┐рд▓рд╛рдбрд╝рд┐рдпреЛрдВ рдХреЗ рдкреВрд░реНрдг рд╕реЗрдЯ рдХреЗ рд▓рд┐рдП, рдЖрдкрдХреЛ рд╣реИрдорд░реЗрд╕реНрдЯ-рд╕рднреА рдХрд▓рд╛рдХреГрддрд┐рдпреЛрдВ рдХреА рдЖрд╡рд╢реНрдпрдХрддрд╛ рд╣реЛрдЧреА, рдЬрд┐рдиреНрд╣реЗрдВ рдЕрд▓рдЧ рд╕реЗ рдЬреЛрдбрд╝рд╛ рдЬрд╛ рд╕рдХрддрд╛ рд╣реИред
рдпрд╣ рдЖрдкрдХреЗ рдкреЛрдо рдХреА рддрд░рд╣ рд▓рдЧ рд╕рдХрддрд╛ рд╣реИ ред
рдпрд╣ рдХреИрд╕реЗ рдХрд╛рдо рдХрд░рддрд╛ рд╣реИ?
рдкреБрд╕реНрддрдХрд╛рд▓рдп рдореЗрдВ рдПрдХ рдЕрдореВрд░реНрдд рд╡рд░реНрдЧ
TypeSafeMatcher, . :
public boolean matchesSafely(Fruit fruit) тАФ , public void describeTo(Description description)
тАФ , protected void describeMismatchSafely(Fruit item, Description mismatchDescription)
тАФ .
, , тАФ null
.
, , , :
public class ShapeMatcher extends TypeSafeMatcher<Fruit> { private Shape expected; public ShapeMatcher(Shape expected) { this.expected = expected; } @Override public boolean matchesSafely(Fruit fruit) { return expected.equals(fruit.getShape()); } @Override protected void describeMismatchSafely(Fruit item, Description mismatchDescription) { mismatchDescription.appendText("fruit has shape - ").appendValue(item.getShape()); } @Override public void describeTo(Description description) { description.appendText("shape - ").appendValue(expected); } @Factory public static ShapeMatcher round() { return new ShapeMatcher(Shape.ROUND); } }
. , , , , тАФ !
, , , , . тАФ . Java FeatureMatcher<WhatWeGet, WhatWeWannaCheck>
, : .
3 :
, WhatWeWannaCheck , ( ), ( - )
, f eatureValueOf
. Hamcrest .
, , .
public class Matchers { public static Matcher<Fruit> hasShape(final Shape shape) { return new FeatureMatcher<Fruit, Shape>(equalTo(shape), "fruit has shape - ", "shape -") { @Override protected Shape featureValueOf(Fruit fruit) { return fruit.getShape(); } }; } public static Matcher<Fruit> round() { return hasShape(Shape.ROUND); } public static Matcher<Fruit> sweet() { return new FeatureMatcher<Fruit, Boolean>(is(true), "fruit should be sweet", "sweet -") { @Override protected Boolean featureValueOf(Fruit fruit) { return fruit.isSweet(); } }; } public static Matcher<Fruit> hasColor(Color color) { return new FeatureMatcher<Fruit, Color>(equalTo(color), "fruit have color - ", "color -") { @Override protected String featureValueOf(Fruit fruit) { return fruit.getColor(); } }; } }
Feel the POWER OF MATCHERS
тАФ . Hamcrest : allOf, anyOf, both, either. , .
, ┬л┬╗ :
@Test public void orangeBothSweetRoundAndOrangeColorWithMatchers() throws Exception { assumeThat(someFruit, both(round()).and(sweet()).and(hasColor(Color.ORANGE))); // }
.
, , тАФ . , . тАФ :
@Test public void orangeBothSweetRoundAndOrangeColorWithMatchers() throws Exception { assertThat(someFruitList, everyItem(both(round()).and(sweet()).and(hasColor(Color.ORANGE)))); }
, : . тАФ , , hasItem()
.
.
, . , тАФ , - . , , тАФ , . , -. .
github.com/yandex-qatools/matchers-java .
TypeSafeMatcher, . :
public boolean matchesSafely(Fruit fruit)
тАФ , public void describeTo(Description description)
тАФ , protected void describeMismatchSafely(Fruit item, Description mismatchDescription)
тАФ .
, , тАФ null
.
, , , :
public class ShapeMatcher extends TypeSafeMatcher<Fruit> { private Shape expected; public ShapeMatcher(Shape expected) { this.expected = expected; } @Override public boolean matchesSafely(Fruit fruit) { return expected.equals(fruit.getShape()); } @Override protected void describeMismatchSafely(Fruit item, Description mismatchDescription) { mismatchDescription.appendText("fruit has shape - ").appendValue(item.getShape()); } @Override public void describeTo(Description description) { description.appendText("shape - ").appendValue(expected); } @Factory public static ShapeMatcher round() { return new ShapeMatcher(Shape.ROUND); } }
. , , , , тАФ !
, , , , . тАФ . Java FeatureMatcher<WhatWeGet, WhatWeWannaCheck>
, : .
3 :
, WhatWeWannaCheck , ( ), ( - )
, f eatureValueOf
. Hamcrest .
, , .
public class Matchers { public static Matcher<Fruit> hasShape(final Shape shape) { return new FeatureMatcher<Fruit, Shape>(equalTo(shape), "fruit has shape - ", "shape -") { @Override protected Shape featureValueOf(Fruit fruit) { return fruit.getShape(); } }; } public static Matcher<Fruit> round() { return hasShape(Shape.ROUND); } public static Matcher<Fruit> sweet() { return new FeatureMatcher<Fruit, Boolean>(is(true), "fruit should be sweet", "sweet -") { @Override protected Boolean featureValueOf(Fruit fruit) { return fruit.isSweet(); } }; } public static Matcher<Fruit> hasColor(Color color) { return new FeatureMatcher<Fruit, Color>(equalTo(color), "fruit have color - ", "color -") { @Override protected String featureValueOf(Fruit fruit) { return fruit.getColor(); } }; } }
Feel the POWER OF MATCHERS
тАФ . Hamcrest : allOf, anyOf, both, either. , .
, ┬л┬╗ :
@Test public void orangeBothSweetRoundAndOrangeColorWithMatchers() throws Exception { assumeThat(someFruit, both(round()).and(sweet()).and(hasColor(Color.ORANGE))); // }
.
, , тАФ . , . тАФ :
@Test public void orangeBothSweetRoundAndOrangeColorWithMatchers() throws Exception { assertThat(someFruitList, everyItem(both(round()).and(sweet()).and(hasColor(Color.ORANGE)))); }
, : . тАФ , , hasItem()
.
.
, . , тАФ , - . , , тАФ , . , -. .
github.com/yandex-qatools/matchers-java .
TypeSafeMatcher, . :
public boolean matchesSafely(Fruit fruit)
тАФ , public void describeTo(Description description)
тАФ , protected void describeMismatchSafely(Fruit item, Description mismatchDescription)
тАФ .
, , тАФ null
.
, , , :
public class ShapeMatcher extends TypeSafeMatcher<Fruit> { private Shape expected; public ShapeMatcher(Shape expected) { this.expected = expected; } @Override public boolean matchesSafely(Fruit fruit) { return expected.equals(fruit.getShape()); } @Override protected void describeMismatchSafely(Fruit item, Description mismatchDescription) { mismatchDescription.appendText("fruit has shape - ").appendValue(item.getShape()); } @Override public void describeTo(Description description) { description.appendText("shape - ").appendValue(expected); } @Factory public static ShapeMatcher round() { return new ShapeMatcher(Shape.ROUND); } }
. , , , , тАФ !
, , , , . тАФ . Java FeatureMatcher<WhatWeGet, WhatWeWannaCheck>
, : .
3 :
, WhatWeWannaCheck , ( ), ( - )
, f eatureValueOf
. Hamcrest .
, , .
public class Matchers { public static Matcher<Fruit> hasShape(final Shape shape) { return new FeatureMatcher<Fruit, Shape>(equalTo(shape), "fruit has shape - ", "shape -") { @Override protected Shape featureValueOf(Fruit fruit) { return fruit.getShape(); } }; } public static Matcher<Fruit> round() { return hasShape(Shape.ROUND); } public static Matcher<Fruit> sweet() { return new FeatureMatcher<Fruit, Boolean>(is(true), "fruit should be sweet", "sweet -") { @Override protected Boolean featureValueOf(Fruit fruit) { return fruit.isSweet(); } }; } public static Matcher<Fruit> hasColor(Color color) { return new FeatureMatcher<Fruit, Color>(equalTo(color), "fruit have color - ", "color -") { @Override protected String featureValueOf(Fruit fruit) { return fruit.getColor(); } }; } }
Feel the POWER OF MATCHERS
тАФ . Hamcrest : allOf, anyOf, both, either. , .
, ┬л┬╗ :
@Test public void orangeBothSweetRoundAndOrangeColorWithMatchers() throws Exception { assumeThat(someFruit, both(round()).and(sweet()).and(hasColor(Color.ORANGE))); // }
.
, , тАФ . , . тАФ :
@Test public void orangeBothSweetRoundAndOrangeColorWithMatchers() throws Exception { assertThat(someFruitList, everyItem(both(round()).and(sweet()).and(hasColor(Color.ORANGE)))); }
, : . тАФ , , hasItem()
.
.
, . , тАФ , - . , , тАФ , . , -. .
github.com/yandex-qatools/matchers-java .
TypeSafeMatcher, . :
public boolean matchesSafely(Fruit fruit)
тАФ , public void describeTo(Description description)
тАФ , protected void describeMismatchSafely(Fruit item, Description mismatchDescription)
тАФ .
, , тАФ null
.
, , , :
public class ShapeMatcher extends TypeSafeMatcher<Fruit> { private Shape expected; public ShapeMatcher(Shape expected) { this.expected = expected; } @Override public boolean matchesSafely(Fruit fruit) { return expected.equals(fruit.getShape()); } @Override protected void describeMismatchSafely(Fruit item, Description mismatchDescription) { mismatchDescription.appendText("fruit has shape - ").appendValue(item.getShape()); } @Override public void describeTo(Description description) { description.appendText("shape - ").appendValue(expected); } @Factory public static ShapeMatcher round() { return new ShapeMatcher(Shape.ROUND); } }
. , , , , тАФ !
, , , , . тАФ . Java FeatureMatcher<WhatWeGet, WhatWeWannaCheck>
, : .
3 :
, WhatWeWannaCheck , ( ), ( - )
, f eatureValueOf
. Hamcrest .
, , .
public class Matchers { public static Matcher<Fruit> hasShape(final Shape shape) { return new FeatureMatcher<Fruit, Shape>(equalTo(shape), "fruit has shape - ", "shape -") { @Override protected Shape featureValueOf(Fruit fruit) { return fruit.getShape(); } }; } public static Matcher<Fruit> round() { return hasShape(Shape.ROUND); } public static Matcher<Fruit> sweet() { return new FeatureMatcher<Fruit, Boolean>(is(true), "fruit should be sweet", "sweet -") { @Override protected Boolean featureValueOf(Fruit fruit) { return fruit.isSweet(); } }; } public static Matcher<Fruit> hasColor(Color color) { return new FeatureMatcher<Fruit, Color>(equalTo(color), "fruit have color - ", "color -") { @Override protected String featureValueOf(Fruit fruit) { return fruit.getColor(); } }; } }
Feel the POWER OF MATCHERS
тАФ . Hamcrest : allOf, anyOf, both, either. , .
, ┬л┬╗ :
@Test public void orangeBothSweetRoundAndOrangeColorWithMatchers() throws Exception { assumeThat(someFruit, both(round()).and(sweet()).and(hasColor(Color.ORANGE))); // }
.
, , тАФ . , . тАФ :
@Test public void orangeBothSweetRoundAndOrangeColorWithMatchers() throws Exception { assertThat(someFruitList, everyItem(both(round()).and(sweet()).and(hasColor(Color.ORANGE)))); }
, : . тАФ , , hasItem()
.
.
, . , тАФ , - . , , тАФ , . , -. .
github.com/yandex-qatools/matchers-java .
TypeSafeMatcher, . :
public boolean matchesSafely(Fruit fruit)
тАФ , public void describeTo(Description description)
тАФ , protected void describeMismatchSafely(Fruit item, Description mismatchDescription)
тАФ .
, , тАФ null
.
, , , :
public class ShapeMatcher extends TypeSafeMatcher<Fruit> { private Shape expected; public ShapeMatcher(Shape expected) { this.expected = expected; } @Override public boolean matchesSafely(Fruit fruit) { return expected.equals(fruit.getShape()); } @Override protected void describeMismatchSafely(Fruit item, Description mismatchDescription) { mismatchDescription.appendText("fruit has shape - ").appendValue(item.getShape()); } @Override public void describeTo(Description description) { description.appendText("shape - ").appendValue(expected); } @Factory public static ShapeMatcher round() { return new ShapeMatcher(Shape.ROUND); } }
. , , , , тАФ !
, , , , . тАФ . Java FeatureMatcher<WhatWeGet, WhatWeWannaCheck>
, : .
3 :
, WhatWeWannaCheck , ( ), ( - )
, f eatureValueOf
. Hamcrest .
, , .
public class Matchers { public static Matcher<Fruit> hasShape(final Shape shape) { return new FeatureMatcher<Fruit, Shape>(equalTo(shape), "fruit has shape - ", "shape -") { @Override protected Shape featureValueOf(Fruit fruit) { return fruit.getShape(); } }; } public static Matcher<Fruit> round() { return hasShape(Shape.ROUND); } public static Matcher<Fruit> sweet() { return new FeatureMatcher<Fruit, Boolean>(is(true), "fruit should be sweet", "sweet -") { @Override protected Boolean featureValueOf(Fruit fruit) { return fruit.isSweet(); } }; } public static Matcher<Fruit> hasColor(Color color) { return new FeatureMatcher<Fruit, Color>(equalTo(color), "fruit have color - ", "color -") { @Override protected String featureValueOf(Fruit fruit) { return fruit.getColor(); } }; } }
Feel the POWER OF MATCHERS
тАФ . Hamcrest : allOf, anyOf, both, either. , .
, ┬л┬╗ :
@Test public void orangeBothSweetRoundAndOrangeColorWithMatchers() throws Exception { assumeThat(someFruit, both(round()).and(sweet()).and(hasColor(Color.ORANGE))); // }
.
, , тАФ . , . тАФ :
@Test public void orangeBothSweetRoundAndOrangeColorWithMatchers() throws Exception { assertThat(someFruitList, everyItem(both(round()).and(sweet()).and(hasColor(Color.ORANGE)))); }
, : . тАФ , , hasItem()
.
.
, . , тАФ , - . , , тАФ , . , -. .
github.com/yandex-qatools/matchers-java .
TypeSafeMatcher, . :
public boolean matchesSafely(Fruit fruit)
тАФ , public void describeTo(Description description)
тАФ , protected void describeMismatchSafely(Fruit item, Description mismatchDescription)
тАФ .
, , тАФ null
.
, , , :
public class ShapeMatcher extends TypeSafeMatcher<Fruit> { private Shape expected; public ShapeMatcher(Shape expected) { this.expected = expected; } @Override public boolean matchesSafely(Fruit fruit) { return expected.equals(fruit.getShape()); } @Override protected void describeMismatchSafely(Fruit item, Description mismatchDescription) { mismatchDescription.appendText("fruit has shape - ").appendValue(item.getShape()); } @Override public void describeTo(Description description) { description.appendText("shape - ").appendValue(expected); } @Factory public static ShapeMatcher round() { return new ShapeMatcher(Shape.ROUND); } }
. , , , , тАФ !
, , , , . тАФ . Java FeatureMatcher<WhatWeGet, WhatWeWannaCheck>
, : .
3 :
, WhatWeWannaCheck , ( ), ( - )
, f eatureValueOf
. Hamcrest .
, , .
public class Matchers { public static Matcher<Fruit> hasShape(final Shape shape) { return new FeatureMatcher<Fruit, Shape>(equalTo(shape), "fruit has shape - ", "shape -") { @Override protected Shape featureValueOf(Fruit fruit) { return fruit.getShape(); } }; } public static Matcher<Fruit> round() { return hasShape(Shape.ROUND); } public static Matcher<Fruit> sweet() { return new FeatureMatcher<Fruit, Boolean>(is(true), "fruit should be sweet", "sweet -") { @Override protected Boolean featureValueOf(Fruit fruit) { return fruit.isSweet(); } }; } public static Matcher<Fruit> hasColor(Color color) { return new FeatureMatcher<Fruit, Color>(equalTo(color), "fruit have color - ", "color -") { @Override protected String featureValueOf(Fruit fruit) { return fruit.getColor(); } }; } }
Feel the POWER OF MATCHERS
тАФ . Hamcrest : allOf, anyOf, both, either. , .
, ┬л┬╗ :
@Test public void orangeBothSweetRoundAndOrangeColorWithMatchers() throws Exception { assumeThat(someFruit, both(round()).and(sweet()).and(hasColor(Color.ORANGE))); // }
.
, , тАФ . , . тАФ :
@Test public void orangeBothSweetRoundAndOrangeColorWithMatchers() throws Exception { assertThat(someFruitList, everyItem(both(round()).and(sweet()).and(hasColor(Color.ORANGE)))); }
, : . тАФ , , hasItem()
.
.
, . , тАФ , - . , , тАФ , . , -. .
github.com/yandex-qatools/matchers-java .
TypeSafeMatcher, . :
public boolean matchesSafely(Fruit fruit)
тАФ , public void describeTo(Description description)
тАФ , protected void describeMismatchSafely(Fruit item, Description mismatchDescription)
тАФ .
, , тАФ null
.
, , , :
public class ShapeMatcher extends TypeSafeMatcher<Fruit> { private Shape expected; public ShapeMatcher(Shape expected) { this.expected = expected; } @Override public boolean matchesSafely(Fruit fruit) { return expected.equals(fruit.getShape()); } @Override protected void describeMismatchSafely(Fruit item, Description mismatchDescription) { mismatchDescription.appendText("fruit has shape - ").appendValue(item.getShape()); } @Override public void describeTo(Description description) { description.appendText("shape - ").appendValue(expected); } @Factory public static ShapeMatcher round() { return new ShapeMatcher(Shape.ROUND); } }
. , , , , тАФ !
, , , , . тАФ . Java FeatureMatcher<WhatWeGet, WhatWeWannaCheck>
, : .
3 :
, WhatWeWannaCheck , ( ), ( - )
, f eatureValueOf
. Hamcrest .
, , .
public class Matchers { public static Matcher<Fruit> hasShape(final Shape shape) { return new FeatureMatcher<Fruit, Shape>(equalTo(shape), "fruit has shape - ", "shape -") { @Override protected Shape featureValueOf(Fruit fruit) { return fruit.getShape(); } }; } public static Matcher<Fruit> round() { return hasShape(Shape.ROUND); } public static Matcher<Fruit> sweet() { return new FeatureMatcher<Fruit, Boolean>(is(true), "fruit should be sweet", "sweet -") { @Override protected Boolean featureValueOf(Fruit fruit) { return fruit.isSweet(); } }; } public static Matcher<Fruit> hasColor(Color color) { return new FeatureMatcher<Fruit, Color>(equalTo(color), "fruit have color - ", "color -") { @Override protected String featureValueOf(Fruit fruit) { return fruit.getColor(); } }; } }
Feel the POWER OF MATCHERS
тАФ . Hamcrest : allOf, anyOf, both, either. , .
, ┬л┬╗ :
@Test public void orangeBothSweetRoundAndOrangeColorWithMatchers() throws Exception { assumeThat(someFruit, both(round()).and(sweet()).and(hasColor(Color.ORANGE)));
TypeSafeMatcher, . :
public boolean matchesSafely(Fruit fruit)
тАФ , public void describeTo(Description description)
тАФ , protected void describeMismatchSafely(Fruit item, Description mismatchDescription)
тАФ .
, , тАФ null
.
, , , :
public class ShapeMatcher extends TypeSafeMatcher<Fruit> { private Shape expected; public ShapeMatcher(Shape expected) { this.expected = expected; } @Override public boolean matchesSafely(Fruit fruit) { return expected.equals(fruit.getShape()); } @Override protected void describeMismatchSafely(Fruit item, Description mismatchDescription) { mismatchDescription.appendText("fruit has shape - ").appendValue(item.getShape()); } @Override public void describeTo(Description description) { description.appendText("shape - ").appendValue(expected); } @Factory public static ShapeMatcher round() { return new ShapeMatcher(Shape.ROUND); } }
. , , , , тАФ !
, , , , . тАФ . Java FeatureMatcher<WhatWeGet, WhatWeWannaCheck>
, : .
3 :
, WhatWeWannaCheck , ( ), ( - )
, f eatureValueOf
. Hamcrest .
, , .
public class Matchers { public static Matcher<Fruit> hasShape(final Shape shape) { return new FeatureMatcher<Fruit, Shape>(equalTo(shape), "fruit has shape - ", "shape -") { @Override protected Shape featureValueOf(Fruit fruit) { return fruit.getShape(); } }; } public static Matcher<Fruit> round() { return hasShape(Shape.ROUND); } public static Matcher<Fruit> sweet() { return new FeatureMatcher<Fruit, Boolean>(is(true), "fruit should be sweet", "sweet -") { @Override protected Boolean featureValueOf(Fruit fruit) { return fruit.isSweet(); } }; } public static Matcher<Fruit> hasColor(Color color) { return new FeatureMatcher<Fruit, Color>(equalTo(color), "fruit have color - ", "color -") { @Override protected String featureValueOf(Fruit fruit) { return fruit.getColor(); } }; } }
Feel the POWER OF MATCHERS
тАФ . Hamcrest : allOf, anyOf, both, either. , .
, ┬л┬╗ :
@Test public void orangeBothSweetRoundAndOrangeColorWithMatchers() throws Exception { assumeThat(someFruit, both(round()).and(sweet()).and(hasColor(Color.ORANGE))); // }
.
, , тАФ . , . тАФ :
@Test public void orangeBothSweetRoundAndOrangeColorWithMatchers() throws Exception { assertThat(someFruitList, everyItem(both(round()).and(sweet()).and(hasColor(Color.ORANGE)))); }
, : . тАФ , , hasItem()
.
.
, . , тАФ , - . , , тАФ , . , -. .
github.com/yandex-qatools/matchers-java .
TypeSafeMatcher, . :
public boolean matchesSafely(Fruit fruit)
тАФ , public void describeTo(Description description)
тАФ , protected void describeMismatchSafely(Fruit item, Description mismatchDescription)
тАФ .
, , тАФ null
.
, , , :
public class ShapeMatcher extends TypeSafeMatcher<Fruit> { private Shape expected; public ShapeMatcher(Shape expected) { this.expected = expected; } @Override public boolean matchesSafely(Fruit fruit) { return expected.equals(fruit.getShape()); } @Override protected void describeMismatchSafely(Fruit item, Description mismatchDescription) { mismatchDescription.appendText("fruit has shape - ").appendValue(item.getShape()); } @Override public void describeTo(Description description) { description.appendText("shape - ").appendValue(expected); } @Factory public static ShapeMatcher round() { return new ShapeMatcher(Shape.ROUND); } }
. , , , , тАФ !
, , , , . тАФ . Java FeatureMatcher<WhatWeGet, WhatWeWannaCheck>
, : .
3 :
, WhatWeWannaCheck , ( ), ( - )
, f eatureValueOf
. Hamcrest .
, , .
public class Matchers { public static Matcher<Fruit> hasShape(final Shape shape) { return new FeatureMatcher<Fruit, Shape>(equalTo(shape), "fruit has shape - ", "shape -") { @Override protected Shape featureValueOf(Fruit fruit) { return fruit.getShape(); } }; } public static Matcher<Fruit> round() { return hasShape(Shape.ROUND); } public static Matcher<Fruit> sweet() { return new FeatureMatcher<Fruit, Boolean>(is(true), "fruit should be sweet", "sweet -") { @Override protected Boolean featureValueOf(Fruit fruit) { return fruit.isSweet(); } }; } public static Matcher<Fruit> hasColor(Color color) { return new FeatureMatcher<Fruit, Color>(equalTo(color), "fruit have color - ", "color -") { @Override protected String featureValueOf(Fruit fruit) { return fruit.getColor(); } }; } }
Feel the POWER OF MATCHERS
тАФ . Hamcrest : allOf, anyOf, both, either. , .
, ┬л┬╗ :
@Test public void orangeBothSweetRoundAndOrangeColorWithMatchers() throws Exception { assumeThat(someFruit, both(round()).and(sweet()).and(hasColor(Color.ORANGE))); // }
.
, , тАФ . , . тАФ :
@Test public void orangeBothSweetRoundAndOrangeColorWithMatchers() throws Exception { assertThat(someFruitList, everyItem(both(round()).and(sweet()).and(hasColor(Color.ORANGE)))); }
, : . тАФ , , hasItem()
.
.
, . , тАФ , - . , , тАФ , . , -. .
github.com/yandex-qatools/matchers-java .
TypeSafeMatcher, . :
public boolean matchesSafely(Fruit fruit)
тАФ , public void describeTo(Description description)
тАФ , protected void describeMismatchSafely(Fruit item, Description mismatchDescription)
тАФ .
, , тАФ null
.
, , , :
public class ShapeMatcher extends TypeSafeMatcher<Fruit> { private Shape expected; public ShapeMatcher(Shape expected) { this.expected = expected; } @Override public boolean matchesSafely(Fruit fruit) { return expected.equals(fruit.getShape()); } @Override protected void describeMismatchSafely(Fruit item, Description mismatchDescription) { mismatchDescription.appendText("fruit has shape - ").appendValue(item.getShape()); } @Override public void describeTo(Description description) { description.appendText("shape - ").appendValue(expected); } @Factory public static ShapeMatcher round() { return new ShapeMatcher(Shape.ROUND); } }
. , , , , тАФ !
, , , , . тАФ . Java FeatureMatcher<WhatWeGet, WhatWeWannaCheck>
, : .
3 :
, WhatWeWannaCheck , ( ), ( - )
, f eatureValueOf
. Hamcrest .
, , .
public class Matchers { public static Matcher<Fruit> hasShape(final Shape shape) { return new FeatureMatcher<Fruit, Shape>(equalTo(shape), "fruit has shape - ", "shape -") { @Override protected Shape featureValueOf(Fruit fruit) { return fruit.getShape(); } }; } public static Matcher<Fruit> round() { return hasShape(Shape.ROUND); } public static Matcher<Fruit> sweet() { return new FeatureMatcher<Fruit, Boolean>(is(true), "fruit should be sweet", "sweet -") { @Override protected Boolean featureValueOf(Fruit fruit) { return fruit.isSweet(); } }; } public static Matcher<Fruit> hasColor(Color color) { return new FeatureMatcher<Fruit, Color>(equalTo(color), "fruit have color - ", "color -") { @Override protected String featureValueOf(Fruit fruit) { return fruit.getColor(); } }; } }
Feel the POWER OF MATCHERS
тАФ . Hamcrest : allOf, anyOf, both, either. , .
, ┬л┬╗ :
@Test public void orangeBothSweetRoundAndOrangeColorWithMatchers() throws Exception { assumeThat(someFruit, both(round()).and(sweet()).and(hasColor(Color.ORANGE))); // }
.
, , тАФ . , . тАФ :
@Test public void orangeBothSweetRoundAndOrangeColorWithMatchers() throws Exception { assertThat(someFruitList, everyItem(both(round()).and(sweet()).and(hasColor(Color.ORANGE)))); }
, : . тАФ , , hasItem()
.
.
, . , тАФ , - . , , тАФ , . , -. .
github.com/yandex-qatools/matchers-java .
TypeSafeMatcher, . :
public boolean matchesSafely(Fruit fruit)
тАФ , public void describeTo(Description description)
тАФ , protected void describeMismatchSafely(Fruit item, Description mismatchDescription)
тАФ .
, , тАФ null
.
, , , :
public class ShapeMatcher extends TypeSafeMatcher<Fruit> { private Shape expected; public ShapeMatcher(Shape expected) { this.expected = expected; } @Override public boolean matchesSafely(Fruit fruit) { return expected.equals(fruit.getShape()); } @Override protected void describeMismatchSafely(Fruit item, Description mismatchDescription) { mismatchDescription.appendText("fruit has shape - ").appendValue(item.getShape()); } @Override public void describeTo(Description description) { description.appendText("shape - ").appendValue(expected); } @Factory public static ShapeMatcher round() { return new ShapeMatcher(Shape.ROUND); } }
. , , , , тАФ !
, , , , . тАФ . Java FeatureMatcher<WhatWeGet, WhatWeWannaCheck>
, : .
3 :
, WhatWeWannaCheck , ( ), ( - )
, f eatureValueOf
. Hamcrest .
, , .
public class Matchers { public static Matcher<Fruit> hasShape(final Shape shape) { return new FeatureMatcher<Fruit, Shape>(equalTo(shape), "fruit has shape - ", "shape -") { @Override protected Shape featureValueOf(Fruit fruit) { return fruit.getShape(); } }; } public static Matcher<Fruit> round() { return hasShape(Shape.ROUND); } public static Matcher<Fruit> sweet() { return new FeatureMatcher<Fruit, Boolean>(is(true), "fruit should be sweet", "sweet -") { @Override protected Boolean featureValueOf(Fruit fruit) { return fruit.isSweet(); } }; } public static Matcher<Fruit> hasColor(Color color) { return new FeatureMatcher<Fruit, Color>(equalTo(color), "fruit have color - ", "color -") { @Override protected String featureValueOf(Fruit fruit) { return fruit.getColor(); } }; } }
Feel the POWER OF MATCHERS
тАФ . Hamcrest : allOf, anyOf, both, either. , .
, ┬л┬╗ :
@Test public void orangeBothSweetRoundAndOrangeColorWithMatchers() throws Exception { assumeThat(someFruit, both(round()).and(sweet()).and(hasColor(Color.ORANGE))); // }
.
, , тАФ . , . тАФ :
@Test public void orangeBothSweetRoundAndOrangeColorWithMatchers() throws Exception { assertThat(someFruitList, everyItem(both(round()).and(sweet()).and(hasColor(Color.ORANGE)))); }
, : . тАФ , , hasItem()
.
.
, . , тАФ , - . , , тАФ , . , -. .
github.com/yandex-qatools/matchers-java .
TypeSafeMatcher, . :
public boolean matchesSafely(Fruit fruit)
тАФ , public void describeTo(Description description)
тАФ , protected void describeMismatchSafely(Fruit item, Description mismatchDescription)
тАФ .
, , тАФ null
.
, , , :
public class ShapeMatcher extends TypeSafeMatcher<Fruit> { private Shape expected; public ShapeMatcher(Shape expected) { this.expected = expected; } @Override public boolean matchesSafely(Fruit fruit) { return expected.equals(fruit.getShape()); } @Override protected void describeMismatchSafely(Fruit item, Description mismatchDescription) { mismatchDescription.appendText("fruit has shape - ").appendValue(item.getShape()); } @Override public void describeTo(Description description) { description.appendText("shape - ").appendValue(expected); } @Factory public static ShapeMatcher round() { return new ShapeMatcher(Shape.ROUND); } }
. , , , , тАФ !
, , , , . тАФ . Java FeatureMatcher<WhatWeGet, WhatWeWannaCheck>
, : .
3 :
, WhatWeWannaCheck , ( ), ( - )
, f eatureValueOf
. Hamcrest .
, , .
public class Matchers { public static Matcher<Fruit> hasShape(final Shape shape) { return new FeatureMatcher<Fruit, Shape>(equalTo(shape), "fruit has shape - ", "shape -") { @Override protected Shape featureValueOf(Fruit fruit) { return fruit.getShape(); } }; } public static Matcher<Fruit> round() { return hasShape(Shape.ROUND); } public static Matcher<Fruit> sweet() { return new FeatureMatcher<Fruit, Boolean>(is(true), "fruit should be sweet", "sweet -") { @Override protected Boolean featureValueOf(Fruit fruit) { return fruit.isSweet(); } }; } public static Matcher<Fruit> hasColor(Color color) { return new FeatureMatcher<Fruit, Color>(equalTo(color), "fruit have color - ", "color -") { @Override protected String featureValueOf(Fruit fruit) { return fruit.getColor(); } }; } }
Feel the POWER OF MATCHERS
тАФ . Hamcrest : allOf, anyOf, both, either. , .
, ┬л┬╗ :
@Test public void orangeBothSweetRoundAndOrangeColorWithMatchers() throws Exception { assumeThat(someFruit, both(round()).and(sweet()).and(hasColor(Color.ORANGE))); // }
.
, , тАФ . , . тАФ :
@Test public void orangeBothSweetRoundAndOrangeColorWithMatchers() throws Exception { assertThat(someFruitList, everyItem(both(round()).and(sweet()).and(hasColor(Color.ORANGE)))); }
, : . тАФ , , hasItem()
.
.
, . , тАФ , - . , , тАФ , . , -. .
github.com/yandex-qatools/matchers-java .
TypeSafeMatcher, . :
public boolean matchesSafely(Fruit fruit)
тАФ , public void describeTo(Description description)
тАФ , protected void describeMismatchSafely(Fruit item, Description mismatchDescription)
тАФ .
, , тАФ null
.
, , , :
public class ShapeMatcher extends TypeSafeMatcher<Fruit> { private Shape expected; public ShapeMatcher(Shape expected) { this.expected = expected; } @Override public boolean matchesSafely(Fruit fruit) { return expected.equals(fruit.getShape()); } @Override protected void describeMismatchSafely(Fruit item, Description mismatchDescription) { mismatchDescription.appendText("fruit has shape - ").appendValue(item.getShape()); } @Override public void describeTo(Description description) { description.appendText("shape - ").appendValue(expected); } @Factory public static ShapeMatcher round() { return new ShapeMatcher(Shape.ROUND); } }
. , , , , тАФ !
, , , , . тАФ . Java FeatureMatcher<WhatWeGet, WhatWeWannaCheck>
, : .
3 :
, WhatWeWannaCheck , ( ), ( - )
, f eatureValueOf
. Hamcrest .
, , .
public class Matchers { public static Matcher<Fruit> hasShape(final Shape shape) { return new FeatureMatcher<Fruit, Shape>(equalTo(shape), "fruit has shape - ", "shape -") { @Override protected Shape featureValueOf(Fruit fruit) { return fruit.getShape(); } }; } public static Matcher<Fruit> round() { return hasShape(Shape.ROUND); } public static Matcher<Fruit> sweet() { return new FeatureMatcher<Fruit, Boolean>(is(true), "fruit should be sweet", "sweet -") { @Override protected Boolean featureValueOf(Fruit fruit) { return fruit.isSweet(); } }; } public static Matcher<Fruit> hasColor(Color color) { return new FeatureMatcher<Fruit, Color>(equalTo(color), "fruit have color - ", "color -") { @Override protected String featureValueOf(Fruit fruit) { return fruit.getColor(); } }; } }
Feel the POWER OF MATCHERS
тАФ . Hamcrest : allOf, anyOf, both, either. , .
, ┬л┬╗ :
@Test public void orangeBothSweetRoundAndOrangeColorWithMatchers() throws Exception { assumeThat(someFruit, both(round()).and(sweet()).and(hasColor(Color.ORANGE))); // }
.
, , тАФ . , . тАФ :
@Test public void orangeBothSweetRoundAndOrangeColorWithMatchers() throws Exception { assertThat(someFruitList, everyItem(both(round()).and(sweet()).and(hasColor(Color.ORANGE)))); }
, : . тАФ , , hasItem()
.
.
, . , тАФ , - . , , тАФ , . , -. .
github.com/yandex-qatools/matchers-java .
TypeSafeMatcher, . :
public boolean matchesSafely(Fruit fruit)
тАФ , public void describeTo(Description description)
тАФ , protected void describeMismatchSafely(Fruit item, Description mismatchDescription)
тАФ .
, , тАФ null
.
, , , :
public class ShapeMatcher extends TypeSafeMatcher<Fruit> { private Shape expected; public ShapeMatcher(Shape expected) { this.expected = expected; } @Override public boolean matchesSafely(Fruit fruit) { return expected.equals(fruit.getShape()); } @Override protected void describeMismatchSafely(Fruit item, Description mismatchDescription) { mismatchDescription.appendText("fruit has shape - ").appendValue(item.getShape()); } @Override public void describeTo(Description description) { description.appendText("shape - ").appendValue(expected); } @Factory public static ShapeMatcher round() { return new ShapeMatcher(Shape.ROUND); } }
. , , , , тАФ !
, , , , . тАФ . Java FeatureMatcher<WhatWeGet, WhatWeWannaCheck>
, : .
3 :
, WhatWeWannaCheck , ( ), ( - )
, f eatureValueOf
. Hamcrest .
, , .
public class Matchers { public static Matcher<Fruit> hasShape(final Shape shape) { return new FeatureMatcher<Fruit, Shape>(equalTo(shape), "fruit has shape - ", "shape -") { @Override protected Shape featureValueOf(Fruit fruit) { return fruit.getShape(); } }; } public static Matcher<Fruit> round() { return hasShape(Shape.ROUND); } public static Matcher<Fruit> sweet() { return new FeatureMatcher<Fruit, Boolean>(is(true), "fruit should be sweet", "sweet -") { @Override protected Boolean featureValueOf(Fruit fruit) { return fruit.isSweet(); } }; } public static Matcher<Fruit> hasColor(Color color) { return new FeatureMatcher<Fruit, Color>(equalTo(color), "fruit have color - ", "color -") { @Override protected String featureValueOf(Fruit fruit) { return fruit.getColor(); } }; } }
Feel the POWER OF MATCHERS
тАФ . Hamcrest : allOf, anyOf, both, either. , .
, ┬л┬╗ :
@Test public void orangeBothSweetRoundAndOrangeColorWithMatchers() throws Exception { assumeThat(someFruit, both(round()).and(sweet()).and(hasColor(Color.ORANGE))); // }
.
, , тАФ . , . тАФ :
@Test public void orangeBothSweetRoundAndOrangeColorWithMatchers() throws Exception { assertThat(someFruitList, everyItem(both(round()).and(sweet()).and(hasColor(Color.ORANGE)))); }
, : . тАФ , , hasItem()
.
.
, . , тАФ , - . , , тАФ , . , -. .
github.com/yandex-qatools/matchers-java .
TypeSafeMatcher, . :
public boolean matchesSafely(Fruit fruit)
тАФ , public void describeTo(Description description)
тАФ , protected void describeMismatchSafely(Fruit item, Description mismatchDescription)
тАФ .
, , тАФ null
.
, , , :
public class ShapeMatcher extends TypeSafeMatcher<Fruit> { private Shape expected; public ShapeMatcher(Shape expected) { this.expected = expected; } @Override public boolean matchesSafely(Fruit fruit) { return expected.equals(fruit.getShape()); } @Override protected void describeMismatchSafely(Fruit item, Description mismatchDescription) { mismatchDescription.appendText("fruit has shape - ").appendValue(item.getShape()); } @Override public void describeTo(Description description) { description.appendText("shape - ").appendValue(expected); } @Factory public static ShapeMatcher round() { return new ShapeMatcher(Shape.ROUND); } }
. , , , , тАФ !
, , , , . тАФ . Java FeatureMatcher<WhatWeGet, WhatWeWannaCheck>
, : .
3 :
, WhatWeWannaCheck , ( ), ( - )
, f eatureValueOf
. Hamcrest .
, , .
public class Matchers { public static Matcher<Fruit> hasShape(final Shape shape) { return new FeatureMatcher<Fruit, Shape>(equalTo(shape), "fruit has shape - ", "shape -") { @Override protected Shape featureValueOf(Fruit fruit) { return fruit.getShape(); } }; } public static Matcher<Fruit> round() { return hasShape(Shape.ROUND); } public static Matcher<Fruit> sweet() { return new FeatureMatcher<Fruit, Boolean>(is(true), "fruit should be sweet", "sweet -") { @Override protected Boolean featureValueOf(Fruit fruit) { return fruit.isSweet(); } }; } public static Matcher<Fruit> hasColor(Color color) { return new FeatureMatcher<Fruit, Color>(equalTo(color), "fruit have color - ", "color -") { @Override protected String featureValueOf(Fruit fruit) { return fruit.getColor(); } }; } }
Feel the POWER OF MATCHERS
тАФ . Hamcrest : allOf, anyOf, both, either. , .
, ┬л┬╗ :
@Test public void orangeBothSweetRoundAndOrangeColorWithMatchers() throws Exception { assumeThat(someFruit, both(round()).and(sweet()).and(hasColor(Color.ORANGE)));
TypeSafeMatcher, . :
public boolean matchesSafely(Fruit fruit)
тАФ , public void describeTo(Description description)
тАФ , protected void describeMismatchSafely(Fruit item, Description mismatchDescription)
тАФ .
, , тАФ null
.
, , , :
public class ShapeMatcher extends TypeSafeMatcher<Fruit> { private Shape expected; public ShapeMatcher(Shape expected) { this.expected = expected; } @Override public boolean matchesSafely(Fruit fruit) { return expected.equals(fruit.getShape()); } @Override protected void describeMismatchSafely(Fruit item, Description mismatchDescription) { mismatchDescription.appendText("fruit has shape - ").appendValue(item.getShape()); } @Override public void describeTo(Description description) { description.appendText("shape - ").appendValue(expected); } @Factory public static ShapeMatcher round() { return new ShapeMatcher(Shape.ROUND); } }
. , , , , тАФ !
, , , , . тАФ . Java FeatureMatcher<WhatWeGet, WhatWeWannaCheck>
, : .
3 :
, WhatWeWannaCheck , ( ), ( - )
, f eatureValueOf
. Hamcrest .
, , .
public class Matchers { public static Matcher<Fruit> hasShape(final Shape shape) { return new FeatureMatcher<Fruit, Shape>(equalTo(shape), "fruit has shape - ", "shape -") { @Override protected Shape featureValueOf(Fruit fruit) { return fruit.getShape(); } }; } public static Matcher<Fruit> round() { return hasShape(Shape.ROUND); } public static Matcher<Fruit> sweet() { return new FeatureMatcher<Fruit, Boolean>(is(true), "fruit should be sweet", "sweet -") { @Override protected Boolean featureValueOf(Fruit fruit) { return fruit.isSweet(); } }; } public static Matcher<Fruit> hasColor(Color color) { return new FeatureMatcher<Fruit, Color>(equalTo(color), "fruit have color - ", "color -") { @Override protected String featureValueOf(Fruit fruit) { return fruit.getColor(); } }; } }
Feel the POWER OF MATCHERS
тАФ . Hamcrest : allOf, anyOf, both, either. , .
, ┬л┬╗ :
@Test public void orangeBothSweetRoundAndOrangeColorWithMatchers() throws Exception { assumeThat(someFruit, both(round()).and(sweet()).and(hasColor(Color.ORANGE))); // }
.
, , тАФ . , . тАФ :
@Test public void orangeBothSweetRoundAndOrangeColorWithMatchers() throws Exception { assertThat(someFruitList, everyItem(both(round()).and(sweet()).and(hasColor(Color.ORANGE)))); }
, : . тАФ , , hasItem()
.
.
, . , тАФ , - . , , тАФ , . , -. .
github.com/yandex-qatools/matchers-java .
TypeSafeMatcher, . :
public boolean matchesSafely(Fruit fruit)
тАФ , public void describeTo(Description description)
тАФ , protected void describeMismatchSafely(Fruit item, Description mismatchDescription)
тАФ .
, , тАФ null
.
, , , :
public class ShapeMatcher extends TypeSafeMatcher<Fruit> { private Shape expected; public ShapeMatcher(Shape expected) { this.expected = expected; } @Override public boolean matchesSafely(Fruit fruit) { return expected.equals(fruit.getShape()); } @Override protected void describeMismatchSafely(Fruit item, Description mismatchDescription) { mismatchDescription.appendText("fruit has shape - ").appendValue(item.getShape()); } @Override public void describeTo(Description description) { description.appendText("shape - ").appendValue(expected); } @Factory public static ShapeMatcher round() { return new ShapeMatcher(Shape.ROUND); } }
. , , , , тАФ !
, , , , . тАФ . Java FeatureMatcher<WhatWeGet, WhatWeWannaCheck>
, : .
3 :
, WhatWeWannaCheck , ( ), ( - )
, f eatureValueOf
. Hamcrest .
, , .
public class Matchers { public static Matcher<Fruit> hasShape(final Shape shape) { return new FeatureMatcher<Fruit, Shape>(equalTo(shape), "fruit has shape - ", "shape -") { @Override protected Shape featureValueOf(Fruit fruit) { return fruit.getShape(); } }; } public static Matcher<Fruit> round() { return hasShape(Shape.ROUND); } public static Matcher<Fruit> sweet() { return new FeatureMatcher<Fruit, Boolean>(is(true), "fruit should be sweet", "sweet -") { @Override protected Boolean featureValueOf(Fruit fruit) { return fruit.isSweet(); } }; } public static Matcher<Fruit> hasColor(Color color) { return new FeatureMatcher<Fruit, Color>(equalTo(color), "fruit have color - ", "color -") { @Override protected String featureValueOf(Fruit fruit) { return fruit.getColor(); } }; } }
Feel the POWER OF MATCHERS
тАФ . Hamcrest : allOf, anyOf, both, either. , .
, ┬л┬╗ :
@Test public void orangeBothSweetRoundAndOrangeColorWithMatchers() throws Exception { assumeThat(someFruit, both(round()).and(sweet()).and(hasColor(Color.ORANGE))); // }
.
, , тАФ . , . тАФ :
@Test public void orangeBothSweetRoundAndOrangeColorWithMatchers() throws Exception { assertThat(someFruitList, everyItem(both(round()).and(sweet()).and(hasColor(Color.ORANGE)))); }
, : . тАФ , , hasItem()
.
.
, . , тАФ , - . , , тАФ , . , -. .
github.com/yandex-qatools/matchers-java .
TypeSafeMatcher, . :
public boolean matchesSafely(Fruit fruit)
тАФ , public void describeTo(Description description)
тАФ , protected void describeMismatchSafely(Fruit item, Description mismatchDescription)
тАФ .
, , тАФ null
.
, , , :
public class ShapeMatcher extends TypeSafeMatcher<Fruit> { private Shape expected; public ShapeMatcher(Shape expected) { this.expected = expected; } @Override public boolean matchesSafely(Fruit fruit) { return expected.equals(fruit.getShape()); } @Override protected void describeMismatchSafely(Fruit item, Description mismatchDescription) { mismatchDescription.appendText("fruit has shape - ").appendValue(item.getShape()); } @Override public void describeTo(Description description) { description.appendText("shape - ").appendValue(expected); } @Factory public static ShapeMatcher round() { return new ShapeMatcher(Shape.ROUND); } }
. , , , , тАФ !
, , , , . тАФ . Java FeatureMatcher<WhatWeGet, WhatWeWannaCheck>
, : .
3 :
, WhatWeWannaCheck , ( ), ( - )
, f eatureValueOf
. Hamcrest .
, , .
public class Matchers { public static Matcher<Fruit> hasShape(final Shape shape) { return new FeatureMatcher<Fruit, Shape>(equalTo(shape), "fruit has shape - ", "shape -") { @Override protected Shape featureValueOf(Fruit fruit) { return fruit.getShape(); } }; } public static Matcher<Fruit> round() { return hasShape(Shape.ROUND); } public static Matcher<Fruit> sweet() { return new FeatureMatcher<Fruit, Boolean>(is(true), "fruit should be sweet", "sweet -") { @Override protected Boolean featureValueOf(Fruit fruit) { return fruit.isSweet(); } }; } public static Matcher<Fruit> hasColor(Color color) { return new FeatureMatcher<Fruit, Color>(equalTo(color), "fruit have color - ", "color -") { @Override protected String featureValueOf(Fruit fruit) { return fruit.getColor(); } }; } }
Feel the POWER OF MATCHERS
тАФ . Hamcrest : allOf, anyOf, both, either. , .
, ┬л┬╗ :
@Test public void orangeBothSweetRoundAndOrangeColorWithMatchers() throws Exception { assumeThat(someFruit, both(round()).and(sweet()).and(hasColor(Color.ORANGE))); // }
.
, , тАФ . , . тАФ :
@Test public void orangeBothSweetRoundAndOrangeColorWithMatchers() throws Exception { assertThat(someFruitList, everyItem(both(round()).and(sweet()).and(hasColor(Color.ORANGE)))); }
, : . тАФ , , hasItem()
.
.
, . , тАФ , - . , , тАФ , . , -. .
github.com/yandex-qatools/matchers-java .
TypeSafeMatcher, . :
public boolean matchesSafely(Fruit fruit)
тАФ , public void describeTo(Description description)
тАФ , protected void describeMismatchSafely(Fruit item, Description mismatchDescription)
тАФ .
, , тАФ null
.
, , , :
public class ShapeMatcher extends TypeSafeMatcher<Fruit> { private Shape expected; public ShapeMatcher(Shape expected) { this.expected = expected; } @Override public boolean matchesSafely(Fruit fruit) { return expected.equals(fruit.getShape()); } @Override protected void describeMismatchSafely(Fruit item, Description mismatchDescription) { mismatchDescription.appendText("fruit has shape - ").appendValue(item.getShape()); } @Override public void describeTo(Description description) { description.appendText("shape - ").appendValue(expected); } @Factory public static ShapeMatcher round() { return new ShapeMatcher(Shape.ROUND); } }
. , , , , тАФ !
, , , , . тАФ . Java FeatureMatcher<WhatWeGet, WhatWeWannaCheck>
, : .
3 :
, WhatWeWannaCheck , ( ), ( - )
, f eatureValueOf
. Hamcrest .
, , .
public class Matchers { public static Matcher<Fruit> hasShape(final Shape shape) { return new FeatureMatcher<Fruit, Shape>(equalTo(shape), "fruit has shape - ", "shape -") { @Override protected Shape featureValueOf(Fruit fruit) { return fruit.getShape(); } }; } public static Matcher<Fruit> round() { return hasShape(Shape.ROUND); } public static Matcher<Fruit> sweet() { return new FeatureMatcher<Fruit, Boolean>(is(true), "fruit should be sweet", "sweet -") { @Override protected Boolean featureValueOf(Fruit fruit) { return fruit.isSweet(); } }; } public static Matcher<Fruit> hasColor(Color color) { return new FeatureMatcher<Fruit, Color>(equalTo(color), "fruit have color - ", "color -") { @Override protected String featureValueOf(Fruit fruit) { return fruit.getColor(); } }; } }
Feel the POWER OF MATCHERS
тАФ . Hamcrest : allOf, anyOf, both, either. , .
, ┬л┬╗ :
@Test public void orangeBothSweetRoundAndOrangeColorWithMatchers() throws Exception { assumeThat(someFruit, both(round()).and(sweet()).and(hasColor(Color.ORANGE)));
TypeSafeMatcher, . :
public boolean matchesSafely(Fruit fruit)
тАФ , public void describeTo(Description description)
тАФ , protected void describeMismatchSafely(Fruit item, Description mismatchDescription)
тАФ .
, , тАФ null
.
, , , :
public class ShapeMatcher extends TypeSafeMatcher<Fruit> { private Shape expected; public ShapeMatcher(Shape expected) { this.expected = expected; } @Override public boolean matchesSafely(Fruit fruit) { return expected.equals(fruit.getShape()); } @Override protected void describeMismatchSafely(Fruit item, Description mismatchDescription) { mismatchDescription.appendText("fruit has shape - ").appendValue(item.getShape()); } @Override public void describeTo(Description description) { description.appendText("shape - ").appendValue(expected); } @Factory public static ShapeMatcher round() { return new ShapeMatcher(Shape.ROUND); } }
. , , , , тАФ !
, , , , . тАФ . Java FeatureMatcher<WhatWeGet, WhatWeWannaCheck>
, : .
3 :
, WhatWeWannaCheck , ( ), ( - )
, f eatureValueOf
. Hamcrest .
, , .
public class Matchers { public static Matcher<Fruit> hasShape(final Shape shape) { return new FeatureMatcher<Fruit, Shape>(equalTo(shape), "fruit has shape - ", "shape -") { @Override protected Shape featureValueOf(Fruit fruit) { return fruit.getShape(); } }; } public static Matcher<Fruit> round() { return hasShape(Shape.ROUND); } public static Matcher<Fruit> sweet() { return new FeatureMatcher<Fruit, Boolean>(is(true), "fruit should be sweet", "sweet -") { @Override protected Boolean featureValueOf(Fruit fruit) { return fruit.isSweet(); } }; } public static Matcher<Fruit> hasColor(Color color) { return new FeatureMatcher<Fruit, Color>(equalTo(color), "fruit have color - ", "color -") { @Override protected String featureValueOf(Fruit fruit) { return fruit.getColor(); } }; } }
Feel the POWER OF MATCHERS
тАФ . Hamcrest : allOf, anyOf, both, either. , .
, ┬л┬╗ :
@Test public void orangeBothSweetRoundAndOrangeColorWithMatchers() throws Exception { assumeThat(someFruit, both(round()).and(sweet()).and(hasColor(Color.ORANGE))); // }
.
, , тАФ . , . тАФ :
@Test public void orangeBothSweetRoundAndOrangeColorWithMatchers() throws Exception { assertThat(someFruitList, everyItem(both(round()).and(sweet()).and(hasColor(Color.ORANGE)))); }
, : . тАФ , , hasItem()
.
.
, . , тАФ , - . , , тАФ , . , -. .
github.com/yandex-qatools/matchers-java .
TypeSafeMatcher, . :
public boolean matchesSafely(Fruit fruit)
тАФ , public void describeTo(Description description)
тАФ , protected void describeMismatchSafely(Fruit item, Description mismatchDescription)
тАФ .
, , тАФ null
.
, , , :
public class ShapeMatcher extends TypeSafeMatcher<Fruit> { private Shape expected; public ShapeMatcher(Shape expected) { this.expected = expected; } @Override public boolean matchesSafely(Fruit fruit) { return expected.equals(fruit.getShape()); } @Override protected void describeMismatchSafely(Fruit item, Description mismatchDescription) { mismatchDescription.appendText("fruit has shape - ").appendValue(item.getShape()); } @Override public void describeTo(Description description) { description.appendText("shape - ").appendValue(expected); } @Factory public static ShapeMatcher round() { return new ShapeMatcher(Shape.ROUND); } }
. , , , , тАФ !
, , , , . тАФ . Java FeatureMatcher<WhatWeGet, WhatWeWannaCheck>
, : .
3 :
, WhatWeWannaCheck , ( ), ( - )
, f eatureValueOf
. Hamcrest .
, , .
public class Matchers { public static Matcher<Fruit> hasShape(final Shape shape) { return new FeatureMatcher<Fruit, Shape>(equalTo(shape), "fruit has shape - ", "shape -") { @Override protected Shape featureValueOf(Fruit fruit) { return fruit.getShape(); } }; } public static Matcher<Fruit> round() { return hasShape(Shape.ROUND); } public static Matcher<Fruit> sweet() { return new FeatureMatcher<Fruit, Boolean>(is(true), "fruit should be sweet", "sweet -") { @Override protected Boolean featureValueOf(Fruit fruit) { return fruit.isSweet(); } }; } public static Matcher<Fruit> hasColor(Color color) { return new FeatureMatcher<Fruit, Color>(equalTo(color), "fruit have color - ", "color -") { @Override protected String featureValueOf(Fruit fruit) { return fruit.getColor(); } }; } }
Feel the POWER OF MATCHERS
тАФ . Hamcrest : allOf, anyOf, both, either. , .
, ┬л┬╗ :
@Test public void orangeBothSweetRoundAndOrangeColorWithMatchers() throws Exception { assumeThat(someFruit, both(round()).and(sweet()).and(hasColor(Color.ORANGE)));
TypeSafeMatcher, . :
public boolean matchesSafely(Fruit fruit)
тАФ , public void describeTo(Description description)
тАФ , protected void describeMismatchSafely(Fruit item, Description mismatchDescription)
тАФ .
, , тАФ null
.
, , , :
public class ShapeMatcher extends TypeSafeMatcher<Fruit> { private Shape expected; public ShapeMatcher(Shape expected) { this.expected = expected; } @Override public boolean matchesSafely(Fruit fruit) { return expected.equals(fruit.getShape()); } @Override protected void describeMismatchSafely(Fruit item, Description mismatchDescription) { mismatchDescription.appendText("fruit has shape - ").appendValue(item.getShape()); } @Override public void describeTo(Description description) { description.appendText("shape - ").appendValue(expected); } @Factory public static ShapeMatcher round() { return new ShapeMatcher(Shape.ROUND); } }
. , , , , тАФ !
, , , , . тАФ . Java FeatureMatcher<WhatWeGet, WhatWeWannaCheck>
, : .
3 :
, WhatWeWannaCheck , ( ), ( - )
, f eatureValueOf
. Hamcrest .
, , .
public class Matchers { public static Matcher<Fruit> hasShape(final Shape shape) { return new FeatureMatcher<Fruit, Shape>(equalTo(shape), "fruit has shape - ", "shape -") { @Override protected Shape featureValueOf(Fruit fruit) { return fruit.getShape(); } }; } public static Matcher<Fruit> round() { return hasShape(Shape.ROUND); } public static Matcher<Fruit> sweet() { return new FeatureMatcher<Fruit, Boolean>(is(true), "fruit should be sweet", "sweet -") { @Override protected Boolean featureValueOf(Fruit fruit) { return fruit.isSweet(); } }; } public static Matcher<Fruit> hasColor(Color color) { return new FeatureMatcher<Fruit, Color>(equalTo(color), "fruit have color - ", "color -") { @Override protected String featureValueOf(Fruit fruit) { return fruit.getColor(); } }; } }
Feel the POWER OF MATCHERS
тАФ . Hamcrest : allOf, anyOf, both, either. , .
, ┬л┬╗ :
@Test public void orangeBothSweetRoundAndOrangeColorWithMatchers() throws Exception { assumeThat(someFruit, both(round()).and(sweet()).and(hasColor(Color.ORANGE))); // }
.
, , тАФ . , . тАФ :
@Test public void orangeBothSweetRoundAndOrangeColorWithMatchers() throws Exception { assertThat(someFruitList, everyItem(both(round()).and(sweet()).and(hasColor(Color.ORANGE)))); }
, : . тАФ , , hasItem()
.
.
, . , тАФ , - . , , тАФ , . , -. .
github.com/yandex-qatools/matchers-java .
TypeSafeMatcher, . :
public boolean matchesSafely(Fruit fruit)
тАФ , public void describeTo(Description description)
тАФ , protected void describeMismatchSafely(Fruit item, Description mismatchDescription)
тАФ .
, , тАФ null
.
, , , :
public class ShapeMatcher extends TypeSafeMatcher<Fruit> { private Shape expected; public ShapeMatcher(Shape expected) { this.expected = expected; } @Override public boolean matchesSafely(Fruit fruit) { return expected.equals(fruit.getShape()); } @Override protected void describeMismatchSafely(Fruit item, Description mismatchDescription) { mismatchDescription.appendText("fruit has shape - ").appendValue(item.getShape()); } @Override public void describeTo(Description description) { description.appendText("shape - ").appendValue(expected); } @Factory public static ShapeMatcher round() { return new ShapeMatcher(Shape.ROUND); } }
. , , , , тАФ !
, , , , . тАФ . Java FeatureMatcher<WhatWeGet, WhatWeWannaCheck>
, : .
3 :
, WhatWeWannaCheck , ( ), ( - )
, f eatureValueOf
. Hamcrest .
, , .
public class Matchers { public static Matcher<Fruit> hasShape(final Shape shape) { return new FeatureMatcher<Fruit, Shape>(equalTo(shape), "fruit has shape - ", "shape -") { @Override protected Shape featureValueOf(Fruit fruit) { return fruit.getShape(); } }; } public static Matcher<Fruit> round() { return hasShape(Shape.ROUND); } public static Matcher<Fruit> sweet() { return new FeatureMatcher<Fruit, Boolean>(is(true), "fruit should be sweet", "sweet -") { @Override protected Boolean featureValueOf(Fruit fruit) { return fruit.isSweet(); } }; } public static Matcher<Fruit> hasColor(Color color) { return new FeatureMatcher<Fruit, Color>(equalTo(color), "fruit have color - ", "color -") { @Override protected String featureValueOf(Fruit fruit) { return fruit.getColor(); } }; } }
Feel the POWER OF MATCHERS
тАФ . Hamcrest : allOf, anyOf, both, either. , .
, ┬л┬╗ :
@Test public void orangeBothSweetRoundAndOrangeColorWithMatchers() throws Exception { assumeThat(someFruit, both(round()).and(sweet()).and(hasColor(Color.ORANGE))); // }
.
, , тАФ . , . тАФ :
@Test public void orangeBothSweetRoundAndOrangeColorWithMatchers() throws Exception { assertThat(someFruitList, everyItem(both(round()).and(sweet()).and(hasColor(Color.ORANGE)))); }
, : . тАФ , , hasItem()
.
.
, . , тАФ , - . , , тАФ , . , -. .
github.com/yandex-qatools/matchers-java .
TypeSafeMatcher, . :
public boolean matchesSafely(Fruit fruit)
тАФ , public void describeTo(Description description)
тАФ , protected void describeMismatchSafely(Fruit item, Description mismatchDescription)
тАФ .
, , тАФ null
.
, , , :
public class ShapeMatcher extends TypeSafeMatcher<Fruit> { private Shape expected; public ShapeMatcher(Shape expected) { this.expected = expected; } @Override public boolean matchesSafely(Fruit fruit) { return expected.equals(fruit.getShape()); } @Override protected void describeMismatchSafely(Fruit item, Description mismatchDescription) { mismatchDescription.appendText("fruit has shape - ").appendValue(item.getShape()); } @Override public void describeTo(Description description) { description.appendText("shape - ").appendValue(expected); } @Factory public static ShapeMatcher round() { return new ShapeMatcher(Shape.ROUND); } }
. , , , , тАФ !
, , , , . тАФ . Java FeatureMatcher<WhatWeGet, WhatWeWannaCheck>
, : .
3 :
, WhatWeWannaCheck , ( ), ( - )
, f eatureValueOf
. Hamcrest .
, , .
public class Matchers { public static Matcher<Fruit> hasShape(final Shape shape) { return new FeatureMatcher<Fruit, Shape>(equalTo(shape), "fruit has shape - ", "shape -") { @Override protected Shape featureValueOf(Fruit fruit) { return fruit.getShape(); } }; } public static Matcher<Fruit> round() { return hasShape(Shape.ROUND); } public static Matcher<Fruit> sweet() { return new FeatureMatcher<Fruit, Boolean>(is(true), "fruit should be sweet", "sweet -") { @Override protected Boolean featureValueOf(Fruit fruit) { return fruit.isSweet(); } }; } public static Matcher<Fruit> hasColor(Color color) { return new FeatureMatcher<Fruit, Color>(equalTo(color), "fruit have color - ", "color -") { @Override protected String featureValueOf(Fruit fruit) { return fruit.getColor(); } }; } }
Feel the POWER OF MATCHERS
тАФ . Hamcrest : allOf, anyOf, both, either. , .
, ┬л┬╗ :
@Test public void orangeBothSweetRoundAndOrangeColorWithMatchers() throws Exception { assumeThat(someFruit, both(round()).and(sweet()).and(hasColor(Color.ORANGE))); // }
.
, , тАФ . , . тАФ :
@Test public void orangeBothSweetRoundAndOrangeColorWithMatchers() throws Exception { assertThat(someFruitList, everyItem(both(round()).and(sweet()).and(hasColor(Color.ORANGE)))); }
, : . тАФ , , hasItem()
.
.
, . , тАФ , - . , , тАФ , . , -. .
github.com/yandex-qatools/matchers-java .