<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet href="/rss.xsl" type="text/xsl"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>JNY.com</title><description>Website personal</description><link>https://rootpass.gitlab.io</link><item><title>Git Commands</title><link>https://rootpass.gitlab.io/posts/git-cmds</link><guid isPermaLink="true">https://rootpass.gitlab.io/posts/git-cmds</guid><description>Some of the commands that I forget the most every now and then.</description><pubDate>Sun, 29 Mar 2026 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;The following are those CLI commands from Git that I tend to forget specially after long periods without
using them, so in order to avoid that uncomfortable feeling of not remember them when I need to implement
something quickly I&apos;ll put every single one here to find them easily.&lt;/p&gt;
&lt;p&gt;Add a fresh local repo to a remote one:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;git init
git remote add origin git@gitlab.com:rootpass/myRepository.git
git push -u origin main
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Create, select and upstream to remote a new branch:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;git branch myBranch
git select myBranch
git push -u origin myBranch
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Delete local and remote branches:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;git branch -d myBranch
git push origin -delete myBranch
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Create tag (annotated or lightweight):&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;git tag -a myTag -m &apos;V1.0&apos;
git tag myTag
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Upstream tag (one tag or several tags):&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;git push origin myTag
git push origin -tags
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Delete local or remote tag:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;git tag -d myTag
git push origin -delete myTag
&lt;/code&gt;&lt;/pre&gt;
</content:encoded><author>JohnnyTB</author></item><item><title>Exception Handling in JUnit</title><link>https://rootpass.gitlab.io/posts/junit-exceptions</link><guid isPermaLink="true">https://rootpass.gitlab.io/posts/junit-exceptions</guid><description>Best practices writing unit tests involving exceptions.</description><pubDate>Wed, 01 Apr 2026 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Lets say we have the following method that receives 2 integer values divides them and returns the result or
throws an &lt;code&gt;ArithmeticException&lt;/code&gt; if an error occurs:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;public class Calc {
  public int divide(int x,int y) throws Exception {
    return x/y;
  }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;As the method &lt;code&gt;divide&lt;/code&gt; specifies that it can throw an &lt;code&gt;ArithmeticException&lt;/code&gt; its not necessary to write the unit test
code in a &lt;em&gt;try-catch&lt;/em&gt; block:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;//Avoid this approach
@Test
void shouldThrowException() {
  try {
    assertEquals(2,new Calc().divide(4,0));
  } catch(ArithmeticException e) {
    e.printStackTrace();
  }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So, instead you can use the following alternative that offers a short and more clear solution:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;//Do this instead
@Test
void shouldThrowException() throws Exception {
  assertEquals(2,new Calc().divide(4,0));
}
&lt;/code&gt;&lt;/pre&gt;
</content:encoded><author>JohnnyTB</author></item><item><title>API Request in Apex</title><link>https://rootpass.gitlab.io/posts/apex-api-request</link><guid isPermaLink="true">https://rootpass.gitlab.io/posts/apex-api-request</guid><description>Write and test a basic API request in Apex.</description><pubDate>Wed, 15 Apr 2026 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;As one of my repositories hosted in GitLab needed to rebuild periodically to handle static
content and keep important data up to date, one way I considered was create a CI/CD pipeline job
that could be triggered by an API request from Salesforce whenever new records are added to its database.&lt;/p&gt;
&lt;p&gt;Once the request is sent, the pipeline job will be triggered and the project will be rebuilt, this task
allows my static app to make API request as well and then update its contents with freshly fetched data,
it sounds a little complicated but I guess that&apos;s a valid approach.&lt;/p&gt;
&lt;p&gt;This is the class in Apex code to try to hit the endpoint exposed by GitLab:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;public class GitLabPipelineService implements Queueable, Database.AllowsCallouts {
  private Set&amp;lt;Id&amp;gt; recordIds;
  public GitLabPipelineService(Set&amp;lt;Id&amp;gt; recordIds) {
    this.recordIds = recordIds;
  }

  public void execute(QueueableContext context) {
    /* Load custom metadata.
       useful to bring secured variables in this case:
       Token__c, Branch__c and ProjectId__c; */
    GitLab_Config__mdt config = GitLab_Config__mdt.getInstance(&apos;Default&apos;);

    Http http = new Http();
    HttpRequest request = new HttpRequest();

    request.setEndpoint(
      &apos;https://gitlab.com/api/v4/projects/&apos;+config.ProjectId__c+&apos;/trigger/pipeline&apos;
    );

    request.setMethod(&apos;POST&apos;);
    request.setHeader(&apos;Content-Type&apos;, &apos;application/x-www-form-urlencoded&apos;);

    String body = &apos;token=&apos;+config.Token__c+&apos;&amp;amp;ref=&apos;+config.Branch__c+
                  &apos;&amp;amp;variables[recordCount]=&apos;+recordIds.size();

    request.setBody(body);

    try {
        HttpResponse response = http.send(request);
        System.debug(&apos;GitLab response: &apos;+response.getBody());
    } catch (Exception e) {
        System.debug(&apos;GitLab error: &apos;+e.getMessage());
    }
  }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The required test class, which is &lt;strong&gt;essential&lt;/strong&gt; to deploy the code to production, shows how to perform a test
using a mocked callout:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;@isTest
public class GitLabPipelineServiceTest {
  @isTest
  static void testTriggerPipeline() {
    Test.setMock(HttpCalloutMock.class, new GitLabMock());
    
    Test.startTest();
    
    // Create test record
    Account a=new Account(Name=&apos;New Account&apos;, Phone=&apos;123-456-789&apos;);
    insert a;
    
    Test.stopTest();
    
    System.assert(true); // basic assertion
  }
  
  @isTest
  static void testTriggerPipelineException() {
    Test.setMock(HttpCalloutMock.class, new GitLabMockExcep());

    Test.startTest();
    Account a=new Account(Name=&apos;New Account&apos;, Phone=&apos;123-456-789&apos;);
    insert a;
    
    Test.stopTest();
    
    System.assert(true);
  }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The following two classes are used by the &lt;code&gt;GitLabPipelineServiceTest&lt;/code&gt; class shown above, the first tests a successful
call and the other tests a failure scenario:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;//Test when a callout is successfull
@isTest
global class GitLabMock implements HttpCalloutMock {
  global HttpResponse respond(HttpRequest req) {
    HttpResponse res = new HttpResponse();
    res.setStatusCode(200);
    res.setBody(&apos;{&quot;status&quot;:&quot;success&quot;}&apos;);
    return res;
  }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;//Test when a callout fails
@isTest
global class GitLabMockExcep implements HttpCalloutMock {
  global HttpResponse respond(HttpRequest req) {
    throw new CalloutException(&apos;Callout failed (Ok!)&apos;);
  }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And finally, the trigger that makes the GitLab pipeline job run via an API call:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;trigger GitLabPipelineService_Trigger on Account (after insert) {
  if (Trigger.isAfter &amp;amp;&amp;amp; Trigger.isInsert) {
    System.enqueueJob(new GitLabPipelineService(Trigger.newMap.keySet()));
  }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;hr /&gt;
&lt;p&gt;Decided to write this here for informational and study purposes, and I think it&apos;s very valuable.&lt;/p&gt;
</content:encoded><author>JohnnyTB</author></item></channel></rss>