org.approvaltests.Approvals Java Examples
The following examples show how to use
org.approvaltests.Approvals.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MessageRequestIT.java From restful-booker-platform with GNU General Public License v3.0 | 6 votes |
@Test public void testSendingToMessageAPI(){ LocalDate checkindate = LocalDate.of(1990, Month.FEBRUARY, 1); LocalDate checkoutdate = LocalDate.of(1990, Month.FEBRUARY, 2); Booking bookingPayload = new Booking.BookingBuilder() .setRoomid(1) .setFirstname("Mark") .setLastname("Winteringham") .setDepositpaid(true) .setCheckin(checkindate) .setCheckout(checkoutdate) .setEmail("[email protected]") .setPhone("01292123456") .build(); Response bookingResponse = given() .contentType(ContentType.JSON) .body(bookingPayload) .when() .post("http://localhost:3000/booking/"); Approvals.verify(server.getCalls().get(0).getPostBody()); }
Example #2
Source File: DateDifferenceTest.java From ApprovalTests.Java with Apache License 2.0 | 6 votes |
@Test public void testFebruaryAndDaylightSavingsTime() { try (WithTimeZone tz = new WithTimeZone("PST")) { StringBuilder buffer = new StringBuilder(); DateFormat f = TemplateDate.FORMATS.DATE_SHORT; for (int i = 1; i <= 28; i++) { Timestamp a = DateUtils.parse("2010/02/0" + i); Timestamp b = DateUtils.parse("2010/03/0" + i); DateDifference dif = new DateDifference(a, b); String standardTimeText = dif.getStandardTimeText(2, "days", "seconds", null, null); buffer.append(f.format(a) + ", " + f.format(b) + " => " + standardTimeText + "\n"); } Approvals.verify(buffer.toString()); } }
Example #3
Source File: BrandingServiceIT.java From restful-booker-platform with GNU General Public License v3.0 | 6 votes |
@Test public void updateBrandingData() { Branding brandingPayload = new Branding( "Updated hotel name", new Map(50.0, 50.0), "https://www.valid.com/link/to/logo", "Description update", new Contact("Update name", "Update address", "9999999999", "[email protected]") ); Response brandingPutResponse = given() .cookie("token", "abc123") .contentType(ContentType.JSON) .body(brandingPayload) .when() .put("http://localhost:3002/branding/"); Approvals.verify(brandingPutResponse.body().prettyPrint()); }
Example #4
Source File: MessageEndpointsIT.java From restful-booker-platform with GNU General Public License v3.0 | 6 votes |
@Test public void markAsReadTest(){ Message messagePayload = new Message("Mark", "[email protected]", "01234556789", "Subject line goes in here for display", "Description details here to give info on request"); Message createdMessage = given() .contentType(ContentType.JSON) .body(messagePayload) .when() .post("http://localhost:3006/message/") .getBody().as(Message.class); given() .cookie("token", "abc123") .put("http://localhost:3006/message/" + createdMessage.getMessageid() + "/read"); Response response = given() .get("http://localhost:3006/message/count"); Approvals.verify(response.getBody().prettyPrint()); }
Example #5
Source File: HadoopApprovals.java From ApprovalTests.Java with Apache License 2.0 | 6 votes |
public static void verifyMapReduce(SmartMapper mapper, SmartReducer reducer, Object key, Object input) throws Exception { MapDriver mapDriver = new MapDriver(); mapDriver.setMapper(mapper); MapReduceDriver mapReduceDriver = new MapReduceDriver(); mapReduceDriver.setMapper(mapper); Object writableKey = WritableUtils.createWritable(key, mapper.getKeyInType()); Object writableValue = WritableUtils.createWritable(input, mapper.getValueInType()); mapDriver.withInput(writableKey, writableValue); List results = mapDriver.run(); Collections.sort(results, PairComparer.INSTANCE); mapReduceDriver = new MapReduceDriver<LongWritable, Text, Text, LongWritable, Text, LongWritable>(); writableKey = WritableUtils.createWritable(key, mapper.getKeyInType()); writableValue = WritableUtils.createWritable(input, mapper.getValueInType()); mapReduceDriver.withInput(writableKey, writableValue); mapReduceDriver.setMapper(mapper); mapReduceDriver.setReducer(reducer); List finalResults = mapReduceDriver.run(); String text = String.format("[%s]\n\n -> maps via %s to -> \n\n%s\n\n -> reduces via %s to -> \n\n%s", input, mapper.getClass().getSimpleName(), ArrayUtils.toString(results, Echo.INSTANCE), reducer.getClass().getSimpleName(), ArrayUtils.toString(finalResults, Echo.INSTANCE)); Approvals.verify(text); }
Example #6
Source File: HadoopApprovals.java From ApprovalTests.Java with Apache License 2.0 | 6 votes |
public static void verifyMapReduce(SmartMapper mapper, SmartReducer reducer, Object key, Object input) throws Exception { MapDriver mapDriver = new MapDriver(); mapDriver.setMapper(mapper); MapReduceDriver mapReduceDriver = new MapReduceDriver(); mapReduceDriver.setMapper(mapper); Object writableKey = WritableUtils.createWritable(key, mapper.getKeyInType()); Object writableValue = WritableUtils.createWritable(input, mapper.getValueInType()); mapDriver.withInput(writableKey, writableValue); List results = mapDriver.run(); Collections.sort(results, PairComparer.INSTANCE); mapReduceDriver = new MapReduceDriver<LongWritable, Text, Text, LongWritable, Text, LongWritable>(); writableKey = WritableUtils.createWritable(key, mapper.getKeyInType()); writableValue = WritableUtils.createWritable(input, mapper.getValueInType()); mapReduceDriver.withInput(writableKey, writableValue); mapReduceDriver.setMapper(mapper); mapReduceDriver.setReducer(reducer); List finalResults = mapReduceDriver.run(); String text = String.format("[%s]\n\n -> maps via %s to -> \n\n%s\n\n -> reduces via %s to -> \n\n%s", input, mapper.getClass().getSimpleName(), ArrayUtils.toString(results, Echo.INSTANCE), reducer.getClass().getSimpleName(), ArrayUtils.toString(finalResults, Echo.INSTANCE)); Approvals.verify(text); }
Example #7
Source File: ReporterChainingTest.java From ApprovalTests.Java with Apache License 2.0 | 6 votes |
@Test public void testMultiReporterWithExceptions() { ExceptionThrowingReporter exception1 = new ExceptionThrowingReporter(); ExceptionThrowingReporter exception2 = new ExceptionThrowingReporter(); MultiReporter reporter = new MultiReporter(exception1, exception2); try { reporter.report("Hello", "world"); } catch (Throwable t) { assertTrue(exception1.run); assertTrue(exception2.run); Approvals.verify(t.getMessage()); } }
Example #8
Source File: ApiTest.java From api-framework with MIT License | 6 votes |
@Test public void postBookingReturns200(){ BookingPayload payload = new BookingPayload.BookingPayloadBuilder() .setFirstname("Mary") .setLastname("White") .setTotalprice(200) .setDepositpaid(true) .setCheckin(new Date()) .setCheckout(new Date()) .setAdditionalneeds("None") .build(); ResponseEntity<BookingResponse> response = Booking.postBooking(payload); Approvals.verify(response.getStatusCode()); }
Example #9
Source File: HadoopApprovals.java From ApprovalTests.Java with Apache License 2.0 | 6 votes |
public static void verifyReducer(SmartReducer reducer, Object key, Object... values) throws Exception { List list = new ArrayList(); for (Object value : values) { list.add(WritableUtils.createWritable(value, reducer.getValueInType())); } ReduceDriver reduceDriver = new ReduceDriver<Text, LongWritable, Text, LongWritable>(); reduceDriver.withInput(WritableUtils.createWritable(key, reducer.getKeyInType()), list); reduceDriver.setReducer(reducer); List results = reduceDriver.run(); Collections.sort(results, PairComparer.INSTANCE); String header = String.format("(%s, %s)\n\n -> reduces via %s to -> \n", key, list, reducer.getClass().getSimpleName()); Approvals.verifyAll(header, results, Echo.INSTANCE); }
Example #10
Source File: ApiTest.java From api-framework with MIT License | 6 votes |
@Test public void postBookingReturns200(){ BookingDates dates = new BookingDates.Builder() .setCheckin(new Date()) .setCheckout(new Date()) .build(); Booking payload = new Booking.Builder() .setFirstname("Mary") .setLastname("White") .setTotalprice(200) .setDepositpaid(true) .setBookingdates(dates) .setAdditionalneeds("None") .build(); Response response = BookingApi.postBooking(payload); Approvals.verify(response.getStatusCode()); }
Example #11
Source File: LegacyApprovals.java From ApprovalTests.Java with Apache License 2.0 | 6 votes |
public static void LockDown(Object call, String method, Object[]... parametersVariations) { StringBuffer sb = new StringBuffer(); IndexPermutations perms = new IndexPermutations(getSizes(parametersVariations)); Method m = null; for (Integer[] indexs : perms) { Object p[] = getParameters(parametersVariations, indexs); if (m == null) { m = new Parameters(p).getBestFitMethod(call.getClass(), method); } Object out; try { out = m.invoke(call, p); } catch (Throwable t) { out = t; } sb.append(String.format("%s = %s \n", Arrays.toString(p), out)); } Approvals.verify(new ApprovalTextWriter(sb.toString(), "txt"), new StackTraceNamer(), ReporterFactory.get()); }
Example #12
Source File: SupermarketTest.java From training with MIT License | 5 votes |
@Test public void xForY_discount() { theCart.addItem(cherryTomatoes); theCart.addItem(cherryTomatoes); teller.addSpecialOffer(SpecialOfferType.TwoForAmount, cherryTomatoes,.99); Receipt receipt = teller.checksOutArticlesFrom(theCart); Approvals.verify(new ReceiptPrinter(40).printReceipt(receipt)); }
Example #13
Source File: AwtApprovals.java From ApprovalTests.Java with Apache License 2.0 | 5 votes |
public static void verify(Component c) { try (NamedEnvironment env = NamerFactory.asOsSpecificTest()) { Approvals.verify(new ComponentApprovalWriter(c)); } }
Example #14
Source File: GenericDiffReporterTest.java From ApprovalTests.Java with Apache License 2.0 | 5 votes |
@Test public void testGetWorkingReportersForEnvironment() { try (NamedEnvironment ne = NamerFactory.asMachineNameSpecificTest()) { Approvals.verifyAll("reporters", MacDiffReporter.INSTANCE.getWorkingReportersForEnviroment()); } }
Example #15
Source File: GenericDiffReporterTest.java From ApprovalTests.Java with Apache License 2.0 | 5 votes |
private void approveGenericReporter(String a, String b, GenericDiffReporter reporter) { File directory = ClassUtils.getSourceDirectory(getClass()); String aPath = directory.getAbsolutePath() + File.separator + a; String bPath = directory.getAbsolutePath() + File.separator + b; Approvals.verify(new QueryableDiffReporterHarness(reporter, aPath, bPath)); }
Example #16
Source File: HadoopApprovals.java From ApprovalTests.Java with Apache License 2.0 | 5 votes |
public static void verifyMapping(SmartMapper mapper, Object key, Object input) throws Exception { MapDriver mapDriver = new MapDriver(); mapDriver.setMapper(mapper); Object writableKey = WritableUtils.createWritable(key, mapper.getKeyInType()); Object writableValue = WritableUtils.createWritable(input, mapper.getValueInType()); mapDriver.withInput(writableKey, writableValue); List results = mapDriver.run(); Collections.sort(results, PairComparer.INSTANCE); String header = String.format("[%s]\n\n -> maps via %s to -> \n", input, mapper.getClass().getSimpleName()); Approvals.verifyAll(header, results, Echo.INSTANCE); }
Example #17
Source File: WhiteSpaceStripperTest.java From ApprovalTests.Java with Apache License 2.0 | 5 votes |
@Test public void test() { String[] useCases = {" hello \n \n \n", " hello \r\n \n a \n", " hello "}; Approvals.verifyAll("whitespace", useCases, u -> String.format("---\n%s\n--- ->---\n%s\n---\n", u, WhiteSpaceStripper.stripBlankLines(u))); }
Example #18
Source File: MessageDBTest.java From restful-booker-platform with GNU General Public License v3.0 | 5 votes |
@Test public void testGetMessages() throws SQLException { Message message = new Message("Mark", "[email protected]", "01821 912812", "A subject you may be interested in", "In posuere accumsan aliquet."); messageDB.create(message); List<MessageSummary> messageSummaries = messageDB.queryMessages(); Approvals.verify(messageSummaries.toString()); }
Example #19
Source File: MessageEndpointsIT.java From restful-booker-platform with GNU General Public License v3.0 | 5 votes |
@Test public void getCount(){ Response response = given() .get("http://localhost:3006/message/count"); Approvals.verify(response.getBody().prettyPrint()); }
Example #20
Source File: GenericDiffReporterTest.java From ApprovalTests.Java with Apache License 2.0 | 5 votes |
@UseReporter(DiffMergeReporter.class) // end-snippet @Test public void testArgumentParsing() { Approvals.verifyAll("CommandLine", VisualStudioCodeReporter.INSTANCE.getCommandLine("received.txt", "approved.txt")); }
Example #21
Source File: SupermarketTest.java From training with MIT License | 5 votes |
@Test public void buy_two_get_one_free_but_insufficient_in_basket() { theCart.addItem(toothbrush); teller.addSpecialOffer(SpecialOfferType.ThreeForTwo, toothbrush, catalog.getUnitPrice(toothbrush)); Receipt receipt = teller.checksOutArticlesFrom(theCart); Approvals.verify(new ReceiptPrinter(40).printReceipt(receipt)); }
Example #22
Source File: ReceiptPrinterTest.java From training with MIT License | 5 votes |
@Test public void total() { receipt.addProduct(toothbrush, 1, 0.99, 2*0.99); receipt.addProduct(apples, 0.75, 1.99, 1.99*0.75); Approvals.verify(new ReceiptPrinter(40).printReceipt(receipt)); }
Example #23
Source File: PackageSettingsTest.java From ApprovalTests.Java with Apache License 2.0 | 5 votes |
@Test public void testRetrieveValue() { // begin-snippet: package_level_settings_get Map<String, Settings> settings = PackageLevelSettings.get(); // end-snippet Approvals.verify(settings); }
Example #24
Source File: F2Test.java From ApprovalTests.Java with Apache License 2.0 | 5 votes |
@Test public void testSquare() throws Exception { final HashMap<Point, String> map = new HashMap<Point, String>(); map.put(new Point(3, 4), "K"); map.put(new Point(4, 4), "Q"); map.put(new Point(1, 1), "P"); String out = Grid.print(6, 5, (a, b) -> (map.get(new Point(a, b)))); Approvals.verify(out); }
Example #25
Source File: PackageSettingsTest.java From ApprovalTests.Java with Apache License 2.0 | 5 votes |
private void failApproval() { try { Approvals.verify("foo"); } catch (Throwable e) { // ignore } }
Example #26
Source File: TestApprovalDirectoryConfig.java From ApprovalTests.Java with Apache License 2.0 | 5 votes |
@Test public void testApprovalBaseDirectory() { String path = Approvals.createApprovalNamer().getSourceFilePath(); System.out.println("path:" + path); assertTrue(path.contains(MessageFormat.format("{0}test{0}resources{0}org{0}", File.separator))); }
Example #27
Source File: AttributeStackSelectorTest.java From ApprovalTests.Java with Apache License 2.0 | 5 votes |
@Test void unrollLambda() { String[] methodNames = {"doStuff", "lambda$handleCallback$0"}; Approvals.verifyAll("unroll lambda", methodNames, m -> String.format("%s -> %s", m, TestUtils.unrollLambda(m))); }
Example #28
Source File: DateDifferenceTest.java From ApprovalTests.Java with Apache License 2.0 | 5 votes |
@Test public void testGetTimeText() { try (WithTimeZone tz = new WithTimeZone()) { Approvals.verifyAll("getTimeText", getTimeTextUseCases(), useCase -> useCase + " -> " + new DateDifference(useCase.milli).getTimeText(useCase.amount, useCase.maxUnit, useCase.minUnit, useCase.nowText, useCase.agoText, useCase.units)); } }
Example #29
Source File: FileApproverTest.java From ApprovalTests.Java with Apache License 2.0 | 5 votes |
@Test public void testCustomApprover() { // begin-snippet: custom_approver ApprovalTextWriter writer = new ApprovalTextWriter("Random: ", "txt"); ApprovalNamer namer = Approvals.createApprovalNamer(); Function2<File, File, Boolean> approveEverything = (r, a) -> true; Approvals.verify(new FileApprover(writer, namer, approveEverything)); // end-snippet }
Example #30
Source File: VelocityApprovals.java From ApprovalTests.Java with Apache License 2.0 | 5 votes |
public static void verify(ContextAware context, String fileExtentsionWithDot) { ApprovalNamer namer = Approvals.createApprovalNamer(); String file = namer.getSourceFilePath() + namer.getApprovalName() + ".template" + fileExtentsionWithDot; FileUtils.createIfNeeded(file); String text = VelocityParser.parseFile(file, context); Approvals.verify(text, fileExtentsionWithDot.substring(1)); }